blob: f37420a9eddd5c26674256b7a4a4b4a7ab99acb4 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700118import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800124import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700126import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700127import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800128import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800131import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800133import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800134import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800154import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800293 // Parameters of select command.
294 private static final int SELECT_COMMAND = 0xA4;
295 private static final int SELECT_P1 = 0x04;
296 private static final int SELECT_P2 = 0;
297 private static final int SELECT_P3 = 0x10;
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /** The singleton instance. */
300 private static PhoneInterfaceManager sInstance;
301
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800304 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700305 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private AppOpsManager mAppOps;
307 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800308 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700310 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 /** User Activity */
313 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
315
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700316 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
317
Derek Tan97ebb422014-09-05 16:55:38 -0700318 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
319 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800320 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800321 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700322
Michelecea4cf22018-12-21 15:00:11 -0800323 // String to store multi SIM allowed
324 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
325
Derek Tan740e1672017-06-27 14:56:27 -0700326 // The AID of ISD-R.
327 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
328
yinxub1bed742017-04-17 11:45:04 -0700329 private NetworkScanRequestTracker mNetworkScanRequestTracker;
330
David Kelly5e06a7f2018-03-12 14:10:59 +0000331 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
332 private static final int MANUFACTURER_CODE_LENGTH = 8;
333
Derek Tan89e89d42014-07-08 17:00:10 -0700334 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700335 * Experiment flag to enable erase modem config on reset network, default value is false
336 */
337 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
338 "reset_network_erase_modem_config_enabled";
339
340 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700341 * A request object to use for transmitting data to an ICC.
342 */
343 private static final class IccAPDUArgument {
344 public int channel, cla, command, p1, p2, p3;
345 public String data;
346
347 public IccAPDUArgument(int channel, int cla, int command,
348 int p1, int p2, int p3, String data) {
349 this.channel = channel;
350 this.cla = cla;
351 this.command = command;
352 this.p1 = p1;
353 this.p2 = p2;
354 this.p3 = p3;
355 this.data = data;
356 }
357 }
358
359 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700360 * A request object to use for transmitting data to an ICC.
361 */
362 private static final class ManualNetworkSelectionArgument {
363 public OperatorInfo operatorInfo;
364 public boolean persistSelection;
365
366 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
367 this.operatorInfo = operatorInfo;
368 this.persistSelection = persistSelection;
369 }
370 }
371
372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
374 * request after sending. The main thread will notify the request when it is complete.
375 */
376 private static final class MainThreadRequest {
377 /** The argument to use for the request */
378 public Object argument;
379 /** The result of the request that is run on the main thread */
380 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800381 // The subscriber id that this request applies to. Defaults to
382 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
383 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Nathan Harold92bed182018-10-12 18:16:49 -0700385 // In cases where subId is unavailable, the caller needs to specify the phone.
386 public Phone phone;
387
vagdeviaf9a5b92018-08-15 16:01:53 -0700388 public WorkSource workSource;
389
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 public MainThreadRequest(Object argument) {
391 this.argument = argument;
392 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800393
Nathan Harold92bed182018-10-12 18:16:49 -0700394 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
395 this.argument = argument;
396 if (phone != null) {
397 this.phone = phone;
398 }
399 this.workSource = workSource;
400 }
401
vagdeviaf9a5b92018-08-15 16:01:53 -0700402 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800403 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800404 if (subId != null) {
405 this.subId = subId;
406 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700407 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 }
410
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800411 private static final class IncomingThirdPartyCallArgs {
412 public final ComponentName component;
413 public final String callId;
414 public final String callerDisplayName;
415
416 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
417 String callerDisplayName) {
418 this.component = component;
419 this.callId = callId;
420 this.callerDisplayName = callerDisplayName;
421 }
422 }
423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /**
425 * A handler that processes messages on the main thread in the phone process. Since many
426 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
427 * inbound binder threads to the main thread in the phone process. The Binder thread
428 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
429 * on, which will be notified when the operation completes and will contain the result of the
430 * request.
431 *
432 * <p>If a MainThreadRequest object is provided in the msg.obj field,
433 * note that request.result must be set to something non-null for the calling thread to
434 * unblock.
435 */
436 private final class MainThreadHandler extends Handler {
437 @Override
438 public void handleMessage(Message msg) {
439 MainThreadRequest request;
440 Message onCompleted;
441 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800442 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800444 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
446 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700447 case CMD_HANDLE_USSD_REQUEST: {
448 request = (MainThreadRequest) msg.obj;
449 final Phone phone = getPhoneFromRequest(request);
450 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
451 String ussdRequest = ussdObject.first;
452 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700453
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 if (!isUssdApiAllowed(request.subId)) {
455 // Carrier does not support use of this API, return failure.
456 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
457 UssdResponse response = new UssdResponse(ussdRequest, null);
458 Bundle returnData = new Bundle();
459 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
460 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700461
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 request.result = true;
463 notifyRequester(request);
464 return;
465 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700466
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 try {
468 request.result = phone != null
469 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
470 } catch (CallStateException cse) {
471 request.result = false;
472 }
473 // Wake up the requesting thread
474 notifyRequester(request);
475 break;
pkanwar32d516d2016-10-14 19:37:38 -0700476 }
477
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700480 final Phone phone = getPhoneFromRequest(request);
481 request.result = phone != null ?
482 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
483 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 if (uiccCard == null) {
494 loge("iccTransmitApduLogicalChannel: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
499 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700500 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 iccArgument.channel, iccArgument.cla, iccArgument.command,
502 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 break;
506
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 if (ar.result == null) {
515 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800516 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800518 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700519 } else {
520 loge("iccTransmitApduLogicalChannel: Unknown exception");
521 }
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 break;
525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
527 request = (MainThreadRequest) msg.obj;
528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 if (uiccCard == null) {
531 loge("iccTransmitApduBasicChannel: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 } else {
535 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
536 request);
537 uiccCard.iccTransmitApduBasicChannel(
538 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
539 iccArgument.p3, iccArgument.data, onCompleted);
540 }
541 break;
542
543 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("iccTransmitApduBasicChannel: Empty response");
552 } else if (ar.exception instanceof CommandException) {
553 loge("iccTransmitApduBasicChannel: CommandException: " +
554 ar.exception);
555 } else {
556 loge("iccTransmitApduBasicChannel: Unknown exception");
557 }
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
562 case CMD_EXCHANGE_SIM_IO:
563 request = (MainThreadRequest) msg.obj;
564 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 if (uiccCard == null) {
567 loge("iccExchangeSimIO: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
572 request);
573 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
574 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
575 iccArgument.data, onCompleted);
576 }
577 break;
578
579 case EVENT_EXCHANGE_SIM_IO_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
582 if (ar.exception == null && ar.result != null) {
583 request.result = ar.result;
584 } else {
585 request.result = new IccIoResult(0x6f, 0, (byte[])null);
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 break;
589
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 case CMD_SEND_ENVELOPE:
591 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800592 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 if (uiccCard == null) {
594 loge("sendEnvelopeWithStatus: No UICC");
595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 } else {
598 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
599 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
600 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800601 break;
602
603 case EVENT_SEND_ENVELOPE_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
610 if (ar.result == null) {
611 loge("sendEnvelopeWithStatus: Empty response");
612 } else if (ar.exception instanceof CommandException) {
613 loge("sendEnvelopeWithStatus: CommandException: " +
614 ar.exception);
615 } else {
616 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
617 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800620 break;
621
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 case CMD_OPEN_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800625 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800628 request.result = new IccOpenLogicalChannelResponse(-1,
629 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800633 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
634 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_OPEN_CHANNEL_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 int[] result = (int[]) ar.result;
644 int channelId = result[0];
645 byte[] selectResponse = null;
646 if (result.length > 1) {
647 selectResponse = new byte[result.length - 1];
648 for (int i = 1; i < result.length; ++i) {
649 selectResponse[i - 1] = (byte) result[i];
650 }
651 }
652 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 if (ar.result == null) {
656 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 if (ar.exception != null) {
659 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
660 }
661
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700662 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700663 if (ar.exception instanceof CommandException) {
664 CommandException.Error error =
665 ((CommandException) (ar.exception)).getCommandError();
666 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700668 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700669 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 }
671 }
672 openChannelResp = new IccOpenLogicalChannelResponse(
673 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700675 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
679 case CMD_CLOSE_CHANNEL:
680 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800681 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 if (uiccCard == null) {
683 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900684 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 } else {
687 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
688 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
692 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800693 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
694 break;
695
696 case CMD_NV_READ_ITEM:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800709 request.result = "";
710 if (ar.result == null) {
711 loge("nvReadItem: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("nvReadItem: CommandException: " +
714 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800716 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 break;
721
Jake Hambye994d462014-02-03 13:10:13 -0800722 case CMD_NV_WRITE_ITEM:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
725 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700727 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800728 break;
729
730 case EVENT_NV_WRITE_ITEM_DONE:
731 handleNullReturnEvent(msg, "nvWriteItem");
732 break;
733
734 case CMD_NV_WRITE_CDMA_PRL:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800737 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
740 case EVENT_NV_WRITE_CDMA_PRL_DONE:
741 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
742 break;
743
chen xu6dac5ab2018-10-26 17:39:23 -0700744 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800745 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700746 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800747 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800748 break;
749
chen xu6dac5ab2018-10-26 17:39:23 -0700750 case EVENT_RESET_MODEM_CONFIG_DONE:
751 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 case CMD_GET_PREFERRED_NETWORK_TYPE:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700757 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800758 break;
759
760 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
761 ar = (AsyncResult) msg.obj;
762 request = (MainThreadRequest) ar.userObj;
763 if (ar.exception == null && ar.result != null) {
764 request.result = ar.result; // Integer
765 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530766 // request.result must be set to something non-null
767 // for the calling thread to unblock
768 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800769 if (ar.result == null) {
770 loge("getPreferredNetworkType: Empty response");
771 } else if (ar.exception instanceof CommandException) {
772 loge("getPreferredNetworkType: CommandException: " +
773 ar.exception);
774 } else {
775 loge("getPreferredNetworkType: Unknown exception");
776 }
777 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800779 break;
780
781 case CMD_SET_PREFERRED_NETWORK_TYPE:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
784 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700785 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800786 break;
787
788 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
789 handleNullReturnEvent(msg, "setPreferredNetworkType");
790 break;
791
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
793 request = (MainThreadRequest)msg.obj;
794 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800795 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000796 break;
797
798 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
799 ar = (AsyncResult)msg.obj;
800 request = (MainThreadRequest)ar.userObj;
801 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700802 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000803 break;
804
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800805 case CMD_SET_VOICEMAIL_NUMBER:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
808 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800809 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
810 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800811 break;
812
813 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
814 handleNullReturnEvent(msg, "setVoicemailNumber");
815 break;
816
Stuart Scott54788802015-03-30 13:18:01 -0700817 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
820 request);
821 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
822 break;
823
824 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
825 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
826 break;
827
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 case CMD_PERFORM_NETWORK_SCAN:
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
831 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
832 break;
833
Shuo Qian4a594052020-01-23 11:59:30 -0800834 case CMD_GET_CALL_FORWARDING:
835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
837 int callForwardingReason = (Integer) request.argument;
838 getPhoneFromRequest(request).getCallForwardingOption(
839 callForwardingReason, onCompleted);
840 break;
841
842 case EVENT_GET_CALL_FORWARDING_DONE:
843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 CallForwardingInfo callForwardingInfo = null;
846 if (ar.exception == null && ar.result != null) {
847 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
848 for (CallForwardInfo callForwardInfo : callForwardInfos) {
849 // Service Class is a bit mask per 3gpp 27.007. Search for
850 // any service for voice call.
851 if ((callForwardInfo.serviceClass
852 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
853 callForwardingInfo = new CallForwardingInfo(
854 callForwardInfo.serviceClass, callForwardInfo.reason,
855 callForwardInfo.number,
856 callForwardInfo.timeSeconds);
857 break;
858 }
859 }
860 // Didn't find a call forward info for voice call.
861 if (callForwardingInfo == null) {
862 callForwardingInfo = new CallForwardingInfo(
863 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
864 0 /* reason */, null /* number */, 0 /* timeout */);
865 }
866 } else {
867 if (ar.result == null) {
868 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
869 }
870 if (ar.exception != null) {
871 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
872 }
873 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
874 if (ar.exception instanceof CommandException) {
875 CommandException.Error error =
876 ((CommandException) (ar.exception)).getCommandError();
877 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
878 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
879 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
880 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
881 }
882 }
883 callForwardingInfo = new CallForwardingInfo(
884 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
885 }
886 request.result = callForwardingInfo;
887 notifyRequester(request);
888 break;
889
890 case CMD_SET_CALL_FORWARDING:
891 request = (MainThreadRequest) msg.obj;
892 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
893 CallForwardingInfo callForwardingInfoToSet =
894 (CallForwardingInfo) request.argument;
895 getPhoneFromRequest(request).setCallForwardingOption(
896 callForwardingInfoToSet.getStatus(),
897 callForwardingInfoToSet.getReason(),
898 callForwardingInfoToSet.getNumber(),
899 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
900 break;
901
902 case EVENT_SET_CALL_FORWARDING_DONE:
903 ar = (AsyncResult) msg.obj;
904 request = (MainThreadRequest) ar.userObj;
905 if (ar.exception == null) {
906 request.result = true;
907 } else {
908 request.result = false;
909 loge("setCallForwarding exception: " + ar.exception);
910 }
911 notifyRequester(request);
912 break;
913
914 case CMD_GET_CALL_WAITING:
915 request = (MainThreadRequest) msg.obj;
916 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
917 getPhoneFromRequest(request).getCallWaiting(onCompleted);
918 break;
919
920 case EVENT_GET_CALL_WAITING_DONE:
921 ar = (AsyncResult) msg.obj;
922 request = (MainThreadRequest) ar.userObj;
923 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
924 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800925 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800926 // Service Class is a bit mask per 3gpp 27.007.
927 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800928 if (callForwardResults.length > 1
929 && ((callForwardResults[1]
930 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
931 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800932 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
933 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
934 } else {
935 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
936 }
937 } else {
938 if (ar.result == null) {
939 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
940 }
941 if (ar.exception != null) {
942 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
943 }
944 if (ar.exception instanceof CommandException) {
945 CommandException.Error error =
946 ((CommandException) (ar.exception)).getCommandError();
947 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
948 callForwardingStatus =
949 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
950 }
951 }
952 }
953 request.result = callForwardingStatus;
954 notifyRequester(request);
955 break;
956
957 case CMD_SET_CALL_WAITING:
958 request = (MainThreadRequest) msg.obj;
959 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
960 boolean isEnable = (Boolean) request.argument;
961 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
962 break;
963
964 case EVENT_SET_CALL_WAITING_DONE:
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 if (ar.exception == null) {
968 request.result = true;
969 } else {
970 request.result = false;
971 loge("setCallWaiting exception: " + ar.exception);
972 }
973 notifyRequester(request);
974 break;
975
Shishir Agrawal302c8692015-06-19 13:49:39 -0700976 case EVENT_PERFORM_NETWORK_SCAN_DONE:
977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
979 CellNetworkScanResult cellScanResult;
980 if (ar.exception == null && ar.result != null) {
981 cellScanResult = new CellNetworkScanResult(
982 CellNetworkScanResult.STATUS_SUCCESS,
983 (List<OperatorInfo>) ar.result);
984 } else {
985 if (ar.result == null) {
986 loge("getCellNetworkScanResults: Empty response");
987 }
988 if (ar.exception != null) {
989 loge("getCellNetworkScanResults: Exception: " + ar.exception);
990 }
991 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
992 if (ar.exception instanceof CommandException) {
993 CommandException.Error error =
994 ((CommandException) (ar.exception)).getCommandError();
995 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
996 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
997 } else if (error == CommandException.Error.GENERIC_FAILURE) {
998 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
999 }
1000 }
1001 cellScanResult = new CellNetworkScanResult(errorCode, null);
1002 }
1003 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001004 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001005 break;
1006
1007 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1008 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001009 ManualNetworkSelectionArgument selArg =
1010 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001011 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1012 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001013 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1014 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001015 break;
1016
1017 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 if (ar.exception == null) {
1021 request.result = true;
1022 } else {
1023 request.result = false;
1024 loge("setNetworkSelectionModeManual " + ar.exception);
1025 }
1026 notifyRequester(request);
1027 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001028 break;
1029
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001030 case CMD_GET_MODEM_ACTIVITY_INFO:
1031 request = (MainThreadRequest) msg.obj;
1032 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001033 if (defaultPhone != null) {
1034 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001035 } else {
1036 ResultReceiver result = (ResultReceiver) request.argument;
1037 Bundle bundle = new Bundle();
1038 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1039 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1040 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001041 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001042 break;
1043
1044 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001047 ResultReceiver result = (ResultReceiver) request.argument;
1048
1049 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001050 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001051 // Update the last modem activity info and the result of the request.
1052 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1053 if (isModemActivityInfoValid(info)) {
1054 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1055 int[] txTimeMs = info.getTransmitTimeMillis();
1056 int[] lastModemTxTimeMs = mLastModemActivityInfo
1057 .getTransmitTimeMillis();
1058 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1059 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1060 }
1061 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1062 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1063 + mLastModemActivityInfo.getSleepTimeMillis());
1064 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1065 + mLastModemActivityInfo.getIdleTimeMillis());
1066 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1067 mLastModemActivityInfo.setReceiveTimeMillis(
1068 info.getReceiveTimeMillis()
1069 + mLastModemActivityInfo.getReceiveTimeMillis());
1070 }
1071 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1072 mLastModemActivityInfo.getSleepTimeMillis(),
1073 mLastModemActivityInfo.getIdleTimeMillis(),
1074 mLastModemActivityInfo.getTransmitTimeMillis(),
1075 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001076 } else {
1077 if (ar.result == null) {
1078 loge("queryModemActivityInfo: Empty response");
1079 } else if (ar.exception instanceof CommandException) {
1080 loge("queryModemActivityInfo: CommandException: " +
1081 ar.exception);
1082 } else {
1083 loge("queryModemActivityInfo: Unknown exception");
1084 }
1085 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001086 Bundle bundle = new Bundle();
1087 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1088 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001089 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001090 break;
1091
Meng Wang1a7c35a2016-05-05 20:56:15 -07001092 case CMD_SET_ALLOWED_CARRIERS:
1093 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001094 CarrierRestrictionRules argument =
1095 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001096 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001097 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001098 break;
1099
1100 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1101 ar = (AsyncResult) msg.obj;
1102 request = (MainThreadRequest) ar.userObj;
1103 if (ar.exception == null && ar.result != null) {
1104 request.result = ar.result;
1105 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001106 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1107 if (ar.exception instanceof CommandException) {
1108 loge("setAllowedCarriers: CommandException: " + ar.exception);
1109 CommandException.Error error =
1110 ((CommandException) (ar.exception)).getCommandError();
1111 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1112 request.result =
1113 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1114 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001115 } else {
1116 loge("setAllowedCarriers: Unknown exception");
1117 }
1118 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001119 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001120 break;
1121
1122 case CMD_GET_ALLOWED_CARRIERS:
1123 request = (MainThreadRequest) msg.obj;
1124 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001125 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001126 break;
1127
1128 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1129 ar = (AsyncResult) msg.obj;
1130 request = (MainThreadRequest) ar.userObj;
1131 if (ar.exception == null && ar.result != null) {
1132 request.result = ar.result;
1133 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001134 request.result = new IllegalStateException(
1135 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001136 if (ar.result == null) {
1137 loge("getAllowedCarriers: Empty response");
1138 } else if (ar.exception instanceof CommandException) {
1139 loge("getAllowedCarriers: CommandException: " +
1140 ar.exception);
1141 } else {
1142 loge("getAllowedCarriers: Unknown exception");
1143 }
1144 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001145 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001146 break;
1147
Nathan Haroldb3014052017-01-25 15:57:32 -08001148 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
1151 if (ar.exception == null && ar.result != null) {
1152 request.result = ar.result;
1153 } else {
1154 request.result = new IllegalArgumentException(
1155 "Failed to retrieve Forbidden Plmns");
1156 if (ar.result == null) {
1157 loge("getForbiddenPlmns: Empty response");
1158 } else {
1159 loge("getForbiddenPlmns: Unknown exception");
1160 }
1161 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001162 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001163 break;
1164
1165 case CMD_GET_FORBIDDEN_PLMNS:
1166 request = (MainThreadRequest) msg.obj;
1167 uiccCard = getUiccCardFromRequest(request);
1168 if (uiccCard == null) {
1169 loge("getForbiddenPlmns() UiccCard is null");
1170 request.result = new IllegalArgumentException(
1171 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001172 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001173 break;
1174 }
1175 Integer appType = (Integer) request.argument;
1176 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1177 if (uiccApp == null) {
1178 loge("getForbiddenPlmns() no app with specified type -- "
1179 + appType);
1180 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001181 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001182 break;
1183 } else {
1184 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1185 + " specified type -- " + appType);
1186 }
1187 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1188 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1189 onCompleted);
1190 break;
1191
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001192 case CMD_SWITCH_SLOTS:
1193 request = (MainThreadRequest) msg.obj;
1194 int[] physicalSlots = (int[]) request.argument;
1195 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1196 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1197 break;
1198
1199 case EVENT_SWITCH_SLOTS_DONE:
1200 ar = (AsyncResult) msg.obj;
1201 request = (MainThreadRequest) ar.userObj;
1202 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001203 notifyRequester(request);
1204 break;
1205 case CMD_GET_NETWORK_SELECTION_MODE:
1206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1208 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1209 break;
1210
1211 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
1214 if (ar.exception != null) {
1215 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1216 } else {
1217 int mode = ((int[]) ar.result)[0];
1218 if (mode == 0) {
1219 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1220 } else {
1221 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1222 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001223 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001224 notifyRequester(request);
1225 break;
1226 case CMD_GET_CDMA_ROAMING_MODE:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1229 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1230 break;
1231 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1232 ar = (AsyncResult) msg.obj;
1233 request = (MainThreadRequest) ar.userObj;
1234 if (ar.exception != null) {
1235 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1236 } else {
1237 request.result = ((int[]) ar.result)[0];
1238 }
1239 notifyRequester(request);
1240 break;
1241 case CMD_SET_CDMA_ROAMING_MODE:
1242 request = (MainThreadRequest) msg.obj;
1243 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1244 int mode = (int) request.argument;
1245 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1246 break;
1247 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1248 ar = (AsyncResult) msg.obj;
1249 request = (MainThreadRequest) ar.userObj;
1250 request.result = ar.exception == null;
1251 notifyRequester(request);
1252 break;
1253 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1254 request = (MainThreadRequest) msg.obj;
1255 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1256 int subscriptionMode = (int) request.argument;
1257 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1258 break;
1259 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1260 ar = (AsyncResult) msg.obj;
1261 request = (MainThreadRequest) ar.userObj;
1262 request.result = ar.exception == null;
1263 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001264 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 case CMD_GET_ALL_CELL_INFO:
1266 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001267 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001268 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001269 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001270 case EVENT_GET_ALL_CELL_INFO_DONE:
1271 ar = (AsyncResult) msg.obj;
1272 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001273 // If a timeout occurs, the response will be null
1274 request.result = (ar.exception == null && ar.result != null)
1275 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001276 synchronized (request) {
1277 request.notifyAll();
1278 }
1279 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001280 case CMD_REQUEST_CELL_INFO_UPDATE:
1281 request = (MainThreadRequest) msg.obj;
1282 request.phone.requestCellInfoUpdate(request.workSource,
1283 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1284 break;
1285 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1286 ar = (AsyncResult) msg.obj;
1287 request = (MainThreadRequest) ar.userObj;
1288 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1289 try {
1290 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001291 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001292 cb.onError(
1293 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1294 ar.exception.getClass().getName(),
1295 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001296 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001297 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001298 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001299 } else {
1300 // use the result as returned
1301 cb.onCellInfo((List<CellInfo>) ar.result);
1302 }
1303 } catch (RemoteException re) {
1304 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1305 }
1306 break;
1307 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001308 request = (MainThreadRequest) msg.obj;
1309 WorkSource ws = (WorkSource) request.argument;
1310 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001311 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001312 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001313 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001314 ar = (AsyncResult) msg.obj;
1315 request = (MainThreadRequest) ar.userObj;
1316 if (ar.exception == null) {
1317 request.result = ar.result;
1318 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001319 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001320 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001321 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001322 }
1323
1324 synchronized (request) {
1325 request.notifyAll();
1326 }
1327 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001328 case CMD_MODEM_REBOOT:
1329 request = (MainThreadRequest) msg.obj;
1330 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001331 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001332 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001333 case EVENT_CMD_MODEM_REBOOT_DONE:
1334 handleNullReturnEvent(msg, "rebootModem");
1335 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001336 case CMD_REQUEST_ENABLE_MODEM:
1337 request = (MainThreadRequest) msg.obj;
1338 boolean enable = (boolean) request.argument;
1339 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001340 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001341 PhoneConfigurationManager.getInstance()
1342 .enablePhone(request.phone, enable, onCompleted);
1343 break;
1344 case EVENT_ENABLE_MODEM_DONE:
1345 ar = (AsyncResult) msg.obj;
1346 request = (MainThreadRequest) ar.userObj;
1347 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001348 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001349 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001350 if ((boolean) request.result) {
1351 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1352 updateModemStateMetrics();
1353 } else {
1354 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1355 + ar.exception);
1356 }
1357 notifyRequester(request);
1358 break;
1359 case CMD_GET_MODEM_STATUS:
1360 request = (MainThreadRequest) msg.obj;
1361 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1362 PhoneConfigurationManager.getInstance()
1363 .getPhoneStatusFromModem(request.phone, onCompleted);
1364 break;
1365 case EVENT_GET_MODEM_STATUS_DONE:
1366 ar = (AsyncResult) msg.obj;
1367 request = (MainThreadRequest) ar.userObj;
1368 int id = request.phone.getPhoneId();
1369 if (ar.exception == null && ar.result != null) {
1370 request.result = ar.result;
1371 //update the cache as modem status has changed
1372 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1373 (boolean) request.result);
1374 } else {
1375 // Return true if modem status cannot be retrieved. For most cases,
1376 // modem status is on. And for older version modems, GET_MODEM_STATUS
1377 // and disable modem are not supported. Modem is always on.
1378 // TODO: this should be fixed in R to support a third
1379 // status UNKNOWN b/131631629
1380 request.result = true;
1381 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1382 + ar.exception);
1383 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001384 notifyRequester(request);
1385 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001386 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1387 request = (MainThreadRequest) msg.obj;
1388 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1389 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1390 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1391 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1392 break;
1393 }
1394 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1395 ar = (AsyncResult) msg.obj;
1396 request = (MainThreadRequest) ar.userObj;
1397 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1398 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1399 args.second.accept(ar.exception == null);
1400 notifyRequester(request);
1401 break;
1402 }
yincheng zhao2737e882019-09-06 17:06:54 -07001403 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1404 ar = (AsyncResult) msg.obj;
1405 request = (MainThreadRequest) ar.userObj;
1406 if (ar.exception == null && ar.result != null) {
1407 request.result = ar.result;
1408 } else {
1409 request.result = -1;
1410 loge("Failed to set Forbidden Plmns");
1411 if (ar.result == null) {
1412 loge("setForbidenPlmns: Empty response");
1413 } else if (ar.exception != null) {
1414 loge("setForbiddenPlmns: Exception: " + ar.exception);
1415 request.result = -1;
1416 } else {
1417 loge("setForbiddenPlmns: Unknown exception");
1418 }
1419 }
1420 notifyRequester(request);
1421 break;
1422 case CMD_SET_FORBIDDEN_PLMNS:
1423 request = (MainThreadRequest) msg.obj;
1424 uiccCard = getUiccCardFromRequest(request);
1425 if (uiccCard == null) {
1426 loge("setForbiddenPlmns: UiccCard is null");
1427 request.result = -1;
1428 notifyRequester(request);
1429 break;
1430 }
1431 Pair<Integer, List<String>> setFplmnsArgs =
1432 (Pair<Integer, List<String>>) request.argument;
1433 appType = setFplmnsArgs.first;
1434 List<String> fplmns = setFplmnsArgs.second;
1435 uiccApp = uiccCard.getApplicationByType(appType);
1436 if (uiccApp == null) {
1437 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1438 request.result = -1;
1439 loge("Failed to get UICC App");
1440 notifyRequester(request);
1441 } else {
1442 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1443 ((SIMRecords) uiccApp.getIccRecords())
1444 .setForbiddenPlmns(onCompleted, fplmns);
1445 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001446 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001447 case CMD_ERASE_MODEM_CONFIG:
1448 request = (MainThreadRequest) msg.obj;
1449 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1450 defaultPhone.eraseModemConfig(onCompleted);
1451 break;
1452 case EVENT_ERASE_MODEM_CONFIG_DONE:
1453 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001454 break;
zoey chene02881a2019-12-30 16:11:23 +08001455
1456 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1457 request = (MainThreadRequest) msg.obj;
1458 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1459 Pair<String, String> changed = (Pair<String, String>) request.argument;
1460 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1461 changed.first, changed.second, onCompleted);
1462 break;
1463 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1464 ar = (AsyncResult) msg.obj;
1465 request = (MainThreadRequest) ar.userObj;
1466 if (ar.exception == null) {
1467 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1468 } else {
1469 request.result = msg.arg1;
1470 }
1471 notifyRequester(request);
1472 break;
1473
1474 case CMD_SET_ICC_LOCK_ENABLED:
1475 request = (MainThreadRequest) msg.obj;
1476 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1477 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1478 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1479 enabled.first, enabled.second, onCompleted);
1480 break;
1481 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1482 ar = (AsyncResult) msg.obj;
1483 request = (MainThreadRequest) ar.userObj;
1484 if (ar.exception == null) {
1485 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1486 } else {
1487 request.result = msg.arg1;
1488 }
1489 notifyRequester(request);
1490 break;
1491
Peter Wangdafb9ac2020-01-15 14:13:38 -08001492 case MSG_NOTIFY_USER_ACTIVITY:
1493 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001494 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001495 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1496 getDefaultPhone().getContext().sendBroadcastAsUser(
1497 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1498 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 default:
1500 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1501 break;
1502 }
1503 }
Jake Hambye994d462014-02-03 13:10:13 -08001504
Pengquan Menga1bb6272018-09-06 09:59:22 -07001505 private void notifyRequester(MainThreadRequest request) {
1506 synchronized (request) {
1507 request.notifyAll();
1508 }
1509 }
1510
Jake Hambye994d462014-02-03 13:10:13 -08001511 private void handleNullReturnEvent(Message msg, String command) {
1512 AsyncResult ar = (AsyncResult) msg.obj;
1513 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1514 if (ar.exception == null) {
1515 request.result = true;
1516 } else {
1517 request.result = false;
1518 if (ar.exception instanceof CommandException) {
1519 loge(command + ": CommandException: " + ar.exception);
1520 } else {
1521 loge(command + ": Unknown exception");
1522 }
1523 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001524 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 }
1527
1528 /**
1529 * Posts the specified command to be executed on the main thread,
1530 * waits for the request to complete, and returns the result.
1531 * @see #sendRequestAsync
1532 */
1533 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001534 return sendRequest(
1535 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001536 }
1537
1538 /**
1539 * Posts the specified command to be executed on the main thread,
1540 * waits for the request to complete, and returns the result.
1541 * @see #sendRequestAsync
1542 */
1543 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1544 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001545 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001546 }
1547
1548 /**
1549 * Posts the specified command to be executed on the main thread,
1550 * waits for the request to complete, and returns the result.
1551 * @see #sendRequestAsync
1552 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001553 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001554 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001555 }
1556
1557 /**
1558 * Posts the specified command to be executed on the main thread,
1559 * waits for the request to complete, and returns the result.
1560 * @see #sendRequestAsync
1561 */
Nathan Harold92bed182018-10-12 18:16:49 -07001562 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1563 return sendRequest(command, argument, subId, null, workSource);
1564 }
1565
1566 /**
1567 * Posts the specified command to be executed on the main thread,
1568 * waits for the request to complete, and returns the result.
1569 * @see #sendRequestAsync
1570 */
1571 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1572 return sendRequest(
1573 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1574 }
1575
1576 /**
1577 * Posts the specified command to be executed on the main thread,
1578 * waits for the request to complete, and returns the result.
1579 * @see #sendRequestAsync
1580 */
1581 private Object sendRequest(
1582 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1584 throw new RuntimeException("This method will deadlock if called from the main thread.");
1585 }
1586
Nathan Harold92bed182018-10-12 18:16:49 -07001587 MainThreadRequest request = null;
1588 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1589 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1590 } else if (phone != null) {
1591 request = new MainThreadRequest(argument, phone, workSource);
1592 } else {
1593 request = new MainThreadRequest(argument, subId, workSource);
1594 }
1595
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 Message msg = mMainThreadHandler.obtainMessage(command, request);
1597 msg.sendToTarget();
1598
1599 // Wait for the request to complete
1600 synchronized (request) {
1601 while (request.result == null) {
1602 try {
1603 request.wait();
1604 } catch (InterruptedException e) {
1605 // Do nothing, go back and wait until the request is complete
1606 }
1607 }
1608 }
1609 return request.result;
1610 }
1611
1612 /**
1613 * Asynchronous ("fire and forget") version of sendRequest():
1614 * Posts the specified command to be executed on the main thread, and
1615 * returns immediately.
1616 * @see #sendRequest
1617 */
1618 private void sendRequestAsync(int command) {
1619 mMainThreadHandler.sendEmptyMessage(command);
1620 }
1621
1622 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001623 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001624 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001625 */
1626 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001627 sendRequestAsync(command, argument, null, null);
1628 }
1629
1630 /**
1631 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1632 * @see {@link #sendRequest(int,Object)}
1633 */
1634 private void sendRequestAsync(
1635 int command, Object argument, Phone phone, WorkSource workSource) {
1636 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001637 Message msg = mMainThreadHandler.obtainMessage(command, request);
1638 msg.sendToTarget();
1639 }
1640
1641 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 * Initialize the singleton PhoneInterfaceManager instance.
1643 * This is only done once, at startup, from PhoneApp.onCreate().
1644 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001645 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 synchronized (PhoneInterfaceManager.class) {
1647 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001648 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 } else {
1650 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1651 }
1652 return sInstance;
1653 }
1654 }
1655
1656 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001657 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001660 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001661 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1663 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001664 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001665 mTelephonySharedPreferences =
1666 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001667 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001668 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001669 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001670
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 publish();
1672 }
1673
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001674 private Phone getDefaultPhone() {
1675 Phone thePhone = getPhone(getDefaultSubscription());
1676 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1677 }
1678
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 private void publish() {
1680 if (DBG) log("publish: " + this);
1681
Peter Wangc035ce42020-01-08 21:00:22 -08001682 TelephonyFrameworkInitializer
1683 .getTelephonyServiceManager()
1684 .getTelephonyServiceRegisterer()
1685 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687
Stuart Scott584921c2015-01-15 17:10:34 -08001688 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001689 if (request.phone != null) {
1690 return request.phone;
1691 } else {
1692 return getPhoneFromSubId(request.subId);
1693 }
1694 }
1695
1696 private Phone getPhoneFromSubId(int subId) {
1697 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1698 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001699 }
1700
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001701 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1702 Phone phone = getPhoneFromRequest(request);
1703 return phone == null ? null :
1704 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1705 }
1706
Wink Saville36469e72014-06-11 15:17:00 -07001707 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001708 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001709 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001710 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711
Naina Nallurid63128d2019-09-17 14:10:30 -07001712 private void sendEraseModemConfig(Phone phone) {
1713 if (phone != null) {
1714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1715 mApp, phone.getSubId(), "eraseModemConfig");
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1719 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
1722 }
1723 }
1724 }
1725
Peter Wang44b186e2020-01-13 23:33:09 -08001726 private boolean isImsAvailableOnDevice() {
1727 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1728 if (pm == null) {
1729 // For some reason package manger is not available.. This will fail internally anyway,
1730 // so do not throw error and allow.
1731 return true;
1732 }
1733 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1734 }
1735
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001738 }
1739
Wink Savilleb564aae2014-10-23 10:18:09 -07001740 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 if (DBG) log("dial: " + number);
1742 // No permission check needed here: This is just a wrapper around the
1743 // ACTION_DIAL intent, which is available to any app since it puts up
1744 // the UI before it does anything.
1745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746 final long identity = Binder.clearCallingIdentity();
1747 try {
1748 String url = createTelUrl(number);
1749 if (url == null) {
1750 return;
1751 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001753 // PENDING: should we just silently fail if phone is offhook or ringing?
1754 PhoneConstants.State state = mCM.getState(subId);
1755 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1756 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1757 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1758 mApp.startActivity(intent);
1759 }
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763 }
1764
1765 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001766 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
1768
Wink Savilleb564aae2014-10-23 10:18:09 -07001769 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 if (DBG) log("call: " + number);
1771
1772 // This is just a wrapper around the ACTION_CALL intent, but we still
1773 // need to do a permission check since we're calling startActivity()
1774 // from the context of the phone app.
1775 enforceCallPermission();
1776
Jordan Liu1617b712019-07-10 15:06:26 -07001777 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 != AppOpsManager.MODE_ALLOWED) {
1779 return;
1780 }
1781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782 final long identity = Binder.clearCallingIdentity();
1783 try {
1784 String url = createTelUrl(number);
1785 if (url == null) {
1786 return;
1787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001789 boolean isValid = false;
1790 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1791 if (slist != null) {
1792 for (SubscriptionInfo subInfoRecord : slist) {
1793 if (subInfoRecord.getSubscriptionId() == subId) {
1794 isValid = true;
1795 break;
1796 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001797 }
Wink Saville08874612014-08-31 19:19:58 -07001798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 if (!isValid) {
1800 return;
1801 }
Wink Saville08874612014-08-31 19:19:58 -07001802
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001803 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1804 intent.putExtra(SUBSCRIPTION_KEY, subId);
1805 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1806 mApp.startActivity(intent);
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
1809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 }
1811
Wink Savilleb564aae2014-10-23 10:18:09 -07001812 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001813 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001814 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1815 }
1816
Wink Savilleb564aae2014-10-23 10:18:09 -07001817 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001818 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001819 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1820 }
1821
Wink Savilleb564aae2014-10-23 10:18:09 -07001822 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001824
1825 final long identity = Binder.clearCallingIdentity();
1826 try {
1827 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1828 checkSimPin.start();
1829 return checkSimPin.unlockSim(null, pin);
1830 } finally {
1831 Binder.restoreCallingIdentity(identity);
1832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 }
1834
Wink Savilleb564aae2014-10-23 10:18:09 -07001835 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837
1838 final long identity = Binder.clearCallingIdentity();
1839 try {
1840 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1841 checkSimPuk.start();
1842 return checkSimPuk.unlockSim(puk, pin);
1843 } finally {
1844 Binder.restoreCallingIdentity(identity);
1845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 }
1847
1848 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001849 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 * a synchronous one.
1851 */
1852 private static class UnlockSim extends Thread {
1853
1854 private final IccCard mSimCard;
1855
1856 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001857 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1858 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859
1860 // For replies from SimCard interface
1861 private Handler mHandler;
1862
1863 // For async handler to identify request type
1864 private static final int SUPPLY_PIN_COMPLETE = 100;
1865
1866 public UnlockSim(IccCard simCard) {
1867 mSimCard = simCard;
1868 }
1869
1870 @Override
1871 public void run() {
1872 Looper.prepare();
1873 synchronized (UnlockSim.this) {
1874 mHandler = new Handler() {
1875 @Override
1876 public void handleMessage(Message msg) {
1877 AsyncResult ar = (AsyncResult) msg.obj;
1878 switch (msg.what) {
1879 case SUPPLY_PIN_COMPLETE:
1880 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1881 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001882 mRetryCount = msg.arg1;
1883 if (ar.exception != null) {
1884 if (ar.exception instanceof CommandException &&
1885 ((CommandException)(ar.exception)).getCommandError()
1886 == CommandException.Error.PASSWORD_INCORRECT) {
1887 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001888 } //When UiccCardApp dispose,handle message and return exception
1889 else if (ar.exception instanceof CommandException &&
1890 ((CommandException) (ar.exception)).getCommandError()
1891 == CommandException.Error.ABORTED) {
1892 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001893 } else {
1894 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1895 }
1896 } else {
1897 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1898 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 mDone = true;
1900 UnlockSim.this.notifyAll();
1901 }
1902 break;
1903 }
1904 }
1905 };
1906 UnlockSim.this.notifyAll();
1907 }
1908 Looper.loop();
1909 }
1910
1911 /*
1912 * Use PIN or PUK to unlock SIM card
1913 *
1914 * If PUK is null, unlock SIM card with PIN
1915 *
1916 * If PUK is not null, unlock SIM card with PUK and set PIN code
1917 */
Wink Saville9de0f752013-10-22 19:04:03 -07001918 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919
1920 while (mHandler == null) {
1921 try {
1922 wait();
1923 } catch (InterruptedException e) {
1924 Thread.currentThread().interrupt();
1925 }
1926 }
1927 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1928
1929 if (puk == null) {
1930 mSimCard.supplyPin(pin, callback);
1931 } else {
1932 mSimCard.supplyPuk(puk, pin, callback);
1933 }
1934
1935 while (!mDone) {
1936 try {
1937 Log.d(LOG_TAG, "wait for done");
1938 wait();
1939 } catch (InterruptedException e) {
1940 // Restore the interrupted status
1941 Thread.currentThread().interrupt();
1942 }
1943 }
1944 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001945 int[] resultArray = new int[2];
1946 resultArray[0] = mResult;
1947 resultArray[1] = mRetryCount;
1948 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 }
1950 }
1951
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001952 /**
1953 * This method has been removed due to privacy and stability concerns.
1954 */
1955 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001957 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
1958 return;
Wink Saville36469e72014-06-11 15:17:00 -07001959 }
1960
Nathan Harold1f889d82020-06-04 17:05:26 -07001961 @Override
1962 public void updateServiceLocationWithPackageName(String callingPackage) {
1963 mApp.getSystemService(AppOpsManager.class)
1964 .checkPackage(Binder.getCallingUid(), callingPackage);
1965
1966 final int targetSdk = getTargetSdk(callingPackage);
1967 if (targetSdk > android.os.Build.VERSION_CODES.R) {
1968 // Callers targeting S have no business invoking this method.
1969 return;
1970 }
1971
1972 LocationAccessPolicy.LocationPermissionResult locationResult =
1973 LocationAccessPolicy.checkLocationPermission(mApp,
1974 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1975 .setCallingPackage(callingPackage)
1976 .setCallingFeatureId(null)
1977 .setCallingPid(Binder.getCallingPid())
1978 .setCallingUid(Binder.getCallingUid())
1979 .setMethod("updateServiceLocation")
1980 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
1981 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1982 .build());
1983 // Apps that lack location permission have no business calling this method;
1984 // however, because no permission was declared in the public API, denials must
1985 // all be "soft".
1986 switch (locationResult) {
1987 case DENIED_HARD: /* fall through */
1988 case DENIED_SOFT:
1989 return;
1990 }
1991
1992 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001993 final long identity = Binder.clearCallingIdentity();
1994 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07001995 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07001997 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998 }
1999 } finally {
2000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 }
2003
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002004 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002005 @Override
2006 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002007 return isRadioOnWithFeature(callingPackage, null);
2008 }
2009
2010
2011 @Override
2012 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2013 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2014 callingFeatureId);
2015 }
2016
2017 @Deprecated
2018 @Override
2019 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2020 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002021 }
2022
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002023 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002024 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2025 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002027 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002028 return false;
2029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030
2031 final long identity = Binder.clearCallingIdentity();
2032 try {
2033 return isRadioOnForSubscriber(subId);
2034 } finally {
2035 Binder.restoreCallingIdentity(identity);
2036 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002037 }
2038
2039 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 final long identity = Binder.clearCallingIdentity();
2041 try {
2042 final Phone phone = getPhone(subId);
2043 if (phone != null) {
2044 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2045 } else {
2046 return false;
2047 }
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 }
2052
2053 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002054 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 }
Wink Saville36469e72014-06-11 15:17:00 -07002056
Wink Savilleb564aae2014-10-23 10:18:09 -07002057 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
2062 final Phone phone = getPhone(subId);
2063 if (phone != null) {
2064 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2065 }
2066 } finally {
2067 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002068 }
Wink Saville36469e72014-06-11 15:17:00 -07002069 }
2070
2071 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002072 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002073 }
2074
Wink Savilleb564aae2014-10-23 10:18:09 -07002075 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002076 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002077
2078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 final Phone phone = getPhone(subId);
2081 if (phone == null) {
2082 return false;
2083 }
2084 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2085 toggleRadioOnOffForSubscriber(subId);
2086 }
2087 return true;
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 }
Wink Saville36469e72014-06-11 15:17:00 -07002092
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002093 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002094 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002095 /*
2096 * If any of the Radios are available, it will need to be
2097 * shutdown. So return true if any Radio is available.
2098 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099 final long identity = Binder.clearCallingIdentity();
2100 try {
2101 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2102 Phone phone = PhoneFactory.getPhone(i);
2103 if (phone != null && phone.isRadioAvailable()) return true;
2104 }
2105 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2106 return false;
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002109 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002110 }
2111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002113 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002114 enforceModifyPermission();
2115
2116 final long identity = Binder.clearCallingIdentity();
2117 try {
2118 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2119 logv("Shutting down Phone " + i);
2120 shutdownRadioUsingPhoneId(i);
2121 }
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002124 }
2125 }
2126
2127 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002128 Phone phone = PhoneFactory.getPhone(phoneId);
2129 if (phone != null && phone.isRadioAvailable()) {
2130 phone.shutdownRadio();
2131 }
2132 }
2133
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002136
2137 final long identity = Binder.clearCallingIdentity();
2138 try {
2139 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2140 if (defaultPhone != null) {
2141 defaultPhone.setRadioPower(turnOn);
2142 return true;
2143 } else {
2144 loge("There's no default phone.");
2145 return false;
2146 }
2147 } finally {
2148 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002149 }
Wink Saville36469e72014-06-11 15:17:00 -07002150 }
2151
Wink Savilleb564aae2014-10-23 10:18:09 -07002152 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002154
2155 final long identity = Binder.clearCallingIdentity();
2156 try {
2157 final Phone phone = getPhone(subId);
2158 if (phone != null) {
2159 phone.setRadioPower(turnOn);
2160 return true;
2161 } else {
2162 return false;
2163 }
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
Wink Saville36469e72014-06-11 15:17:00 -07002169 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002170 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 public boolean enableDataConnectivity() {
2172 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002173
2174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 int subId = mSubscriptionController.getDefaultDataSubId();
2177 final Phone phone = getPhone(subId);
2178 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002179 phone.getDataEnabledSettings().setDataEnabled(
2180 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002181 return true;
2182 } else {
2183 return false;
2184 }
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 }
2189
Wink Saville36469e72014-06-11 15:17:00 -07002190 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002191 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 public boolean disableDataConnectivity() {
2193 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002194
2195 final long identity = Binder.clearCallingIdentity();
2196 try {
2197 int subId = mSubscriptionController.getDefaultDataSubId();
2198 final Phone phone = getPhone(subId);
2199 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002200 phone.getDataEnabledSettings().setDataEnabled(
2201 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002202 return true;
2203 } else {
2204 return false;
2205 }
2206 } finally {
2207 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 }
2210
Sanket Padawe356d7632015-06-22 14:03:32 -07002211 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002212 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002213 final long identity = Binder.clearCallingIdentity();
2214 try {
2215 final Phone phone = getPhone(subId);
2216 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002217 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002218 } else {
2219 return false;
2220 }
2221 } finally {
2222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 }
2225
2226 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002227 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002228 }
2229
pkanwarae03a6b2016-11-06 20:37:09 -08002230 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231 enforceCallPermission();
2232
2233 final long identity = Binder.clearCallingIdentity();
2234 try {
2235 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2236 return;
2237 }
2238 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2239 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2240 } finally {
2241 Binder.restoreCallingIdentity(identity);
2242 }
pkanwar32d516d2016-10-14 19:37:38 -07002243 };
2244
Wink Savilleb564aae2014-10-23 10:18:09 -07002245 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247
2248 final long identity = Binder.clearCallingIdentity();
2249 try {
2250 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2251 return false;
2252 }
2253 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2254 } finally {
2255 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 }
2258
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002260 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002261 }
2262
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002263 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 Phone phone = PhoneFactory.getPhone(slotIndex);
2267 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2268 PhoneConstantConversions.convertCallState(phone.getState());
2269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 }
2273
Sanket Padawe356d7632015-06-22 14:03:32 -07002274 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002275 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002276 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2277 }
2278
2279 @Override
2280 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002281 final long identity = Binder.clearCallingIdentity();
2282 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002283 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284 if (phone != null) {
2285 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2286 } else {
2287 return PhoneConstantConversions.convertDataState(
2288 PhoneConstants.DataState.DISCONNECTED);
2289 }
2290 } finally {
2291 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
Sanket Padawe356d7632015-06-22 14:03:32 -07002295 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002296 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002297 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2298 }
2299
2300 @Override
2301 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302 final long identity = Binder.clearCallingIdentity();
2303 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002304 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 if (phone != null) {
2306 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2307 } else {
2308 return TelephonyManager.DATA_ACTIVITY_NONE;
2309 }
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
2315 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002316 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002317 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002318 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002319
2320 LocationAccessPolicy.LocationPermissionResult locationResult =
2321 LocationAccessPolicy.checkLocationPermission(mApp,
2322 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2323 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002324 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002325 .setCallingPid(Binder.getCallingPid())
2326 .setCallingUid(Binder.getCallingUid())
2327 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002328 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002329 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2330 .build());
2331 switch (locationResult) {
2332 case DENIED_HARD:
2333 throw new SecurityException("Not allowed to access cell location");
2334 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002335 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2336 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 }
2338
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002339 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340 final long identity = Binder.clearCallingIdentity();
2341 try {
2342 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002343 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002344 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345 } finally {
2346 Binder.restoreCallingIdentity(identity);
2347 }
Svetoslav64fad262015-04-14 14:35:21 -07002348 }
2349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002351 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002352 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2353 // registered cell info, so return a NULL country instead.
2354 final long identity = Binder.clearCallingIdentity();
2355 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002356 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2357 // Get default phone in this case.
2358 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2359 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002360 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002361 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002362 if (phone == null) return "";
2363 ServiceStateTracker sst = phone.getServiceStateTracker();
2364 if (sst == null) return "";
2365 LocaleTracker lt = sst.getLocaleTracker();
2366 if (lt == null) return "";
2367 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2368 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2369 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002370 } finally {
2371 Binder.restoreCallingIdentity(identity);
2372 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002373 }
2374
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002375 /**
2376 * This method was removed due to potential issues caused by performing partial
2377 * updates of service state, and lack of a credible use case.
2378 *
2379 * This has the ability to break the telephony implementation by disabling notification of
2380 * changes in device connectivity. DO NOT USE THIS!
2381 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002382 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 public void enableLocationUpdates() {
2384 mApp.enforceCallingOrSelfPermission(
2385 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 }
2387
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002388 /**
2389 * This method was removed due to potential issues caused by performing partial
2390 * updates of service state, and lack of a credible use case.
2391 *
2392 * This has the ability to break the telephony implementation by disabling notification of
2393 * changes in device connectivity. DO NOT USE THIS!
2394 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 @Override
2396 public void disableLocationUpdates() {
2397 mApp.enforceCallingOrSelfPermission(
2398 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 }
2400
Nathan Harold31d7ff32018-10-15 20:20:30 -07002401 /**
2402 * Returns the target SDK version number for a given package name.
2403 *
Nathan Haroldec184742019-07-10 17:04:16 -07002404 * This call MUST be invoked before clearing the calling UID.
2405 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002406 * @return target SDK if the package is found or INT_MAX.
2407 */
2408 private int getTargetSdk(String packageName) {
2409 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002410 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002411 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002412 if (ai != null) return ai.targetSdkVersion;
2413 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002414 loge("Failed to get package info for pkg="
2415 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002416 }
2417 return Integer.MAX_VALUE;
2418 }
2419
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 @Override
2421 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002422 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2423 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002424 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002425 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2426 throw new SecurityException(
2427 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2428 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002429
Jordan Liu1617b712019-07-10 15:06:26 -07002430 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2432 return null;
2433 }
Svetoslav64fad262015-04-14 14:35:21 -07002434
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002435 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002437 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002438 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439
Nathan Haroldf180aac2018-06-01 18:43:55 -07002440 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2441 for (CellInfo ci : info) {
2442 if (ci instanceof CellInfoGsm) {
2443 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2444 } else if (ci instanceof CellInfoWcdma) {
2445 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002448 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 }
2450
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002451 private List<CellInfo> getCachedCellInfo() {
2452 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2453 for (Phone phone : PhoneFactory.getPhones()) {
2454 List<CellInfo> info = phone.getAllCellInfo();
2455 if (info != null) cellInfos.addAll(info);
2456 }
2457 return cellInfos;
2458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459
2460 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002461 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002462 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002463 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002464
2465 LocationAccessPolicy.LocationPermissionResult locationResult =
2466 LocationAccessPolicy.checkLocationPermission(mApp,
2467 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2468 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002469 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002470 .setCallingPid(Binder.getCallingPid())
2471 .setCallingUid(Binder.getCallingUid())
2472 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002473 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002474 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2475 .build());
2476 switch (locationResult) {
2477 case DENIED_HARD:
2478 throw new SecurityException("Not allowed to access cell info");
2479 case DENIED_SOFT:
2480 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 }
2482
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002483 final int targetSdk = getTargetSdk(callingPackage);
2484 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2485 return getCachedCellInfo();
2486 }
2487
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002488 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002489 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2493 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002494 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002495 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496 if (info != null) cellInfos.addAll(info);
2497 }
2498 return cellInfos;
2499 } finally {
2500 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502 }
2503
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002504 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002505 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2506 String callingFeatureId) {
2507 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2508 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002509 }
2510
2511 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002512 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2513 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002514 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002515 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002516 }
2517
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002518 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2519 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002520 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002521 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002522
2523 LocationAccessPolicy.LocationPermissionResult locationResult =
2524 LocationAccessPolicy.checkLocationPermission(mApp,
2525 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2526 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002527 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002528 .setCallingPid(Binder.getCallingPid())
2529 .setCallingUid(Binder.getCallingUid())
2530 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002531 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2532 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002533 .build());
2534 switch (locationResult) {
2535 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002536 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2537 // Safetynet logging for b/154934934
2538 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2539 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002540 throw new SecurityException("Not allowed to access cell info");
2541 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002542 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2543 // Safetynet logging for b/154934934
2544 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2545 }
Nathan Harold5320c422019-05-09 10:26:08 -07002546 try {
2547 cb.onCellInfo(new ArrayList<CellInfo>());
2548 } catch (RemoteException re) {
2549 // Drop without consequences
2550 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002551 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002552 }
2553
Nathan Harolda939a962019-05-09 10:13:47 -07002554
2555 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002556 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2557
2558 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2559 }
2560
2561 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002563 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002564 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002568 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569 } finally {
2570 Binder.restoreCallingIdentity(identity);
2571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
2573
Shishir Agrawala9f32182016-04-12 12:00:16 -07002574 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002575 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002576 Phone phone = PhoneFactory.getPhone(slotIndex);
2577 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 return null;
2579 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002580 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002581 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002582 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002583 return null;
2584 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585
2586 final long identity = Binder.clearCallingIdentity();
2587 try {
2588 return phone.getImei();
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002592 }
2593
2594 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002595 public String getTypeAllocationCodeForSlot(int slotIndex) {
2596 Phone phone = PhoneFactory.getPhone(slotIndex);
2597 String tac = null;
2598 if (phone != null) {
2599 String imei = phone.getImei();
2600 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2601 }
2602 return tac;
2603 }
2604
2605 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002606 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002607 Phone phone = PhoneFactory.getPhone(slotIndex);
2608 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002609 return null;
2610 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002611
Jeff Davidson913390f2018-02-23 17:11:49 -08002612 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002613 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002614 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002615 return null;
2616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617
2618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 return phone.getMeid();
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
2623 }
Jack Yu2af8d712017-03-15 17:14:14 -07002624 }
2625
2626 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002627 public String getManufacturerCodeForSlot(int slotIndex) {
2628 Phone phone = PhoneFactory.getPhone(slotIndex);
2629 String manufacturerCode = null;
2630 if (phone != null) {
2631 String meid = phone.getMeid();
2632 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2633 }
2634 return manufacturerCode;
2635 }
2636
2637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002638 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2639 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002640 Phone phone = PhoneFactory.getPhone(slotIndex);
2641 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002642 return null;
2643 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002644 int subId = phone.getSubId();
2645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002646 mApp, subId, callingPackage, callingFeatureId,
2647 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002648 return null;
2649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650
2651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 return phone.getDeviceSvn();
2654 } finally {
2655 Binder.restoreCallingIdentity(identity);
2656 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002657 }
2658
fionaxu43304da2017-11-27 22:51:16 -08002659 @Override
2660 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 final Phone phone = getPhone(subId);
2664 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
fionaxu43304da2017-11-27 22:51:16 -08002668 }
2669
2670 @Override
2671 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 final long identity = Binder.clearCallingIdentity();
2673 try {
2674 final Phone phone = getPhone(subId);
2675 return phone == null ? null : phone.getCarrierName();
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
2678 }
fionaxu43304da2017-11-27 22:51:16 -08002679 }
2680
calvinpanffe225e2018-11-01 19:43:06 +08002681 @Override
chen xu0026ca62019-03-06 15:28:50 -08002682 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 final Phone phone = getPhone(subId);
2686 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002687 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
2691 }
2692
2693 @Override
chen xu0026ca62019-03-06 15:28:50 -08002694 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002695 final long identity = Binder.clearCallingIdentity();
2696 try {
2697 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002698 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002699 } finally {
2700 Binder.restoreCallingIdentity(identity);
2701 }
2702 }
2703
chen xu651eec72018-11-11 19:03:44 -08002704 @Override
chen xu864e11c2018-12-06 22:10:03 -08002705 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2706 if (!isSubscriptionMccMnc) {
2707 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2708 }
chen xu651eec72018-11-11 19:03:44 -08002709 final Phone phone = PhoneFactory.getPhone(slotIndex);
2710 if (phone == null) {
2711 return TelephonyManager.UNKNOWN_CARRIER_ID;
2712 }
2713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2716 } finally {
2717 Binder.restoreCallingIdentity(identity);
2718 }
2719 }
2720
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 //
2722 // Internal helper methods.
2723 //
2724
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002725 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2727 *
2728 * @throws SecurityException if the caller does not have the required permission
2729 */
2730 private void enforceModifyPermission() {
2731 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2732 }
2733
Shuo Qiancd19c462020-01-16 20:51:11 -08002734 /**
2735 * Make sure the caller is system.
2736 *
2737 * @throws SecurityException if the caller is not system.
2738 */
2739 private void enforceSystemCaller() {
2740 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2741 throw new SecurityException("Caller must be system");
2742 }
2743 }
2744
Shuo Qian3b6ee772019-11-13 17:43:31 -08002745 private void enforceActiveEmergencySessionPermission() {
2746 mApp.enforceCallingOrSelfPermission(
2747 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2748 }
2749
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750 /**
2751 * Make sure the caller has the CALL_PHONE permission.
2752 *
2753 * @throws SecurityException if the caller does not have the required permission
2754 */
2755 private void enforceCallPermission() {
2756 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2757 }
2758
paulhu5a773602019-08-23 19:17:33 +08002759 private void enforceSettingsPermission() {
2760 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002761 }
2762
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 private String createTelUrl(String number) {
2764 if (TextUtils.isEmpty(number)) {
2765 return null;
2766 }
2767
Jake Hambye994d462014-02-03 13:10:13 -08002768 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
Ihab Awadf9e92732013-12-05 18:02:52 -08002771 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2773 }
2774
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002775 private static void logv(String msg) {
2776 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2777 }
2778
Ihab Awadf9e92732013-12-05 18:02:52 -08002779 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2781 }
2782
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002783 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002785 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002786 }
2787
Sanket Padawe356d7632015-06-22 14:03:32 -07002788 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002789 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 final long identity = Binder.clearCallingIdentity();
2791 try {
2792 final Phone phone = PhoneFactory.getPhone(slotIndex);
2793 if (phone == null) {
2794 return PhoneConstants.PHONE_TYPE_NONE;
2795 } else {
2796 return phone.getPhoneType();
2797 }
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002800 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002801 }
2802
2803 /**
2804 * Returns the CDMA ERI icon index to display
2805 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002806 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002807 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2808 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2809 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002810 }
2811
Sanket Padawe356d7632015-06-22 14:03:32 -07002812 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002813 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2814 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002816 mApp, subId, callingPackage, callingFeatureId,
2817 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002818 return -1;
2819 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 final Phone phone = getPhone(subId);
2824 if (phone != null) {
2825 return phone.getCdmaEriIconIndex();
2826 } else {
2827 return -1;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 }
2833
2834 /**
2835 * Returns the CDMA ERI icon mode,
2836 * 0 - ON
2837 * 1 - FLASHING
2838 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002839 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002840 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2841 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2842 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002843 }
2844
Sanket Padawe356d7632015-06-22 14:03:32 -07002845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002846 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2847 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002849 mApp, subId, callingPackage, callingFeatureId,
2850 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002851 return -1;
2852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 final Phone phone = getPhone(subId);
2857 if (phone != null) {
2858 return phone.getCdmaEriIconMode();
2859 } else {
2860 return -1;
2861 }
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
2866
2867 /**
2868 * Returns the CDMA ERI text,
2869 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002870 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002871 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2872 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2873 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002874 }
2875
Sanket Padawe356d7632015-06-22 14:03:32 -07002876 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002877 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2878 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002880 mApp, subId, callingPackage, callingFeatureId,
2881 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002882 return null;
2883 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884
2885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 final Phone phone = getPhone(subId);
2888 if (phone != null) {
2889 return phone.getCdmaEriText();
2890 } else {
2891 return null;
2892 }
2893 } finally {
2894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 }
2897
2898 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002899 * Returns the CDMA MDN.
2900 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002902 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2904 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905
2906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002909 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 return phone.getLine1Number();
2911 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002912 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 return null;
2914 }
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002917 }
2918 }
2919
2920 /**
2921 * Returns the CDMA MIN.
2922 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002923 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002924 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2926 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 final Phone phone = getPhone(subId);
2931 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2932 return phone.getCdmaMin();
2933 } else {
2934 return null;
2935 }
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002938 }
2939 }
2940
Hall Liud892bec2018-11-30 14:51:45 -08002941 @Override
2942 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2943 INumberVerificationCallback callback, String callingPackage) {
2944 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2945 != PERMISSION_GRANTED) {
2946 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2947 }
2948 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2949
2950 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2951 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2952 throw new SecurityException("Calling package must be configured in the device config");
2953 }
2954
2955 if (range == null) {
2956 throw new NullPointerException("Range must be non-null");
2957 }
2958
2959 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002960 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002961
2962 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2963 }
2964
Junda Liuca05d5d2014-08-14 22:36:34 -07002965 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002966 * Returns true if CDMA provisioning needs to run.
2967 */
2968 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969 final long identity = Binder.clearCallingIdentity();
2970 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002971 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 }
2976
2977 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002978 * Sets the voice mail number of a given subId.
2979 */
2980 @Override
2981 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002982 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2983 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984
2985 final long identity = Binder.clearCallingIdentity();
2986 try {
2987 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2988 new Pair<String, String>(alphaTag, number), new Integer(subId));
2989 return success;
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002993 }
2994
Ta-wei Yen87c49842016-05-13 21:19:52 -07002995 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002996 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2997 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002998 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2999 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003000 if (!TextUtils.equals(callingPackage, systemDialer)) {
3001 throw new SecurityException("caller must be system dialer");
3002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003
3004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3007 if (phoneAccountHandle == null) {
3008 return null;
3009 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003010 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011 } finally {
3012 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003013 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003014 }
3015
3016 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003017 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3018 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003019 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003021 mApp, subId, callingPackage, callingFeatureId,
3022 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003023 return null;
3024 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003026 final long identity = Binder.clearCallingIdentity();
3027 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003028 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003029 } finally {
3030 Binder.restoreCallingIdentity(identity);
3031 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003032 }
3033
3034 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003035 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3036 VisualVoicemailSmsFilterSettings settings) {
3037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003046 }
3047
3048 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003049 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3050 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
3054 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003055 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003059 }
3060
3061 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003062 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3063 String callingPackage, int subId) {
3064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065
3066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003069 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070 } finally {
3071 Binder.restoreCallingIdentity(identity);
3072 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003073 }
3074
3075 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003076 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078
3079 final long identity = Binder.clearCallingIdentity();
3080 try {
3081 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003082 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003086 }
3087
3088 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003089 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3090 String callingAttributionTag, int subId, String number, int port, String text,
3091 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003092 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003093 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003094 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003095 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003096 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3097 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003098 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003099
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003100 /**
fionaxu0152e512016-11-14 13:36:14 -08003101 * Sets the voice activation state of a given subId.
3102 */
3103 @Override
3104 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3106 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107
3108 final long identity = Binder.clearCallingIdentity();
3109 try {
3110 final Phone phone = getPhone(subId);
3111 if (phone != null) {
3112 phone.setVoiceActivationState(activationState);
3113 } else {
3114 loge("setVoiceActivationState fails with invalid subId: " + subId);
3115 }
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003118 }
3119 }
3120
3121 /**
3122 * Sets the data activation state of a given subId.
3123 */
3124 @Override
3125 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3127 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003128
3129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 final Phone phone = getPhone(subId);
3132 if (phone != null) {
3133 phone.setDataActivationState(activationState);
3134 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003135 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136 }
3137 } finally {
3138 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003139 }
3140 }
3141
3142 /**
3143 * Returns the voice activation state of a given subId.
3144 */
3145 @Override
3146 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003147 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148
fionaxu0152e512016-11-14 13:36:14 -08003149 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 if (phone != null) {
3153 return phone.getVoiceActivationState();
3154 } else {
3155 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3156 }
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003159 }
3160 }
3161
3162 /**
3163 * Returns the data activation state of a given subId.
3164 */
3165 @Override
3166 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003167 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168
fionaxu0152e512016-11-14 13:36:14 -08003169 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 final long identity = Binder.clearCallingIdentity();
3171 try {
3172 if (phone != null) {
3173 return phone.getDataActivationState();
3174 } else {
3175 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3176 }
3177 } finally {
3178 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003179 }
3180 }
3181
3182 /**
Wink Saville36469e72014-06-11 15:17:00 -07003183 * Returns the unread count of voicemails for a subId
3184 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003186 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3187 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003189 mApp, subId, callingPackage, callingFeatureId,
3190 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003191 return 0;
3192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 final Phone phone = getPhone(subId);
3196 if (phone != null) {
3197 return phone.getVoiceMessageCount();
3198 } else {
3199 return 0;
3200 }
3201 } finally {
3202 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 }
3205
3206 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003207 * returns true, if the device is in a state where both voice and data
3208 * are supported simultaneously. This can change based on location or network condition.
3209 */
3210 @Override
3211 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 final Phone phone = getPhone(subId);
3215 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003219 }
3220
3221 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003222 * Send the dialer code if called from the current default dialer or the caller has
3223 * carrier privilege.
3224 * @param inputCode The dialer code to send
3225 */
3226 @Override
3227 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003228 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003229 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003230 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3231 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003232 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003233 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003234 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003239 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
fionaxu235cc5e2017-03-06 22:25:57 -08003243 }
3244
Pengquan Menga1bb6272018-09-06 09:59:22 -07003245 @Override
3246 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003247 TelephonyPermissions
3248 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3249 mApp, subId, "getNetworkSelectionMode");
3250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 if (!isActiveSubscription(subId)) {
3253 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3254 }
3255 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003259 }
3260
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003262 public boolean isInEmergencySmsMode() {
3263 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 for (Phone phone : PhoneFactory.getPhones()) {
3267 if (phone.isInEmergencySmsMode()) {
3268 return true;
3269 }
3270 }
3271 } finally {
3272 Binder.restoreCallingIdentity(identity);
3273 }
3274 return false;
3275 }
3276
shilu366312e2019-12-17 09:28:10 -08003277 /**
3278 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3279 * @param subId The subscription to use to check the configuration.
3280 * @param c The callback that will be used to send the result.
3281 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003282 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003283 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3284 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003285 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3286 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003287
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003288 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3289 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3290 "IMS not available on device.");
3291 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 final long token = Binder.clearCallingIdentity();
3293 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003295 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003296 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003297 } catch (ImsException e) {
3298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003299 } finally {
3300 Binder.restoreCallingIdentity(token);
3301 }
3302 }
3303
shilu366312e2019-12-17 09:28:10 -08003304 /**
3305 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3306 * @param subId The subscription to use to check the configuration.
3307 * @param c The callback that will be used to send the result.
3308 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003309 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003310 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003311 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3312 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003313 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3314 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3315 }
Meng Wangafbc5852019-09-19 17:37:13 -07003316 final long token = Binder.clearCallingIdentity();
3317 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003318 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003319 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3320 .removeRegistrationCallbackForSubscription(c, subId);
3321 } catch (ImsException e) {
3322 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3323 + "is inactive, ignoring unregister.");
3324 // If the subscription is no longer active, just return, since the callback
3325 // will already have been removed internally.
3326 } finally {
3327 Binder.restoreCallingIdentity(token);
3328 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003329 }
3330
Brad Ebingera34a6c22019-10-22 17:36:18 -07003331 /**
3332 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3333 */
3334 @Override
3335 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3336 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3337 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3338 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3339 "IMS not available on device.");
3340 }
3341 final long token = Binder.clearCallingIdentity();
3342 try {
3343 Phone phone = getPhone(subId);
3344 if (phone == null) {
3345 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3346 + subId + "'");
3347 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3348 }
3349 phone.getImsRegistrationState(regState -> {
3350 try {
3351 consumer.accept((regState == null)
3352 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3353 } catch (RemoteException e) {
3354 // Ignore if the remote process is no longer available to call back.
3355 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3356 }
3357 });
3358 } finally {
3359 Binder.restoreCallingIdentity(token);
3360 }
3361 }
3362
3363 /**
3364 * Get the transport type for the IMS service registration state.
3365 */
3366 @Override
3367 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003368 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3369 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003370 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3371 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3372 "IMS not available on device.");
3373 }
3374 final long token = Binder.clearCallingIdentity();
3375 try {
3376 Phone phone = getPhone(subId);
3377 if (phone == null) {
3378 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3379 + subId + "'");
3380 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3381 }
3382 phone.getImsRegistrationTech(regTech -> {
3383 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3384 int regTechConverted = (regTech == null)
3385 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3386 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3387 regTechConverted);
3388 try {
3389 consumer.accept(regTechConverted);
3390 } catch (RemoteException e) {
3391 // Ignore if the remote process is no longer available to call back.
3392 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3393 }
3394 });
3395 } finally {
3396 Binder.restoreCallingIdentity(token);
3397 }
3398 }
3399
shilu366312e2019-12-17 09:28:10 -08003400 /**
3401 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3402 * @param subId The subscription to use to check the configuration.
3403 * @param c The callback that will be used to send the result.
3404 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003405 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003406 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3407 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003408 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3409 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003410 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3411 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3412 "IMS not available on device.");
3413 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3415 final long token = Binder.clearCallingIdentity();
3416 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003417 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003418 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003419 } catch (ImsException e) {
3420 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 } finally {
3422 Binder.restoreCallingIdentity(token);
3423 }
3424 }
3425
shilu366312e2019-12-17 09:28:10 -08003426 /**
3427 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3428 * @param subId The subscription to use to check the configuration.
3429 * @param c The callback that will be used to send the result.
3430 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003431 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003432 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003433 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3434 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003435 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3436 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3437 }
Meng Wangafbc5852019-09-19 17:37:13 -07003438
3439 final long token = Binder.clearCallingIdentity();
3440 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003441 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003442 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003443 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003444 } catch (ImsException e) {
3445 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3446 + "is inactive, ignoring unregister.");
3447 // If the subscription is no longer active, just return, since the callback
3448 // will already have been removed internally.
3449 } finally {
3450 Binder.restoreCallingIdentity(token);
3451 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003452 }
3453
3454 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003455 public boolean isCapable(int subId, int capability, int regTech) {
3456 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003457 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3458 final long token = Binder.clearCallingIdentity();
3459 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003460 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003462 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003463 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3464 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003465 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003466 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3467 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003468 } finally {
3469 Binder.restoreCallingIdentity(token);
3470 }
3471 }
3472
3473 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003474 public boolean isAvailable(int subId, int capability, int regTech) {
3475 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003476 final long token = Binder.clearCallingIdentity();
3477 try {
3478 Phone phone = getPhone(subId);
3479 if (phone == null) return false;
3480 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003481 } catch (com.android.ims.ImsException e) {
3482 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3483 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003484 } finally {
3485 Binder.restoreCallingIdentity(token);
3486 }
3487 }
3488
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003489 /**
3490 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3491 * subscription.
3492 * @param subId The subscription to use to check the configuration.
3493 * @param callback The callback that will be used to send the result.
3494 * @param capability The MmTelFeature capability that will be used to send the result.
3495 * @param transportType The transport type of the MmTelFeature capability.
3496 */
3497 @Override
3498 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3499 int transportType) {
3500 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3501 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3502 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3503 "IMS not available on device.");
3504 }
3505 final long token = Binder.clearCallingIdentity();
3506 try {
3507 int slotId = getSlotIndex(subId);
3508 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3509 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3510 + subId + "'");
3511 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3512 }
3513 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3514 transportType, aBoolean -> {
3515 try {
3516 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3517 } catch (RemoteException e) {
3518 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3519 + "running. Ignore");
3520 }
3521 });
3522 } finally {
3523 Binder.restoreCallingIdentity(token);
3524 }
3525 }
3526
shilu366312e2019-12-17 09:28:10 -08003527 /**
3528 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3529 * @param subId The subscription to use to check the configuration.
3530 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 @Override
3532 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003533 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3534 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003535
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3537 final long token = Binder.clearCallingIdentity();
3538 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003539 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003540 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003541 } catch (ImsException e) {
3542 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003543 } finally {
3544 Binder.restoreCallingIdentity(token);
3545 }
3546 }
3547
3548 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003549 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003551 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003555 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003557 } catch (ImsException e) {
3558 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003559 } finally {
3560 Binder.restoreCallingIdentity(identity);
3561 }
3562 }
3563
shilu366312e2019-12-17 09:28:10 -08003564 /**
3565 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3566 * @param subId The subscription to use to check the configuration.
3567 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003569 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003570 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3571 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003575 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3576 } catch (ImsException e) {
3577 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
3581 }
3582
3583 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003584 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003586 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003591 } catch (ImsException e) {
3592 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 } finally {
3594 Binder.restoreCallingIdentity(identity);
3595 }
3596 }
3597
shilu366312e2019-12-17 09:28:10 -08003598 /**
3599 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3600 * @param subId The subscription to use to check the configuration.
3601 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 @Override
3603 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003604 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3605 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003609 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003611 } catch (ImsException e) {
3612 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
3616 }
3617
3618 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003619 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003621 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003625 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003626 } catch (ImsException e) {
3627 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003628 } finally {
3629 Binder.restoreCallingIdentity(identity);
3630 }
3631 }
3632
shilu366312e2019-12-17 09:28:10 -08003633 /**
3634 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3635 * @param subId The subscription to use to check the configuration.
3636 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 @Override
3638 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003639 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3640 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 final long identity = Binder.clearCallingIdentity();
3642 try {
3643 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003644 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003645 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003646 } catch (ImsException e) {
3647 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003648 } finally {
3649 Binder.restoreCallingIdentity(identity);
3650 }
3651 }
3652
3653 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003654 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003656 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 final long identity = Binder.clearCallingIdentity();
3658 try {
3659 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003660 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003661 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003662 } catch (ImsException e) {
3663 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
3667 }
3668
3669 @Override
3670 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3672 "setVoWiFiNonPersistent");
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003676 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003677 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003678 } catch (ImsException e) {
3679 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
shilu366312e2019-12-17 09:28:10 -08003685 /**
3686 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3687 * @param subId The subscription to use to check the configuration.
3688 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 @Override
3690 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003691 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3692 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 final long identity = Binder.clearCallingIdentity();
3694 try {
3695 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003696 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003698 } catch (ImsException e) {
3699 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 } finally {
3701 Binder.restoreCallingIdentity(identity);
3702 }
3703 }
3704
3705 @Override
3706 public void setVoWiFiModeSetting(int subId, int mode) {
3707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3708 "setVoWiFiModeSetting");
3709 final long identity = Binder.clearCallingIdentity();
3710 try {
3711 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003714 } catch (ImsException e) {
3715 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
3719 }
3720
3721 @Override
3722 public int getVoWiFiRoamingModeSetting(int subId) {
3723 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003727 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003728 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003729 } catch (ImsException e) {
3730 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
3734 }
3735
3736 @Override
3737 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3739 "setVoWiFiRoamingModeSetting");
3740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003743 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003745 } catch (ImsException e) {
3746 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
3750 }
3751
3752 @Override
3753 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3755 "setRttCapabilityEnabled");
3756 final long identity = Binder.clearCallingIdentity();
3757 try {
3758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003759 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3760 } catch (ImsException e) {
3761 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
3765 }
3766
shilu366312e2019-12-17 09:28:10 -08003767 /**
3768 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3769 * @param subId The subscription to use to check the configuration.
3770 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003771 @Override
3772 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003773 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3774 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003778 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003779 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003780 } catch (ImsException e) {
3781 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003782 } finally {
3783 Binder.restoreCallingIdentity(identity);
3784 }
3785 }
3786
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003787 @Override
3788 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3789 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3790 final long identity = Binder.clearCallingIdentity();
3791 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003792 if (!isImsAvailableOnDevice()) {
3793 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3794 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003795 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003797 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003798 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003799 } catch (ImsException e) {
3800 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003801 } finally {
3802 Binder.restoreCallingIdentity(identity);
3803 }
3804 }
3805
3806 @Override
3807 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3808 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3809 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003810 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3811 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3812 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003813 try {
3814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003815 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003816 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003817 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003818 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3819 + "is inactive, ignoring unregister.");
3820 // If the subscription is no longer active, just return, since the callback will already
3821 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003822 } finally {
3823 Binder.restoreCallingIdentity(identity);
3824 }
3825 }
3826
allenwtsu99c623b2020-01-03 18:24:23 +08003827
3828 private void checkModifyPhoneStatePermission(int subId, String message) {
3829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3830 message);
3831 }
3832
3833 private boolean isImsProvisioningRequired(int subId, int capability,
3834 boolean isMmtelCapability) {
3835 Phone phone = getPhone(subId);
3836 if (phone == null) {
3837 loge("phone instance null for subid " + subId);
3838 return false;
3839 }
3840 if (isMmtelCapability) {
3841 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3842 return false;
3843 }
3844 } else {
3845 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3846 return false;
3847 }
3848 }
3849 return true;
3850 }
3851
3852 @Override
3853 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3854 boolean isProvisioned) {
3855 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3856
3857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3860 if (!isImsProvisioningRequired(subId, capability, false)) {
3861 return;
3862 }
3863
3864 // this capability requires provisioning, route to the correct API.
3865 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3866 switch (capability) {
3867 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3868 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3869 ims.setEabProvisioned(isProvisioned);
3870 break;
3871 default: {
3872 throw new IllegalArgumentException("Tried to set provisioning for "
3873 + "rcs capability '" + capability + "', which does not require "
3874 + "provisioning.");
3875 }
3876 }
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
3879 }
3880
3881 }
3882
3883
3884 @Override
3885 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3886 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3890 if (!isImsProvisioningRequired(subId, capability, false)) {
3891 return true;
3892 }
3893
3894 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3895 switch (capability) {
3896 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3897 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3898 return ims.isEabProvisionedOnDevice();
3899
3900 default: {
3901 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3902 + "capability '" + capability + "', which does not require "
3903 + "provisioning.");
3904 }
3905 }
3906
3907 } finally {
3908 Binder.restoreCallingIdentity(identity);
3909 }
3910 }
3911
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003912 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003913 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3914 boolean isProvisioned) {
3915 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3916 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3917 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3918 }
allenwtsu99c623b2020-01-03 18:24:23 +08003919 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003923 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003924 return;
3925 }
3926
3927 // this capability requires provisioning, route to the correct API.
3928 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3929 switch (capability) {
3930 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3931 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3932 ims.setVolteProvisioned(isProvisioned);
3933 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3934 ims.setWfcProvisioned(isProvisioned);
3935 }
3936 break;
3937 }
3938 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3939 // There is currently no difference in VT provisioning type.
3940 ims.setVtProvisioned(isProvisioned);
3941 break;
3942 }
3943 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3944 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3945 // change the capability of the feature instead if needed.
3946 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3947 == isProvisioned) {
3948 // No change in provisioning.
3949 return;
3950 }
3951 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3952 try {
3953 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003954 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003955 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3956 + ", Exception" + e.getMessage());
3957 }
3958 break;
3959 }
3960 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003961 throw new IllegalArgumentException("Tried to set provisioning for "
3962 + "MmTel capability '" + capability + "', which does not require "
3963 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003964 }
3965 }
3966
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
3969 }
3970 }
3971
3972 @Override
3973 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3974 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3975 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3976 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3977 }
3978 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003982 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003983 return true;
3984 }
3985
3986 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3987 switch (capability) {
3988 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3989 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3990 return ims.isVolteProvisionedOnDevice();
3991 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3992 return ims.isWfcProvisionedOnDevice();
3993 }
3994 // This should never happen, since we are checking tech above to make sure it
3995 // is either LTE or IWLAN.
3996 throw new IllegalArgumentException("Invalid radio technology for voice "
3997 + "capability.");
3998 }
3999 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4000 // There is currently no difference in VT provisioning type.
4001 return ims.isVtProvisionedOnDevice();
4002 }
4003 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4004 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4005 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4006 }
4007 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004008 throw new IllegalArgumentException(
4009 "Tried to get provisioning for MmTel capability '" + capability
4010 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004011 }
4012 }
4013
4014 } finally {
4015 Binder.restoreCallingIdentity(identity);
4016 }
4017 }
4018
4019 @Override
4020 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4021 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4022 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4023 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4024 }
4025 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4026 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4027 return (provisionedBits & capability) > 0;
4028 }
4029
4030 @Override
4031 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4032 boolean isProvisioned) {
4033 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4034 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4035 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4036 }
4037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4038 "setProvisioningStatusForCapability");
4039 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4040 // If the current provisioning status for capability already matches isProvisioned,
4041 // do nothing.
4042 if (((provisionedBits & capability) > 0) == isProvisioned) {
4043 return;
4044 }
4045 if (isProvisioned) {
4046 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4047 } else {
4048 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4049 }
4050 }
4051
4052 /**
4053 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4054 * technology. The bitfield should mirror the bitfield defined by
4055 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4056 */
4057 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4058 String key = getMmTelProvisioningKey(subId, tech);
4059 // Default is no capabilities are provisioned.
4060 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4061 }
4062
4063 /**
4064 * Sets the MmTel capability provisioning bitfield (defined by
4065 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4066 * technology specified.
4067 *
4068 * Note: This is a synchronous command and should not be called on UI thread.
4069 */
4070 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4071 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4072 String key = getMmTelProvisioningKey(subId, tech);
4073 editor.putInt(key, newField);
4074 editor.commit();
4075 }
4076
4077 private static String getMmTelProvisioningKey(int subId, int tech) {
4078 // resulting key is provision_ims_mmtel_{subId}_{tech}
4079 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4080 }
4081
4082 /**
4083 * Query CarrierConfig to see if the specified capability requires provisioning for the
4084 * carrier associated with the subscription id.
4085 */
4086 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4087 int capability) {
4088 CarrierConfigManager configManager = new CarrierConfigManager(context);
4089 PersistableBundle c = configManager.getConfigForSubId(subId);
4090 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004091 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004092 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4093 false);
4094 boolean requireVoiceVtProvisioning = c.getBoolean(
4095 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4096
4097 // First check to make sure that the capability requires provisioning.
4098 switch (capability) {
4099 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4100 // intentional fallthrough
4101 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4102 if (requireVoiceVtProvisioning) {
4103 // Voice and Video requires provisioning
4104 return true;
4105 }
4106 break;
4107 }
4108 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4109 if (requireUtProvisioning) {
4110 // UT requires provisioning
4111 return true;
4112 }
4113 break;
4114 }
4115 }
4116 return false;
4117 }
4118
allenwtsu99c623b2020-01-03 18:24:23 +08004119 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4120 int capability) {
4121 CarrierConfigManager configManager = new CarrierConfigManager(context);
4122 PersistableBundle c = configManager.getConfigForSubId(subId);
4123
4124 boolean requireRcsProvisioning = c.getBoolean(
4125 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4126
4127 // First check to make sure that the capability requires provisioning.
4128 switch (capability) {
4129 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4130 // intentional fallthrough
4131 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4132 if (requireRcsProvisioning) {
4133 // OPTION or PRESENCE requires provisioning
4134 return true;
4135 }
4136 break;
4137 }
4138 }
4139 return false;
4140 }
4141
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004142 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004143 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004144 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4145 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4146 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004147 enforceReadPrivilegedPermission("getImsProvisioningInt");
4148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004151 int slotId = getSlotIndex(subId);
4152 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4153 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4154 + subId + "' for key:" + key);
4155 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4156 }
4157 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004158 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004159 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4160 + subId + "' for key:" + key);
4161 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
4165 }
4166
4167 @Override
4168 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004169 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4170 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4171 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004172 enforceReadPrivilegedPermission("getImsProvisioningString");
4173 final long identity = Binder.clearCallingIdentity();
4174 try {
4175 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004176 int slotId = getSlotIndex(subId);
4177 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4178 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4179 + subId + "' for key:" + key);
4180 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4181 }
4182 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004183 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004184 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4185 + subId + "' for key:" + key);
4186 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004187 } finally {
4188 Binder.restoreCallingIdentity(identity);
4189 }
4190 }
4191
4192 @Override
4193 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004194 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4195 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4196 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4198 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004199 final long identity = Binder.clearCallingIdentity();
4200 try {
4201 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004202 int slotId = getSlotIndex(subId);
4203 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4204 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4205 + subId + "' for key:" + key);
4206 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4207 }
4208 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004209 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004210 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4211 + "' for key:" + key);
4212 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004213 } finally {
4214 Binder.restoreCallingIdentity(identity);
4215 }
4216 }
4217
4218 @Override
4219 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004220 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4221 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4222 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4224 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004225 final long identity = Binder.clearCallingIdentity();
4226 try {
4227 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004228 int slotId = getSlotIndex(subId);
4229 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4230 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4231 + subId + "' for key:" + key);
4232 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4233 }
4234 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004235 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004236 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4237 + "' for key:" + key);
4238 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
4242 }
4243
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004244 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 int slotId = SubscriptionManager.getSlotIndex(subId);
4246 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004247 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4248 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004249 }
4250 return slotId;
4251 }
4252
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004253 private int getSlotIndex(int subId) {
4254 int slotId = SubscriptionManager.getSlotIndex(subId);
4255 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4256 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4257 }
4258 return slotId;
4259 }
4260
Wink Saville36469e72014-06-11 15:17:00 -07004261 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004262 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004263 */
4264 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004265 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4266 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004267 final int targetSdk = getTargetSdk(callingPackage);
4268 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004270 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004271 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 mApp, subId, callingPackage, callingFeatureId,
4273 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004274 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4275 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 final Phone phone = getPhone(subId);
4280 if (phone != null) {
4281 return phone.getServiceState().getDataNetworkType();
4282 } else {
4283 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4284 }
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004288 }
4289
4290 /**
4291 * Returns the data network type
4292 */
4293 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004294 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4295 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4296 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004297 }
4298
4299 /**
4300 * Returns the data network type for a subId
4301 */
4302 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004303 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4304 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004306 mApp, subId, callingPackage, callingFeatureId,
4307 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004308 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4309 }
4310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311 final long identity = Binder.clearCallingIdentity();
4312 try {
4313 final Phone phone = getPhone(subId);
4314 if (phone != null) {
4315 return phone.getServiceState().getDataNetworkType();
4316 } else {
4317 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4318 }
4319 } finally {
4320 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004322 }
4323
4324 /**
Wink Saville36469e72014-06-11 15:17:00 -07004325 * Returns the Voice network type for a subId
4326 */
4327 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004328 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4329 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004331 mApp, subId, callingPackage, callingFeatureId,
4332 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004333 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4334 }
4335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336 final long identity = Binder.clearCallingIdentity();
4337 try {
4338 final Phone phone = getPhone(subId);
4339 if (phone != null) {
4340 return phone.getServiceState().getVoiceNetworkType();
4341 } else {
4342 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4343 }
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004347 }
4348
4349 /**
4350 * @return true if a ICC card is present
4351 */
4352 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004353 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004354 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4355 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004356 }
4357
4358 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004359 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004360 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004361 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004362 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363 final long identity = Binder.clearCallingIdentity();
4364 try {
4365 final Phone phone = PhoneFactory.getPhone(slotIndex);
4366 if (phone != null) {
4367 return phone.getIccCard().hasIccCard();
4368 } else {
4369 return false;
4370 }
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004374 }
4375
4376 /**
4377 * Return if the current radio is LTE on CDMA. This
4378 * is a tri-state return value as for a period of time
4379 * the mode may be unknown.
4380 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004381 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004382 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004383 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004384 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004385 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004386 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4387 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4388 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004389 }
4390
Sanket Padawe356d7632015-06-22 14:03:32 -07004391 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004392 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4393 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004394 try {
4395 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4396 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004397 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4398 }
4399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400 final long identity = Binder.clearCallingIdentity();
4401 try {
4402 final Phone phone = getPhone(subId);
4403 if (phone == null) {
4404 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4405 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004406 return TelephonyProperties.lte_on_cdma_device()
4407 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408 }
4409 } finally {
4410 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004411 }
Wink Saville36469e72014-06-11 15:17:00 -07004412 }
4413
Wink Saville36469e72014-06-11 15:17:00 -07004414 /**
4415 * {@hide}
4416 * Returns Default subId, 0 in the case of single standby.
4417 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004418 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004419 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004420 }
4421
Shishir Agrawala9f32182016-04-12 12:00:16 -07004422 private int getSlotForDefaultSubscription() {
4423 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4424 }
4425
Wink Savilleb564aae2014-10-23 10:18:09 -07004426 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004427 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004428 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004429
Pengquan Menge92a50d2018-09-21 15:54:48 -07004430 private boolean isActiveSubscription(int subId) {
4431 return mSubscriptionController.isActiveSubId(subId);
4432 }
4433
Ihab Awadf2177b72013-11-25 13:33:23 -08004434 /**
4435 * @see android.telephony.TelephonyManager.WifiCallingChoices
4436 */
4437 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004438 final long identity = Binder.clearCallingIdentity();
4439 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004440 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4442 getWhenToMakeWifiCallsDefaultPreference());
4443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004446 }
4447
4448 /**
4449 * @see android.telephony.TelephonyManager.WifiCallingChoices
4450 */
4451 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 final long identity = Binder.clearCallingIdentity();
4453 try {
4454 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004455 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004460 }
4461
Sailesh Nepald1e68152013-12-12 19:08:02 -08004462 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004463 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004464 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004465 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004466
Jordan Liu4c733742019-02-28 12:03:40 -08004467 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4468 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4469 if (phoneId == -1) {
4470 throw new IllegalArgumentException("Given slot index: " + slotIndex
4471 + " does not correspond to an active phone");
4472 }
4473 return PhoneFactory.getPhone(phoneId);
4474 }
4475
Shishir Agrawal566b7612013-10-28 14:41:00 -07004476 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004477 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4478 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4480 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004482 if (DBG) {
4483 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4484 }
4485 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4486 p2);
4487 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004488
Jordan Liu4c733742019-02-28 12:03:40 -08004489
4490 @Override
4491 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4492 int slotIndex, String callingPackage, String aid, int p2) {
4493 enforceModifyPermission();
4494 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4495 if (DBG) {
4496 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4497 }
4498 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4499 callingPackage, aid, p2);
4500 }
4501
4502 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4503 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004504 final long identity = Binder.clearCallingIdentity();
4505 try {
4506 if (TextUtils.equals(ISDR_AID, aid)) {
4507 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004508 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4509 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510 if (bestComponent == null
4511 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4512 loge("The calling package is not allowed to access ISD-R.");
4513 throw new SecurityException(
4514 "The calling package is not allowed to access ISD-R.");
4515 }
Derek Tan740e1672017-06-27 14:56:27 -07004516 }
Derek Tan740e1672017-06-27 14:56:27 -07004517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004519 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4520 null /* workSource */);
4521 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522 return response;
4523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004526 }
4527
4528 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004529 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4531 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004532 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4533 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4534 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004535
Jordan Liu4c733742019-02-28 12:03:40 -08004536 @Override
4537 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4538 enforceModifyPermission();
4539 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4540 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4541 channel);
4542 }
4543
4544 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545 final long identity = Binder.clearCallingIdentity();
4546 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004547 if (channel < 0) {
4548 return false;
4549 }
Jordan Liu4c733742019-02-28 12:03:40 -08004550 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4551 null /* workSource */);
4552 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 return success;
4554 } finally {
4555 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004556 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004557 }
4558
4559 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004560 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004561 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4563 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004564 if (DBG) {
4565 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4566 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4567 + p3 + " data=" + data);
4568 }
4569 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4570 command, p1, p2, p3, data);
4571 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004572
Jordan Liu4c733742019-02-28 12:03:40 -08004573 @Override
4574 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4575 int command, int p1, int p2, int p3, String data) {
4576 enforceModifyPermission();
4577 if (DBG) {
4578 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4579 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4580 + p3 + " data=" + data);
4581 }
4582 return iccTransmitApduLogicalChannelWithPermission(
4583 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4584 data);
4585 }
4586
4587 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4588 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
4590 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004591 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 return "";
4593 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004596 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4597 null /* workSource */);
4598 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004600 // Append the returned status code to the end of the response payload.
4601 String s = Integer.toHexString(
4602 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4603 if (response.payload != null) {
4604 s = IccUtils.bytesToHexString(response.payload) + s;
4605 }
4606 return s;
4607 } finally {
4608 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004609 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004610 }
Jake Hambye994d462014-02-03 13:10:13 -08004611
Evan Charltonc66da362014-05-16 14:06:40 -07004612 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004613 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4614 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4616 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004617 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004618 if (DBG) {
4619 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4620 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4621 }
4622 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4623 cla, command, p1, p2, p3, data);
4624 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004625
Jordan Liu4c733742019-02-28 12:03:40 -08004626 @Override
4627 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4628 int command, int p1, int p2, int p3, String data) {
4629 enforceModifyPermission();
4630 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4631 if (DBG) {
4632 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4633 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4634 + " data=" + data);
4635 }
4636
4637 return iccTransmitApduBasicChannelWithPermission(
4638 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4639 p2, p3, data);
4640 }
4641
4642 // open APDU basic channel assuming the caller has sufficient permissions
4643 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4644 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4648 && TextUtils.equals(ISDR_AID, data)) {
4649 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004650 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4651 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 if (bestComponent == null
4653 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4654 loge("The calling package is not allowed to select ISD-R.");
4655 throw new SecurityException(
4656 "The calling package is not allowed to select ISD-R.");
4657 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004658 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004661 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4662 null /* workSource */);
4663 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 // Append the returned status code to the end of the response payload.
4666 String s = Integer.toHexString(
4667 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4668 if (response.payload != null) {
4669 s = IccUtils.bytesToHexString(response.payload) + s;
4670 }
4671 return s;
4672 } finally {
4673 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004674 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004675 }
4676
4677 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004678 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004679 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4681 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 final long identity = Binder.clearCallingIdentity();
4684 try {
4685 if (DBG) {
4686 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4687 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4688 }
4689
4690 IccIoResult response =
4691 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4692 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4693 subId);
4694
4695 if (DBG) {
4696 log("Exchange SIM_IO [R]" + response);
4697 }
4698
4699 byte[] result = null;
4700 int length = 2;
4701 if (response.payload != null) {
4702 length = 2 + response.payload.length;
4703 result = new byte[length];
4704 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4705 } else {
4706 result = new byte[length];
4707 }
4708
4709 result[length - 1] = (byte) response.sw2;
4710 result[length - 2] = (byte) response.sw1;
4711 return result;
4712 } finally {
4713 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004714 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004715 }
4716
Nathan Haroldb3014052017-01-25 15:57:32 -08004717 /**
4718 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4719 * on a particular subscription
4720 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004721 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4722 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004724 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004725 return null;
4726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727
4728 final long identity = Binder.clearCallingIdentity();
4729 try {
4730 if (appType != TelephonyManager.APPTYPE_USIM
4731 && appType != TelephonyManager.APPTYPE_SIM) {
4732 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4733 return null;
4734 }
4735 Object response = sendRequest(
4736 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4737 if (response instanceof String[]) {
4738 return (String[]) response;
4739 }
yincheng zhao2737e882019-09-06 17:06:54 -07004740 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004741 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004742 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 } finally {
4744 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004745 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004746 }
4747
yincheng zhao2737e882019-09-06 17:06:54 -07004748 /**
4749 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4750 * subscription.
4751 *
4752 * @param subId the id of the subscription.
4753 * @param appType the uicc app type, must be USIM or SIM.
4754 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4755 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004756 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004757 * @return number of fplmns that is successfully written to the SIM.
4758 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004759 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4760 String callingFeatureId) {
4761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4762 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004763 if (DBG) logv("no permissions for setForbiddenplmns");
4764 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4765 }
4766 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4767 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4768 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4769 }
4770 if (fplmns == null) {
4771 throw new IllegalArgumentException("Fplmn List provided is null");
4772 }
4773 for (String fplmn : fplmns) {
4774 if (!CellIdentity.isValidPlmn(fplmn)) {
4775 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4776 }
4777 }
4778 final long identity = Binder.clearCallingIdentity();
4779 try {
4780 Object response = sendRequest(
4781 CMD_SET_FORBIDDEN_PLMNS,
4782 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4783 subId);
4784 return (int) response;
4785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
4788 }
4789
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004790 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004791 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4793 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004795 final long identity = Binder.clearCallingIdentity();
4796 try {
4797 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4798 if (response.payload == null) {
4799 return "";
4800 }
Evan Charltonc66da362014-05-16 14:06:40 -07004801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802 // Append the returned status code to the end of the response payload.
4803 String s = Integer.toHexString(
4804 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4805 s = IccUtils.bytesToHexString(response.payload) + s;
4806 return s;
4807 } finally {
4808 Binder.restoreCallingIdentity(identity);
4809 }
Evan Charltonc66da362014-05-16 14:06:40 -07004810 }
4811
Jake Hambye994d462014-02-03 13:10:13 -08004812 /**
4813 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4814 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4815 *
4816 * @param itemID the ID of the item to read
4817 * @return the NV item as a String, or null on error.
4818 */
4819 @Override
4820 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004821 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4823 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824
4825 final long identity = Binder.clearCallingIdentity();
4826 try {
4827 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004828 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4830 return value;
4831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
Jake Hambye994d462014-02-03 13:10:13 -08004834 }
4835
4836 /**
4837 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4838 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4839 *
4840 * @param itemID the ID of the item to read
4841 * @param itemValue the value to write, as a String
4842 * @return true on success; false on any failure
4843 */
4844 @Override
4845 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004846 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4848 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849
4850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4853 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004854 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4856 return success;
4857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
Jake Hambye994d462014-02-03 13:10:13 -08004860 }
4861
4862 /**
4863 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4864 * Used for device configuration by some CDMA operators.
4865 *
4866 * @param preferredRoamingList byte array containing the new PRL
4867 * @return true on success; false on any failure
4868 */
4869 @Override
4870 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4872 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873
4874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4877 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4878 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4879 return success;
4880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
Jake Hambye994d462014-02-03 13:10:13 -08004883 }
4884
4885 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004886 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004887 * Used for device configuration by some CDMA operators.
4888 *
chen xu6dac5ab2018-10-26 17:39:23 -07004889 * @param slotIndex - device slot.
4890 *
Jake Hambye994d462014-02-03 13:10:13 -08004891 * @return true on success; false on any failure
4892 */
4893 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004894 public boolean resetModemConfig(int slotIndex) {
4895 Phone phone = PhoneFactory.getPhone(slotIndex);
4896 if (phone != null) {
4897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4898 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899
chen xu6dac5ab2018-10-26 17:39:23 -07004900 final long identity = Binder.clearCallingIdentity();
4901 try {
4902 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4903 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4904 return success;
4905 } finally {
4906 Binder.restoreCallingIdentity(identity);
4907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 }
chen xu6dac5ab2018-10-26 17:39:23 -07004909 return false;
4910 }
4911
4912 /**
4913 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4914 *
4915 * @param slotIndex - device slot.
4916 *
4917 * @return true on success; false on any failure
4918 */
4919 @Override
4920 public boolean rebootModem(int slotIndex) {
4921 Phone phone = PhoneFactory.getPhone(slotIndex);
4922 if (phone != null) {
4923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4924 mApp, phone.getSubId(), "rebootModem");
4925
4926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4929 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4930 return success;
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
4934 }
4935 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004936 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004937
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004938 public String[] getPcscfAddress(String apnType, String callingPackage,
4939 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004940 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4942 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004943 return new String[0];
4944 }
4945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 final long identity = Binder.clearCallingIdentity();
4947 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004948 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
Wink Saville36469e72014-06-11 15:17:00 -07004952 }
4953
Brad Ebinger51f743a2017-01-23 13:50:20 -08004954 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004955 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4956 * {@link #disableIms(int)}.
4957 * @param slotIndex device slot.
4958 */
4959 public void resetIms(int slotIndex) {
4960 enforceModifyPermission();
4961
4962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 if (mImsResolver == null) {
4965 // may happen if the does not support IMS.
4966 return;
4967 }
4968 mImsResolver.disableIms(slotIndex);
4969 mImsResolver.enableIms(slotIndex);
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
4973 }
4974
4975 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004976 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4977 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004978 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004979 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004980 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004981
4982 final long identity = Binder.clearCallingIdentity();
4983 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004984 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004985 // may happen if the device does not support IMS.
4986 return;
4987 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004988 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004992 }
4993
4994 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004995 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4996 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004997 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004998 public void disableIms(int slotId) {
4999 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000
5001 final long identity = Binder.clearCallingIdentity();
5002 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005003 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005004 // may happen if the device does not support IMS.
5005 return;
5006 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005007 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005011 }
5012
5013 /**
5014 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
5015 * feature or {@link null} if the service is not available. If the feature is available, the
5016 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
5017 */
5018 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08005019 IImsServiceFeatureCallback callback) {
5020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021
5022 final long identity = Binder.clearCallingIdentity();
5023 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005024 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005025 // may happen if the device does not support IMS.
5026 return null;
5027 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005028 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029 } finally {
5030 Binder.restoreCallingIdentity(identity);
5031 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005032 }
5033
5034 /**
5035 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5036 * feature during emergency calling or {@link null} if the service is not available. If the
5037 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5038 * listener for feature updates.
5039 */
5040 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042
5043 final long identity = Binder.clearCallingIdentity();
5044 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005045 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005046 // may happen if the device does not support IMS.
5047 return null;
5048 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005049 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 } finally {
5051 Binder.restoreCallingIdentity(identity);
5052 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005053 }
5054
Brad Ebinger5f64b052017-12-14 14:26:15 -08005055 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005056 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5057 */
5058 public void unregisterImsFeatureCallback(int slotId, int featureType,
5059 IImsServiceFeatureCallback callback) {
5060 enforceModifyPermission();
5061
5062 final long identity = Binder.clearCallingIdentity();
5063 try {
5064 if (mImsResolver == null) return;
5065 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
5069 }
5070
5071 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005072 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005073 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005074 */
5075 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5076 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077
5078 final long identity = Binder.clearCallingIdentity();
5079 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005080 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005081 // may happen if the device does not support IMS.
5082 return null;
5083 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005084 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005088 }
5089
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005090 /**
5091 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005092 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005093 */
5094 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5095 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096
5097 final long identity = Binder.clearCallingIdentity();
5098 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005099 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005100 // may happen if the device does not support IMS.
5101 return null;
5102 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005103 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005107 }
5108
Brad Ebinger884c07b2018-02-15 16:17:40 -08005109 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005110 * Sets the ImsService Package Name that Telephony will bind to.
5111 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005112 * @param slotIndex the slot ID that the ImsService should bind for.
5113 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005114 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005115 * @param featureTypes An integer array of feature types associated with a packageName.
5116 * @param packageName The name of the package that the current configuration will be replaced
5117 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005118 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005119 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005120 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5121 int[] featureTypes, String packageName) {
5122 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5123 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5125 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005126 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 final long identity = Binder.clearCallingIdentity();
5129 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005130 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005131 // may happen if the device does not support IMS.
5132 return false;
5133 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005134 Map<Integer, String> featureConfig = new HashMap<>();
5135 for (int featureType : featureTypes) {
5136 featureConfig.put(featureType, packageName);
5137 }
5138 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5139 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 } finally {
5141 Binder.restoreCallingIdentity(identity);
5142 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005143 }
5144
5145 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005146 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005147 *
5148 * @param slotId The slot that the ImsService is associated with.
5149 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5150 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005151 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005152 * @return the package name of the ImsService configuration.
5153 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005154 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5155 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005156 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005157 TelephonyPermissions
5158 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5159 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5160 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 final long identity = Binder.clearCallingIdentity();
5163 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005164 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005165 // may happen if the device does not support IMS.
5166 return "";
5167 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005168 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005169 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5170 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 } finally {
5172 Binder.restoreCallingIdentity(identity);
5173 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005174 }
5175
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005176 /**
5177 * Get the MmTelFeature state associated with the requested subscription id.
5178 * @param subId The subscription that the MmTelFeature is associated with.
5179 * @param callback A callback with an integer containing the
5180 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5181 */
5182 @Override
5183 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5184 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5185 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5186 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5187 "IMS not available on device.");
5188 }
5189 final long token = Binder.clearCallingIdentity();
5190 try {
5191 int slotId = getSlotIndex(subId);
5192 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5193 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5194 + subId + "'");
5195 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5196 }
5197 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5198 try {
5199 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5200 } catch (RemoteException e) {
5201 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5202 + "Ignore");
5203 }
5204 });
5205 } finally {
5206 Binder.restoreCallingIdentity(token);
5207 }
5208 }
5209
Wink Saville36469e72014-06-11 15:17:00 -07005210 public void setImsRegistrationState(boolean registered) {
5211 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212
5213 final long identity = Binder.clearCallingIdentity();
5214 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005215 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
Wink Saville36469e72014-06-11 15:17:00 -07005219 }
5220
5221 /**
Stuart Scott54788802015-03-30 13:18:01 -07005222 * Set the network selection mode to automatic.
5223 *
5224 */
5225 @Override
5226 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5228 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229
5230 final long identity = Binder.clearCallingIdentity();
5231 try {
shilufc958392020-01-20 11:36:01 -08005232 if (!isActiveSubscription(subId)) {
5233 return;
5234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5236 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
Stuart Scott54788802015-03-30 13:18:01 -07005240 }
5241
Pengquan Mengea84e042018-09-20 14:57:26 -07005242 /**
5243 * Ask the radio to connect to the input network and change selection mode to manual.
5244 *
5245 * @param subId the id of the subscription.
5246 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5247 * the operator to attach to.
5248 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5249 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5250 * normal network selection next time.
5251 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005252 */
5253 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005254 public boolean setNetworkSelectionModeManual(
5255 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5257 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005258
5259 if (!isActiveSubscription(subId)) {
5260 return false;
5261 }
5262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 final long identity = Binder.clearCallingIdentity();
5264 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005265 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005267 if (DBG) {
5268 log("setNetworkSelectionModeManual: subId: " + subId
5269 + " operator: " + operatorInfo);
5270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5272 } finally {
5273 Binder.restoreCallingIdentity(identity);
5274 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005275 }
shilu84f6e8b2019-12-19 13:58:01 -08005276 /**
5277 * Get the manual network selection
5278 *
5279 * @param subId the id of the subscription.
5280 *
5281 * @return the previously saved user selected PLMN
5282 */
5283 @Override
5284 public String getManualNetworkSelectionPlmn(int subId) {
5285 TelephonyPermissions
5286 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5287 mApp, subId, "getManualNetworkSelectionPlmn");
5288
5289 final long identity = Binder.clearCallingIdentity();
5290 try {
5291 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005292 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005293 }
5294
5295 final Phone phone = getPhone(subId);
5296 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005297 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005298 }
5299 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5300 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5301 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
5305 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005306
5307 /**
5308 * Scans for available networks.
5309 */
5310 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005311 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5312 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5314 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005315 LocationAccessPolicy.LocationPermissionResult locationResult =
5316 LocationAccessPolicy.checkLocationPermission(mApp,
5317 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5318 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005319 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005320 .setCallingPid(Binder.getCallingPid())
5321 .setCallingUid(Binder.getCallingUid())
5322 .setMethod("getCellNetworkScanResults")
5323 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005324 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5325 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005326 .build());
5327 switch (locationResult) {
5328 case DENIED_HARD:
5329 throw new SecurityException("Not allowed to access scan results -- location");
5330 case DENIED_SOFT:
5331 return null;
5332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333
Pengquan Menga1bb6272018-09-06 09:59:22 -07005334 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 try {
5336 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005337 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005342 }
5343
5344 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005345 * Get the call forwarding info, given the call forwarding reason.
5346 */
5347 @Override
5348 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5349 enforceReadPrivilegedPermission("getCallForwarding");
5350 long identity = Binder.clearCallingIdentity();
5351 try {
5352 if (DBG) {
5353 log("getCallForwarding: subId " + subId
5354 + " callForwardingReason" + callForwardingReason);
5355 }
5356 return (CallForwardingInfo) sendRequest(
5357 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
5361 }
5362
5363 /**
5364 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5365 * reason, the number to forward, and the timeout before the forwarding is attempted.
5366 */
5367 @Override
5368 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5369 enforceModifyPermission();
5370 long identity = Binder.clearCallingIdentity();
5371 try {
5372 if (DBG) {
5373 log("setCallForwarding: subId " + subId
5374 + " callForwardingInfo" + callForwardingInfo);
5375 }
5376 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
5380 }
5381
5382 /**
5383 * Get the call forwarding info, given the call forwarding reason.
5384 */
5385 @Override
5386 public int getCallWaitingStatus(int subId) {
5387 enforceReadPrivilegedPermission("getCallForwarding");
5388 long identity = Binder.clearCallingIdentity();
5389 try {
5390 if (DBG) log("getCallWaitingStatus: subId " + subId);
5391 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5392 } finally {
5393 Binder.restoreCallingIdentity(identity);
5394 }
5395 }
5396
5397 /**
5398 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5399 * reason, the number to forward, and the timeout before the forwarding is attempted.
5400 */
5401 @Override
5402 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5403 enforceModifyPermission();
5404 long identity = Binder.clearCallingIdentity();
5405 try {
5406 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5407 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
5410 }
5411 }
5412
5413 /**
yinxub1bed742017-04-17 11:45:04 -07005414 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005415 *
yinxub1bed742017-04-17 11:45:04 -07005416 * @param subId id of the subscription
5417 * @param request contains the radio access networks with bands/channels to scan
5418 * @param messenger callback messenger for scan results or errors
5419 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005420 * @return the id of the requested scan which can be used to stop the scan.
5421 */
5422 @Override
5423 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005424 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5426 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005427 LocationAccessPolicy.LocationPermissionResult locationResult =
5428 LocationAccessPolicy.checkLocationPermission(mApp,
5429 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5430 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005431 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005432 .setCallingPid(Binder.getCallingPid())
5433 .setCallingUid(Binder.getCallingUid())
5434 .setMethod("requestNetworkScan")
5435 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005436 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5437 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005438 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005439 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005440 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005441 if (e != null) {
5442 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5443 throw e;
5444 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005445 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005446 return TelephonyScanManager.INVALID_SCAN_ID;
5447 }
5448 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 }
Hall Liu912dfd32019-04-25 14:02:26 -07005450 int callingUid = Binder.getCallingUid();
5451 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005452 final long identity = Binder.clearCallingIdentity();
5453 try {
5454 return mNetworkScanRequestTracker.startNetworkScan(
5455 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005456 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
yinxu504e1392017-04-12 16:03:22 -07005460 }
5461
Hall Liub2ac8ef2019-02-28 15:56:23 -08005462 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005463 NetworkScanRequest request, int subId) {
5464 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5465 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5466 boolean hasNetworkScanPermission =
5467 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5468 == PERMISSION_GRANTED;
5469
5470 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5471 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5472 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005473 }
5474
5475 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5476 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005477 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5478 return new SecurityException("Specific channels must not be"
5479 + " scanned without location access.");
5480 }
5481 }
5482 }
5483
Hall Liub2ac8ef2019-02-28 15:56:23 -08005484 return null;
5485 }
5486
yinxu504e1392017-04-12 16:03:22 -07005487 /**
5488 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005489 *
5490 * @param subId id of the subscription
5491 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005492 */
5493 @Override
5494 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5496 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497
Hall Liu912dfd32019-04-25 14:02:26 -07005498 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 final long identity = Binder.clearCallingIdentity();
5500 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005501 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
yinxu504e1392017-04-12 16:03:22 -07005505 }
5506
5507 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005508 * Get the calculated preferred network type.
5509 * Used for debugging incorrect network type.
5510 *
5511 * @return the preferred network type, defined in RILConstants.java.
5512 */
5513 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005514 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005515 final Phone defaultPhone = getDefaultPhone();
5516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005517 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005518 return RILConstants.PREFERRED_NETWORK_MODE;
5519 }
5520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005524 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
Junda Liu84d15a22014-07-02 11:21:04 -07005528 }
5529
5530 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005531 * Get the preferred network type.
5532 * Used for device configuration by some CDMA operators.
5533 *
5534 * @return the preferred network type, defined in RILConstants.java.
5535 */
5536 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005537 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005538 TelephonyPermissions
5539 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5540 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541
5542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 if (DBG) log("getPreferredNetworkType");
5545 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5546 int networkType = (result != null ? result[0] : -1);
5547 if (DBG) log("getPreferredNetworkType: " + networkType);
5548 return networkType;
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005552 }
5553
5554 /**
5555 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005556 *
5557 * @param networkType the preferred network type, defined in RILConstants.java.
5558 * @return true on success; false on any failure.
5559 */
5560 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005561 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5563 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005567 Settings.Global.putInt(mApp.getContentResolver(),
5568 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan8ed33732020-03-12 14:17:55 +08005569
5570 Boolean success = (Boolean) sendRequest(
5571 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5572 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5573 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 } finally {
5575 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005576 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005577 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005578
5579 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005580 * Get the allowed network types that store in the telephony provider.
5581 *
5582 * @param subId the id of the subscription.
5583 * @return allowedNetworkTypes the allowed network types.
5584 */
5585 @Override
5586 public long getAllowedNetworkTypes(int subId) {
5587 TelephonyPermissions
5588 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5589 mApp, subId, "getAllowedNetworkTypes");
5590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 return SubscriptionManager.getLongSubscriptionProperty(
5594 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
5598 }
5599
5600 /**
5601 * Set the allowed network types.
5602 *
5603 * @param subId the id of the subscription.
5604 * @param allowedNetworkTypes the allowed network types.
5605 * @return true on success; false on any failure.
5606 */
5607 @Override
5608 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5610 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005611
calvinpan8ed33732020-03-12 14:17:55 +08005612 SubscriptionManager.setSubscriptionProperty(subId,
5613 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5614 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005615
calvinpan8ed33732020-03-12 14:17:55 +08005616 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5617 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5618 RILConstants.PREFERRED_NETWORK_MODE);
5619 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005620 }
5621
5622 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005623 * Get the allowed network types for certain reason.
5624 *
5625 * @param subId the id of the subscription.
5626 * @param reason the reason the allowed network type change is taking place
5627 * @return the allowed network types.
5628 */
5629 @Override
5630 public long getAllowedNetworkTypesForReason(int subId,
5631 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5632 TelephonyPermissions
5633 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5634 mApp, subId, "getAllowedNetworkTypesForReason");
5635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
5641 }
5642
5643 /**
5644 * Get the effective allowed network types on the device.
5645 * This API will return an intersection of allowed network types for all reasons,
5646 * including the configuration done through setAllowedNetworkTypes
5647 *
5648 * @param subId the id of the subscription.
5649 * @return the allowed network types
5650 */
5651 @Override
5652 public long getEffectiveAllowedNetworkTypes(int subId) {
5653 TelephonyPermissions
5654 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5655 mApp, subId, "getEffectiveAllowedNetworkTypes");
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
5658 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
5662 }
5663
5664 /**
5665 * Set the allowed network types of the device and
5666 * provide the reason triggering the allowed network change.
5667 *
5668 * @param subId the id of the subscription.
5669 * @param reason the reason the allowed network type change is taking place
5670 * @param allowedNetworkTypes the allowed network types.
5671 * @return true on success; false on any failure.
5672 */
5673 @Override
5674 public boolean setAllowedNetworkTypesForReason(int subId,
5675 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5677 mApp, subId, "setAllowedNetworkTypesForReason");
5678 final long identity = Binder.clearCallingIdentity();
5679 try {
5680 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5681 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5682 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5683 RILConstants.PREFERRED_NETWORK_MODE);
5684 return setPreferredNetworkType(subId, preferredNetworkMode);
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
5689
5690 /**
Miaoa84611c2019-03-15 09:21:10 +08005691 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005692 *
Miaoa84611c2019-03-15 09:21:10 +08005693 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005694 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005695 * @hide
5696 */
5697 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005698 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005701 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 try {
Miaoa84611c2019-03-15 09:21:10 +08005703 if (phone != null) {
5704 return phone.hasMatchedTetherApnSetting();
5705 } else {
5706 return false;
5707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 } finally {
5709 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005710 }
Junda Liu475951f2014-11-07 16:45:03 -08005711 }
5712
5713 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005714 * Enable or disable always reporting signal strength changes from radio.
5715 *
5716 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5717 */
5718 @Override
5719 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5720 enforceModifyPermission();
5721 enforceSystemCaller();
5722
5723 final long identity = Binder.clearCallingIdentity();
5724 final Phone phone = getPhone(subId);
5725 try {
5726 if (phone != null) {
5727 if (DBG) {
5728 log("setAlwaysReportSignalStrength: subId=" + subId
5729 + " isEnable=" + isEnable);
5730 }
5731 phone.setAlwaysReportSignalStrength(isEnable);
5732 } else {
5733 loge("setAlwaysReportSignalStrength: no phone found for subId="
5734 + subId);
5735 }
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
5739 }
5740
5741 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005742 * Get the user enabled state of Mobile Data.
5743 *
5744 * TODO: remove and use isUserDataEnabled.
5745 * This can't be removed now because some vendor codes
5746 * calls through ITelephony directly while they should
5747 * use TelephonyManager.
5748 *
5749 * @return true on enabled
5750 */
5751 @Override
5752 public boolean getDataEnabled(int subId) {
5753 return isUserDataEnabled(subId);
5754 }
5755
5756 /**
5757 * Get whether mobile data is enabled per user setting.
5758 *
5759 * There are other factors deciding whether mobile data is actually enabled, but they are
5760 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005761 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005762 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005763 *
5764 * @return {@code true} if data is enabled else {@code false}
5765 */
5766 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005767 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005768 try {
5769 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5770 null);
5771 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5773 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775
5776 final long identity = Binder.clearCallingIdentity();
5777 try {
5778 int phoneId = mSubscriptionController.getPhoneId(subId);
5779 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5780 Phone phone = PhoneFactory.getPhone(phoneId);
5781 if (phone != null) {
5782 boolean retVal = phone.isUserDataEnabled();
5783 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5784 return retVal;
5785 } else {
5786 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5787 return false;
5788 }
5789 } finally {
5790 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005791 }
5792 }
5793
5794 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005795 * Checks if the device is capable of mobile data by considering whether whether the
5796 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5797 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005798 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005799 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005800 */
5801 @Override
5802 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005803 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804
5805 final long identity = Binder.clearCallingIdentity();
5806 try {
5807 int phoneId = mSubscriptionController.getPhoneId(subId);
5808 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5809 Phone phone = PhoneFactory.getPhone(phoneId);
5810 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005811 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5813 return retVal;
5814 } else {
5815 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5816 return false;
5817 }
5818 } finally {
5819 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005820 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005821 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005822
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005823 /**
5824 * Check if data is enabled for a specific reason
5825 * @param subId Subscription index
5826 * @param reason the reason the data enable change is taking place
5827 * @return {@code true} if the overall data is enabled; {@code false} if not.
5828 */
5829 @Override
5830 public boolean isDataEnabledWithReason(int subId,
5831 @TelephonyManager.DataEnabledReason int reason) {
5832 try {
5833 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5834 null);
5835 } catch (Exception e) {
5836 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
5837 "isDataEnabledWithReason");
5838 }
5839
5840
5841 final long identity = Binder.clearCallingIdentity();
5842 try {
5843 int phoneId = mSubscriptionController.getPhoneId(subId);
5844 if (DBG) {
5845 log("isDataEnabledWithReason: subId=" + subId + " phoneId=" + phoneId
5846 + " reason=" + reason);
5847 }
5848 Phone phone = PhoneFactory.getPhone(phoneId);
5849 if (phone != null) {
5850 boolean retVal;
5851 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
5852 retVal = phone.isUserDataEnabled();
5853 } else {
5854 retVal = phone.getDataEnabledSettings().isDataEnabledWithReason(reason);
5855 }
5856 if (DBG) log("isDataEnabledWithReason: retVal=" + retVal);
5857 return retVal;
5858 } else {
5859 if (DBG) {
5860 loge("isDataEnabledWithReason: no phone subId="
5861 + subId + " retVal=false");
5862 }
5863 return false;
5864 }
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
5868 }
5869
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005870 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005871 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07005872 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5873 // Skip the check if it's one of these special uids
5874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5875 }
5876
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005877 //load access rules from carrier configs, and check those as well: b/139133814
5878 SubscriptionController subController = SubscriptionController.getInstance();
5879 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5880 || subController == null) return privilegeFromSim;
5881
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005882 PackageManager pkgMgr = phone.getContext().getPackageManager();
5883 String[] packages = pkgMgr.getPackagesForUid(uid);
5884
5885 final long identity = Binder.clearCallingIdentity();
5886 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005887 int subId = phone.getSubId();
5888 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5889 // A test override is in place for the privileges for this subId, so don't try to
5890 // read the subscription privileges.
5891 return privilegeFromSim;
5892 }
5893 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005894 SubscriptionManager subManager = (SubscriptionManager)
5895 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5896 for (String pkg : packages) {
5897 if (subManager.canManageSubscription(subInfo, pkg)) {
5898 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5899 }
5900 }
5901 return privilegeFromSim;
5902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
5905 }
5906
5907 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5908 String pkgName) {
5909 //load access rules from carrier configs, and check those as well: b/139133814
5910 SubscriptionController subController = SubscriptionController.getInstance();
5911 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5912 || subController == null) return privilegeFromSim;
5913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005916 int subId = phone.getSubId();
5917 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5918 // A test override is in place for the privileges for this subId, so don't try to
5919 // read the subscription privileges.
5920 return privilegeFromSim;
5921 }
5922 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005923 SubscriptionManager subManager = (SubscriptionManager)
5924 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5925 return subManager.canManageSubscription(subInfo, pkgName)
5926 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5927 } finally {
5928 Binder.restoreCallingIdentity(identity);
5929 }
5930 }
5931
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005932 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005933 public int getCarrierPrivilegeStatus(int subId) {
5934 final Phone phone = getPhone(subId);
5935 if (phone == null) {
5936 loge("getCarrierPrivilegeStatus: Invalid subId");
5937 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5938 }
5939 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005940 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005941 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005942 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5943 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005944
5945 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5946 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005947 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005948 }
Junda Liu29340342014-07-10 15:23:27 -07005949
5950 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005951 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005952 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005953 final Phone phone = getPhone(subId);
5954 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005955 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005956 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5957 }
5958 UiccProfile profile =
5959 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5960 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005961 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005962 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5963 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005964 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005965 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005966 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005967 }
5968
5969 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005970 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5971 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005972 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005973 }
5974
5975 int phoneId = SubscriptionManager.getPhoneId(subId);
5976 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005977 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005978 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005979 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5980 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005981 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5982 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5983 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005984 }
5985
5986 @Override
5987 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005988 if (TextUtils.isEmpty(pkgName))
5989 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005990 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5991 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5992 UiccCard card = UiccController.getInstance().getUiccCard(i);
5993 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005994 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005995 continue;
5996 }
5997
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005998 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5999 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6000 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006001 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6002 break;
6003 }
6004 }
6005
6006 return result;
Junda Liu29340342014-07-10 15:23:27 -07006007 }
Derek Tan89e89d42014-07-08 17:00:10 -07006008
6009 @Override
Junda Liue64de782015-04-16 17:19:16 -07006010 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6011 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6012 loge("phoneId " + phoneId + " is not valid.");
6013 return null;
6014 }
6015 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006016 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006017 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006018 return null ;
6019 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006020 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006021 }
6022
Amith Yamasani6e118872016-02-19 12:53:51 -08006023 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006024 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006025 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006026 List<String> privilegedPackages = new ArrayList<>();
6027 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006028 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6029 // has UICC in that slot.
6030 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006031 if (card.hasCarrierPrivilegeRules()) {
6032 if (packages == null) {
6033 // Only check packages in user 0 for now
6034 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006035 PackageManager.MATCH_DISABLED_COMPONENTS
6036 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006037 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006038 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006039 }
6040 for (int p = packages.size() - 1; p >= 0; p--) {
6041 PackageInfo pkgInfo = packages.get(p);
6042 if (pkgInfo != null && pkgInfo.packageName != null
6043 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006044 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006045 privilegedPackages.add(pkgInfo.packageName);
6046 }
6047 }
6048 }
6049 }
6050 return privilegedPackages;
6051 }
6052
chen xuf7e9fe82019-05-09 19:31:02 -07006053 @Override
6054 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006055 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6056
6057 final long identity = Binder.clearCallingIdentity();
6058
chen xuf7e9fe82019-05-09 19:31:02 -07006059 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006060 try {
6061 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6062 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6063 }
6064 } finally {
6065 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006066 }
6067 return privilegedPackages;
6068 }
6069
Wink Savilleb564aae2014-10-23 10:18:09 -07006070 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006071 final Phone phone = getPhone(subId);
6072 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006073 if (card == null) {
6074 loge("getIccId: No UICC");
6075 return null;
6076 }
6077 String iccId = card.getIccId();
6078 if (TextUtils.isEmpty(iccId)) {
6079 loge("getIccId: ICC ID is null or empty.");
6080 return null;
6081 }
6082 return iccId;
6083 }
6084
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006085 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006086 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6087 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006088 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006089 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 final long identity = Binder.clearCallingIdentity();
6092 try {
6093 final String iccId = getIccId(subId);
6094 final Phone phone = getPhone(subId);
6095 if (phone == null) {
6096 return false;
6097 }
6098 final String subscriberId = phone.getSubscriberId();
6099
6100 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006101 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 + subscriberId + " to " + number);
6103 }
6104
6105 if (TextUtils.isEmpty(iccId)) {
6106 return false;
6107 }
6108
6109 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6110
6111 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6112 if (alphaTag == null) {
6113 editor.remove(alphaTagPrefKey);
6114 } else {
6115 editor.putString(alphaTagPrefKey, alphaTag);
6116 }
6117
6118 // Record both the line number and IMSI for this ICCID, since we need to
6119 // track all merged IMSIs based on line number
6120 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6121 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6122 if (number == null) {
6123 editor.remove(numberPrefKey);
6124 editor.remove(subscriberPrefKey);
6125 } else {
6126 editor.putString(numberPrefKey, number);
6127 editor.putString(subscriberPrefKey, subscriberId);
6128 }
6129
6130 editor.commit();
6131 return true;
6132 } finally {
6133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006134 }
Derek Tan7226c842014-07-02 17:42:23 -07006135 }
6136
6137 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006138 public String getLine1NumberForDisplay(int subId, String callingPackage,
6139 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006140 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006142 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006143 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006144 return null;
6145 }
Derek Tan97ebb422014-09-05 16:55:38 -07006146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 final long identity = Binder.clearCallingIdentity();
6148 try {
6149 String iccId = getIccId(subId);
6150 if (iccId != null) {
6151 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6152 if (DBG_MERGE) {
6153 log("getLine1NumberForDisplay returning "
6154 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6155 }
6156 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6159 return null;
6160 } finally {
6161 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006162 }
Derek Tan7226c842014-07-02 17:42:23 -07006163 }
6164
6165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006166 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6167 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006169 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006170 return null;
6171 }
Derek Tan97ebb422014-09-05 16:55:38 -07006172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173 final long identity = Binder.clearCallingIdentity();
6174 try {
6175 String iccId = getIccId(subId);
6176 if (iccId != null) {
6177 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6178 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6179 }
6180 return null;
6181 } finally {
6182 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006183 }
Derek Tan7226c842014-07-02 17:42:23 -07006184 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006185
6186 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006187 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6188 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006189 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6190 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006192 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006193 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006194 return null;
6195 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006196
Jordan Liub49b04b2019-05-06 14:45:15 -07006197 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6198 // the process, where TelephonyManager was instantiated.
6199 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006200 final long identity = Binder.clearCallingIdentity();
6201 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006202 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 final TelephonyManager tele = TelephonyManager.from(context);
6204 final SubscriptionManager sub = SubscriptionManager.from(context);
6205
6206 // Figure out what subscribers are currently active
6207 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208
Jordan Liub49b04b2019-05-06 14:45:15 -07006209 // Only consider subs which match the current subId
6210 // This logic can be simplified. See b/131189269 for progress.
6211 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006212 activeSubscriberIds.add(tele.getSubscriberId(subId));
6213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214
6215 // First pass, find a number override for an active subscriber
6216 String mergeNumber = null;
6217 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6218 for (String key : prefs.keySet()) {
6219 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6220 final String subscriberId = (String) prefs.get(key);
6221 if (activeSubscriberIds.contains(subscriberId)) {
6222 final String iccId = key.substring(
6223 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6224 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6225 mergeNumber = (String) prefs.get(numberKey);
6226 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006227 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 + " for active subscriber " + subscriberId);
6229 }
6230 if (!TextUtils.isEmpty(mergeNumber)) {
6231 break;
6232 }
6233 }
6234 }
6235 }
6236
6237 // Shortcut when no active merged subscribers
6238 if (TextUtils.isEmpty(mergeNumber)) {
6239 return null;
6240 }
6241
6242 // Second pass, find all subscribers under that line override
6243 final ArraySet<String> result = new ArraySet<>();
6244 for (String key : prefs.keySet()) {
6245 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6246 final String number = (String) prefs.get(key);
6247 if (mergeNumber.equals(number)) {
6248 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6249 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6250 final String subscriberId = (String) prefs.get(subscriberKey);
6251 if (!TextUtils.isEmpty(subscriberId)) {
6252 result.add(subscriberId);
6253 }
6254 }
6255 }
6256 }
6257
6258 final String[] resultArray = result.toArray(new String[result.size()]);
6259 Arrays.sort(resultArray);
6260 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006261 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6263 }
6264 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006265 } finally {
6266 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006267 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006268 }
6269
6270 @Override
zoey chen38003472019-12-13 17:16:31 +08006271 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6272 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006273
6274 final long identity = Binder.clearCallingIdentity();
6275 try {
6276 final TelephonyManager telephonyManager = mApp.getSystemService(
6277 TelephonyManager.class);
6278 String subscriberId = telephonyManager.getSubscriberId(subId);
6279 if (subscriberId == null) {
6280 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006281 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006282 + subId);
6283 }
6284 return null;
6285 }
6286
6287 final SubscriptionInfo info = SubscriptionController.getInstance()
6288 .getSubscriptionInfo(subId);
6289 final ParcelUuid groupUuid = info.getGroupUuid();
6290 // If it doesn't belong to any group, return just subscriberId of itself.
6291 if (groupUuid == null) {
6292 return new String[]{subscriberId};
6293 }
6294
6295 // Get all subscriberIds from the group.
6296 final List<String> mergedSubscriberIds = new ArrayList<>();
6297 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006298 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006299 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006300 for (SubscriptionInfo subInfo : groupInfos) {
6301 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6302 if (subscriberId != null) {
6303 mergedSubscriberIds.add(subscriberId);
6304 }
6305 }
6306
6307 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6308 } finally {
6309 Binder.restoreCallingIdentity(identity);
6310
6311 }
6312 }
6313
6314 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006315 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006316 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006317 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318
6319 final long identity = Binder.clearCallingIdentity();
6320 try {
6321 final Phone phone = getPhone(subId);
6322 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006326 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006327
6328 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006329 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006330 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6331 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006332 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6333 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 final Phone phone = getPhone(subId);
6338 if (phone == null) {
6339 return false;
6340 }
6341 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6342 cdmaNonRoamingList);
6343 } finally {
6344 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006345 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006346 }
6347
6348 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006349 @Deprecated
6350 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6351 enforceModifyPermission();
6352
6353 int returnValue = 0;
6354 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006355 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006356 if(result.exception == null) {
6357 if (result.result != null) {
6358 byte[] responseData = (byte[])(result.result);
6359 if(responseData.length > oemResp.length) {
6360 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6361 responseData.length + "bytes. Buffer Size is " +
6362 oemResp.length + "bytes.");
6363 }
6364 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6365 returnValue = responseData.length;
6366 }
6367 } else {
6368 CommandException ex = (CommandException) result.exception;
6369 returnValue = ex.getCommandError().ordinal();
6370 if(returnValue > 0) returnValue *= -1;
6371 }
6372 } catch (RuntimeException e) {
6373 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6374 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6375 if(returnValue > 0) returnValue *= -1;
6376 }
6377
6378 return returnValue;
6379 }
6380
6381 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006382 public void setRadioCapability(RadioAccessFamily[] rafs) {
6383 try {
6384 ProxyController.getInstance().setRadioCapability(rafs);
6385 } catch (RuntimeException e) {
6386 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6387 }
6388 }
6389
6390 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006391 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006392 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006393 try {
6394 TelephonyPermissions
6395 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6396 mApp, phone.getSubId(), "getRadioAccessFamily");
6397 } catch (SecurityException e) {
6398 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6399 throw e;
6400 }
chen xub97461a2018-10-26 14:17:57 -07006401 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006402 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006403 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 final long identity = Binder.clearCallingIdentity();
6406 try {
chen xub97461a2018-10-26 14:17:57 -07006407 TelephonyPermissions
6408 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6409 mApp, phone.getSubId(), "getRadioAccessFamily");
6410 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
chen xub97461a2018-10-26 14:17:57 -07006414 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006415 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006416
6417 @Override
6418 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006419 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421
6422 final long identity = Binder.clearCallingIdentity();
6423 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006424 ImsManager.getInstance(defaultPhone.getContext(),
6425 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426 } finally {
6427 Binder.restoreCallingIdentity(identity);
6428 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006429 }
6430
6431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006432 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006433 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6435 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006436 return false;
6437 }
Svet Ganovb320e182015-04-16 12:30:10 -07006438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 // Check the user preference and the system-level IMS setting. Even if the user has
6442 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6443 // In the long run, we may instead need to check if there exists a connection service
6444 // which can support video calling.
6445 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006446 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 return imsManager.isVtEnabledByPlatform()
6448 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6449 && imsManager.isVtEnabledByUser();
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006453 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006454
Andrew Leea1239f22015-03-02 17:44:07 -08006455 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006456 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6457 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006459 mApp, subId, callingPackage, callingFeatureId,
6460 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461 return false;
6462 }
6463
6464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 CarrierConfigManager configManager =
6467 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006468 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
Andrew Leea1239f22015-03-02 17:44:07 -08006473 }
6474
6475 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006476 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006478 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479 return false;
6480 }
6481
6482 final long identity = Binder.clearCallingIdentity();
6483 try {
6484 CarrierConfigManager configManager =
6485 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006486 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
Andrew Leea1239f22015-03-02 17:44:07 -08006491 }
6492
Andrew Lee9431b832015-03-09 18:46:45 -07006493 @Override
6494 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006495 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006496 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006497 }
6498
6499 @Override
6500 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501 final long identity = Binder.clearCallingIdentity();
6502 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006503 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006504 } finally {
6505 Binder.restoreCallingIdentity(identity);
6506 }
Andrew Lee9431b832015-03-09 18:46:45 -07006507 }
6508
Hall Liuf6668912018-10-31 17:05:23 -07006509 /**
6510 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6511 * support for the feature and device firmware support.
6512 *
6513 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6514 */
6515 @Override
6516 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006517 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006518 final Phone phone = getPhone(subscriptionId);
6519 if (phone == null) {
6520 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6521 return false;
6522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006524 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006525 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6526 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006527 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 return isCarrierSupported && isDeviceSupported;
6529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
Hall Liu98187582018-01-22 19:15:32 -08006532 }
6533
Hall Liuf6668912018-10-31 17:05:23 -07006534 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006535 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6536 * RTT setting, will return true if the device and carrier both support RTT.
6537 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006538 */
6539 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 final long identity = Binder.clearCallingIdentity();
6541 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006542 boolean isRttSupported = isRttSupported(subscriptionId);
6543 boolean isUserRttSettingOn = Settings.Secure.getInt(
6544 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6545 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6546 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6547 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 } finally {
6549 Binder.restoreCallingIdentity(identity);
6550 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006551 }
6552
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006553 @Deprecated
6554 @Override
6555 public String getDeviceId(String callingPackage) {
6556 return getDeviceIdWithFeature(callingPackage, null);
6557 }
6558
Sanket Padawe7310cc72015-01-14 09:53:20 -08006559 /**
6560 * Returns the unique device ID of phone, for example, the IMEI for
6561 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6562 *
6563 * <p>Requires Permission:
6564 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6565 */
6566 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006567 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006568 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006569 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006570 return null;
6571 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006572 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006573 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006574 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006575 return null;
6576 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577
6578 final long identity = Binder.clearCallingIdentity();
6579 try {
6580 return phone.getDeviceId();
6581 } finally {
6582 Binder.restoreCallingIdentity(identity);
6583 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006584 }
6585
Ping Sunc67b7c22016-03-02 19:16:45 +08006586 /**
6587 * {@hide}
6588 * Returns the IMS Registration Status on a particular subid
6589 *
6590 * @param subId
6591 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006592 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006593 Phone phone = getPhone(subId);
6594 if (phone != null) {
6595 return phone.isImsRegistered();
6596 } else {
6597 return false;
6598 }
6599 }
6600
Santos Cordon7a1885b2015-02-03 11:15:19 -08006601 @Override
6602 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603 final long identity = Binder.clearCallingIdentity();
6604 try {
6605 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
6608 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006609 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006610
Tyler Gunnf70ed162019-04-03 15:28:53 -07006611 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006612 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006613 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006615 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006616 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6617 }
6618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6621 } finally {
6622 Binder.restoreCallingIdentity(identity);
6623 }
6624 }
6625
6626 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006627 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006628 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6629 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006630 final long identity = Binder.clearCallingIdentity();
6631 try {
6632 Phone phone = getPhone(subscriptionId);
6633 if (phone == null) {
6634 return null;
6635 }
6636 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6637 } finally {
6638 Binder.restoreCallingIdentity(identity);
6639 }
6640 }
6641
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006642 /**
6643 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006644 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006645 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 final long identity = Binder.clearCallingIdentity();
6647 try {
6648 Phone phone = getPhone(subId);
6649 if (phone != null) {
6650 return phone.isWifiCallingEnabled();
6651 } else {
6652 return false;
6653 }
6654 } finally {
6655 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006656 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006657 }
6658
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006659 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006660 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006661 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006662 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 final long identity = Binder.clearCallingIdentity();
6664 try {
6665 Phone phone = getPhone(subId);
6666 if (phone != null) {
6667 return phone.isVideoEnabled();
6668 } else {
6669 return false;
6670 }
6671 } finally {
6672 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006673 }
6674 }
6675
6676 /**
6677 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6678 * defined in {@link ImsRegistrationImplBase}.
6679 */
6680 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681 final long identity = Binder.clearCallingIdentity();
6682 try {
6683 Phone phone = getPhone(subId);
6684 if (phone != null) {
6685 return phone.getImsRegistrationTech();
6686 } else {
6687 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6688 }
6689 } finally {
6690 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006691 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006692 }
6693
Stuart Scott8eef64f2015-04-08 15:13:54 -07006694 @Override
6695 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006696 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006697 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6698 return;
6699 }
6700
Svet Ganovcc087f82015-05-12 20:35:54 -07006701 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006702
Svet Ganovcc087f82015-05-12 20:35:54 -07006703 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006704 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6705 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006706 setDataEnabledWithReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
6707 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006708 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006709 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006710 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6711 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006712 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006713 // There has been issues when Sms raw table somehow stores orphan
6714 // fragments. They lead to garbled message when new fragments come
6715 // in and combined with those stale ones. In case this happens again,
6716 // user can reset all network settings which will clean up this table.
6717 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006718 // Clean up IMS settings as well here.
6719 int slotId = getSlotIndex(subId);
6720 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6721 ImsManager.getInstance(mApp, slotId).factoryReset();
6722 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006723
6724 // Erase modem config if erase modem on network setting is enabled.
6725 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6726 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6727 if (configValue != null && Boolean.parseBoolean(configValue)) {
6728 sendEraseModemConfig(getDefaultPhone());
6729 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006730 } finally {
6731 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006732 }
6733 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006734
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006735 private void cleanUpSmsRawTable(Context context) {
6736 ContentResolver resolver = context.getContentResolver();
6737 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6738 resolver.delete(uri, null, null);
6739 }
6740
Narayan Kamath1c496c22015-04-16 14:40:19 +01006741 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006742 public String getSimLocaleForSubscriber(int subId) {
6743 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6744 final Phone phone = getPhone(subId);
6745 if (phone == null) {
6746 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006747 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749 final long identity = Binder.clearCallingIdentity();
6750 try {
chen xu5d3637b2019-01-21 23:31:38 -08006751 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006752 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006753 if (info == null) {
6754 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6755 return null;
6756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 // Try and fetch the locale from the carrier properties or from the SIM language
6758 // preferences (EF-PL and EF-LI)...
6759 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006761 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6762 if (localeFromDefaultSim != null) {
6763 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6764 if (DBG) log("Using locale from subId: " + subId + " locale: "
6765 + localeFromDefaultSim);
6766 return localeFromDefaultSim.toLanguageTag();
6767 } else {
6768 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 }
6770 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 // The SIM language preferences only store a language (e.g. fr = French), not an
6773 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6774 // the SIM and carrier preferences does not include a country we add the country
6775 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006776 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006778 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 return mccLocale.toLanguageTag();
6780 }
6781
6782 if (DBG) log("No locale found - returning null");
6783 return null;
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006787 }
6788
6789 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006790 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006791 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006792 }
6793
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794 /**
6795 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6796 */
6797 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006798 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006799 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006800 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006801
Chenjie Yu1ba97252018-01-11 18:16:20 -08006802 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006803 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006804
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006805 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006806 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6807 * representing the state of the modem.
6808 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006809 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6810 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006811 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006812 */
6813 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006814 public void requestModemActivityInfo(ResultReceiver result) {
6815 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006816 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817
6818 final long identity = Binder.clearCallingIdentity();
6819 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006820 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 } finally {
6822 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006823 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006824 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006825
Siddharth Rayb8114062018-06-17 15:02:38 -07006826 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6827 // less than total activity duration.
6828 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6829 if (info == null) {
6830 return false;
6831 }
6832 int activityDurationMs =
6833 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6834 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006835 int[] txTimeMs = info.getTransmitTimeMillis();
6836 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6837 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006838 }
6839 return (info.isValid()
6840 && (info.getSleepTimeMillis() <= activityDurationMs)
6841 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006842 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006843 && (totalTxTimeMs <= activityDurationMs));
6844 }
6845
Jack Yu85bd38a2015-11-09 11:34:32 -08006846 /**
6847 * {@hide}
6848 * Returns the service state information on specified subscription.
6849 */
6850 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006851 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6852 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006853 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006854 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006855 return null;
6856 }
6857
Hall Liuf19c44f2018-11-27 14:38:17 -08006858 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6859 LocationAccessPolicy.checkLocationPermission(mApp,
6860 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6861 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006862 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006863 .setCallingPid(Binder.getCallingPid())
6864 .setCallingUid(Binder.getCallingUid())
6865 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006866 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006867 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006868 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6869 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006870 .build());
6871
6872 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6873 LocationAccessPolicy.checkLocationPermission(mApp,
6874 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6875 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006876 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006877 .setCallingPid(Binder.getCallingPid())
6878 .setCallingUid(Binder.getCallingUid())
6879 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006880 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006881 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006882 .setMinSdkVersionForFine(Integer.MAX_VALUE)
6883 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006884 .build());
6885 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6886 boolean hasFinePermission =
6887 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6888 boolean hasCoarsePermission =
6889 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 final long identity = Binder.clearCallingIdentity();
6892 try {
6893 final Phone phone = getPhone(subId);
6894 if (phone == null) {
6895 return null;
6896 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006897
Hall Liuf19c44f2018-11-27 14:38:17 -08006898 ServiceState ss = phone.getServiceState();
6899
6900 // Scrub out the location info in ServiceState depending on what level of access
6901 // the caller has.
6902 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006903 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6904 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905 } finally {
6906 Binder.restoreCallingIdentity(identity);
6907 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006908 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006909
6910 /**
6911 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6912 *
6913 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6914 * voicemail ringtone.
6915 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6916 * PhoneAccount.
6917 */
6918 @Override
6919 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920 final long identity = Binder.clearCallingIdentity();
6921 try {
6922 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6923 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006924 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6928 } finally {
6929 Binder.restoreCallingIdentity(identity);
6930 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006931 }
6932
6933 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006934 * Sets the per-account voicemail ringtone.
6935 *
6936 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6937 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6938 *
6939 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6940 * voicemail ringtone.
6941 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6942 * PhoneAccount.
6943 */
6944 @Override
6945 public void setVoicemailRingtoneUri(String callingPackage,
6946 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006947 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006948 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006949 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6950 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6952 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6953 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955
6956 final long identity = Binder.clearCallingIdentity();
6957 try {
6958 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6959 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006960 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961 }
6962 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6963 } finally {
6964 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006965 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006966 }
6967
6968 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006969 * Returns whether vibration is set for voicemail notification in Phone settings.
6970 *
6971 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6972 * voicemail vibration setting.
6973 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6974 */
6975 @Override
6976 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6980 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006981 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6985 } finally {
6986 Binder.restoreCallingIdentity(identity);
6987 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006988 }
6989
Youhan Wange64578a2016-05-02 15:32:42 -07006990 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006991 * Sets the per-account voicemail vibration.
6992 *
6993 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6994 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6995 *
6996 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6997 * voicemail vibration setting.
6998 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6999 * specific PhoneAccount.
7000 */
7001 @Override
7002 public void setVoicemailVibrationEnabled(String callingPackage,
7003 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007004 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007005 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007006 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7007 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7009 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7010 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007011 }
7012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 final long identity = Binder.clearCallingIdentity();
7014 try {
7015 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7016 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007017 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 }
7019 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7020 } finally {
7021 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007022 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007023 }
7024
7025 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007026 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7027 *
7028 * @throws SecurityException if the caller does not have the required permission
7029 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007030 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007031 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007032 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007033 }
7034
7035 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007036 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7037 * permission.
7038 *
7039 * @throws SecurityException if the caller does not have the required permission
7040 */
7041 private void enforceSendSmsPermission() {
7042 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7043 }
7044
7045 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007046 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007047 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007048 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007049 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007050 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 final long identity = Binder.clearCallingIdentity();
7052 try {
7053 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007054 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 if (componentName == null) {
7056 throw new SecurityException(
7057 "Caller not current active visual voicemail package[null]");
7058 }
7059 String vvmPackage = componentName.getPackageName();
7060 if (!callingPackage.equals(vvmPackage)) {
7061 throw new SecurityException("Caller not current active visual voicemail package["
7062 + vvmPackage + "]");
7063 }
7064 } finally {
7065 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007066 }
7067 }
7068
7069 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007070 * Return the application ID for the app type.
7071 *
7072 * @param subId the subscription ID that this request applies to.
7073 * @param appType the uicc app type.
7074 * @return Application ID for specificied app type, or null if no uicc.
7075 */
7076 @Override
7077 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007078 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007079 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080
7081 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007082 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 if (phone == null) {
7084 return null;
7085 }
7086 String aid = null;
7087 try {
7088 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7089 .getApplicationByType(appType).getAid();
7090 } catch (Exception e) {
7091 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7092 }
7093 return aid;
7094 } finally {
7095 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007096 }
Youhan Wange64578a2016-05-02 15:32:42 -07007097 }
7098
Youhan Wang4001d252016-05-11 10:29:41 -07007099 /**
7100 * Return the Electronic Serial Number.
7101 *
7102 * @param subId the subscription ID that this request applies to.
7103 * @return ESN or null if error.
7104 */
7105 @Override
7106 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007107 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007108 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007109
7110 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007111 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112 if (phone == null) {
7113 return null;
7114 }
7115 String esn = null;
7116 try {
7117 esn = phone.getEsn();
7118 } catch (Exception e) {
7119 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7120 }
7121 return esn;
7122 } finally {
7123 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007124 }
Youhan Wang4001d252016-05-11 10:29:41 -07007125 }
7126
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007127 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007128 * Return the Preferred Roaming List Version.
7129 *
7130 * @param subId the subscription ID that this request applies to.
7131 * @return PRLVersion or null if error.
7132 */
7133 @Override
7134 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007135 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007136 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137
7138 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007139 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 if (phone == null) {
7141 return null;
7142 }
7143 String cdmaPrlVersion = null;
7144 try {
7145 cdmaPrlVersion = phone.getCdmaPrlVersion();
7146 } catch (Exception e) {
7147 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7148 }
7149 return cdmaPrlVersion;
7150 } finally {
7151 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007152 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007153 }
7154
7155 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007156 * Get snapshot of Telephony histograms
7157 * @return List of Telephony histograms
7158 * @hide
7159 */
7160 @Override
7161 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7163 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164
7165 final long identity = Binder.clearCallingIdentity();
7166 try {
7167 return RIL.getTelephonyRILTimingHistograms();
7168 } finally {
7169 Binder.restoreCallingIdentity(identity);
7170 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007171 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007172
7173 /**
7174 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007175 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7176 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007177 * Require system privileges. In the future we may add this to carrier APIs.
7178 *
Michele Berionne482f8202018-11-27 18:57:59 -08007179 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007180 */
7181 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007182 @TelephonyManager.SetCarrierRestrictionResult
7183 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007184 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007185 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007186
Michele Berionne482f8202018-11-27 18:57:59 -08007187 if (carrierRestrictionRules == null) {
7188 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007189 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007190
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 final long identity = Binder.clearCallingIdentity();
7192 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007193 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007194 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195 } finally {
7196 Binder.restoreCallingIdentity(identity);
7197 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007198 }
7199
7200 /**
7201 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007202 * Get the allowed carrier list and the excluded carrier list, including the priority between
7203 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007204 * Require system privileges. In the future we may add this to carrier APIs.
7205 *
Michele Berionne482f8202018-11-27 18:57:59 -08007206 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007207 */
7208 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007209 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007210 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007211 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212
7213 final long identity = Binder.clearCallingIdentity();
7214 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007215 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7216 if (response instanceof CarrierRestrictionRules) {
7217 return (CarrierRestrictionRules) response;
7218 }
7219 // Response is an Exception of some kind,
7220 // which is signalled to the user as a NULL retval
7221 return null;
7222 } catch (Exception e) {
7223 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7224 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225 } finally {
7226 Binder.restoreCallingIdentity(identity);
7227 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007228 }
7229
fionaxu59545b42016-05-25 15:53:37 -07007230 /**
fionaxu59545b42016-05-25 15:53:37 -07007231 * Action set from carrier signalling broadcast receivers to enable/disable radio
7232 * @param subId the subscription ID that this action applies to.
7233 * @param enabled control enable or disable radio.
7234 * {@hide}
7235 */
7236 @Override
7237 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7238 enforceModifyPermission();
7239 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240
7241 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007242 if (phone == null) {
7243 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7244 return;
7245 }
7246 try {
7247 phone.carrierActionSetRadioEnabled(enabled);
7248 } catch (Exception e) {
7249 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 } finally {
7251 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007252 }
7253 }
7254
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007255 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007256 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7257 * network status based on which carrier apps could apply actions accordingly,
7258 * enable/disable default url handler for example.
7259 *
7260 * @param subId the subscription ID that this action applies to.
7261 * @param report control start/stop reporting the default network status.
7262 * {@hide}
7263 */
7264 @Override
7265 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7266 enforceModifyPermission();
7267 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007268
7269 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007270 if (phone == null) {
7271 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7272 return;
7273 }
7274 try {
7275 phone.carrierActionReportDefaultNetworkStatus(report);
7276 } catch (Exception e) {
7277 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 } finally {
7279 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007280 }
7281 }
7282
7283 /**
fionaxud9622282017-07-17 17:51:30 -07007284 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7285 * @param subId the subscription ID that this action applies to.
7286 * {@hide}
7287 */
7288 @Override
7289 public void carrierActionResetAll(int subId) {
7290 enforceModifyPermission();
7291 final Phone phone = getPhone(subId);
7292 if (phone == null) {
7293 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7294 return;
7295 }
7296 try {
7297 phone.carrierActionResetAll();
7298 } catch (Exception e) {
7299 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7300 }
7301 }
7302
7303 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007304 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7305 * bug report is being generated.
7306 */
7307 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007308 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007309 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7310 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007311 writer.println("Permission Denial: can't dump Phone from pid="
7312 + Binder.getCallingPid()
7313 + ", uid=" + Binder.getCallingUid()
7314 + "without permission "
7315 + android.Manifest.permission.DUMP);
7316 return;
7317 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007318 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007319 }
Jack Yueb89b242016-06-22 13:27:47 -07007320
Brad Ebingerdac2f002018-04-03 15:17:52 -07007321 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007322 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7323 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7324 @NonNull String[] args) {
7325 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7326 this, in.getFileDescriptor(), out.getFileDescriptor(),
7327 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007328 }
7329
Jack Yueb89b242016-06-22 13:27:47 -07007330 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007331 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007332 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007333 * @param reason the reason the data enable change is taking place
7334 * @param enabled True if enabling the data, otherwise disabling.
7335 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007336 */
7337 @Override
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007338 public void setDataEnabledWithReason(int subId, @TelephonyManager.DataEnabledReason int reason,
7339 boolean enabled) {
7340 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7341 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7342 try {
7343 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7344 mApp, subId, "setDataEnabledWithReason");
7345 } catch (SecurityException se) {
7346 enforceModifyPermission();
7347 }
7348 } else {
7349 enforceModifyPermission();
7350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351
7352 final long identity = Binder.clearCallingIdentity();
7353 try {
7354 Phone phone = getPhone(subId);
7355 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007356 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7357 phone.carrierActionSetMeteredApnsEnabled(enabled);
7358 } else {
7359 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7360 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361 }
7362 } finally {
7363 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007364 }
7365 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007366
7367 /**
7368 * Get Client request stats
7369 * @return List of Client Request Stats
7370 * @hide
7371 */
7372 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007373 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7374 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007376 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007377 return null;
7378 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007379 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 final long identity = Binder.clearCallingIdentity();
7382 try {
7383 if (phone != null) {
7384 return phone.getClientRequestStats();
7385 }
7386
7387 return null;
7388 } finally {
7389 Binder.restoreCallingIdentity(identity);
7390 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007391 }
7392
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007393 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007394 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007395 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007396 }
Jack Yueb4124c2017-02-16 15:32:43 -08007397
7398 /**
Grace Chen70990072017-03-24 17:21:30 -07007399 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007400 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007401 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007402 * @param state State of SIM (power down, power up, pass through)
7403 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7404 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7405 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007406 *
7407 **/
7408 @Override
Grace Chen70990072017-03-24 17:21:30 -07007409 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007410 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007411 Phone phone = PhoneFactory.getPhone(slotIndex);
7412
vagdeviaf9a5b92018-08-15 16:01:53 -07007413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 final long identity = Binder.clearCallingIdentity();
7416 try {
7417 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007418 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 }
7420 } finally {
7421 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007422 }
7423 }
Shuo Qiandd210312017-04-12 22:11:33 +00007424
Tyler Gunn65d45c22017-06-05 11:22:26 -07007425 private boolean isUssdApiAllowed(int subId) {
7426 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007428 if (configManager == null) {
7429 return false;
7430 }
7431 PersistableBundle pb = configManager.getConfigForSubId(subId);
7432 if (pb == null) {
7433 return false;
7434 }
7435 return pb.getBoolean(
7436 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7437 }
7438
Shuo Qiandd210312017-04-12 22:11:33 +00007439 /**
7440 * Check if phone is in emergency callback mode
7441 * @return true if phone is in emergency callback mode
7442 * @param subId sub id
7443 */
goneil9c5f4872017-12-05 14:07:56 -08007444 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007445 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007446 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007447 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448
7449 final long identity = Binder.clearCallingIdentity();
7450 try {
7451 if (phone != null) {
7452 return phone.isInEcm();
7453 } else {
7454 return false;
7455 }
7456 } finally {
7457 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007458 }
7459 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007460
7461 /**
7462 * Get the current signal strength information for the given subscription.
7463 * Because this information is not updated when the device is in a low power state
7464 * it should not be relied-upon to be current.
7465 * @param subId Subscription index
7466 * @return the most recent cached signal strength info from the modem
7467 */
7468 @Override
7469 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 final long identity = Binder.clearCallingIdentity();
7471 try {
7472 Phone p = getPhone(subId);
7473 if (p == null) {
7474 return null;
7475 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 return p.getSignalStrength();
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
7480 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007481 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007482
Pengquan Meng77b7f132018-08-22 14:49:57 -07007483 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007484 * Get the current modem radio state for the given slot.
7485 * @param slotIndex slot index.
7486 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007487 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007488 * @return the current radio power state from the modem
7489 */
7490 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007491 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007492 Phone phone = PhoneFactory.getPhone(slotIndex);
7493 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7495 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007496 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7497 }
7498
7499 final long identity = Binder.clearCallingIdentity();
7500 try {
7501 return phone.getRadioPowerState();
7502 } finally {
7503 Binder.restoreCallingIdentity(identity);
7504 }
7505 }
7506 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7507 }
7508
7509 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007510 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7511 *
7512 * <p>Requires one of the following permissions:
7513 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7514 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7515 * privileges.
7516 *
7517 * @param subId subscription id
7518 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7519 * {@code false}.
7520 */
7521 @Override
7522 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007523 try {
7524 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7525 null);
7526 } catch (Exception e) {
7527 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7528 mApp, subId, "isDataRoamingEnabled");
7529 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007530
Pengquan Menga1bb6272018-09-06 09:59:22 -07007531 boolean isEnabled = false;
7532 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007533 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007534 Phone phone = getPhone(subId);
7535 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007536 } finally {
7537 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007538 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007539 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007540 }
7541
7542
7543 /**
7544 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7545 *
7546 * <p> Requires permission:
7547 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7548 * privileges.
7549 *
7550 * @param subId subscription id
7551 * @param isEnabled {@code true} means enable, {@code false} means disable.
7552 */
7553 @Override
7554 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7556 mApp, subId, "setDataRoamingEnabled");
7557
Pengquan Menga1bb6272018-09-06 09:59:22 -07007558 final long identity = Binder.clearCallingIdentity();
7559 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007560 Phone phone = getPhone(subId);
7561 if (phone != null) {
7562 phone.setDataRoamingEnabled(isEnabled);
7563 }
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007566 }
7567 }
7568
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007569 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007570 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007571 TelephonyPermissions
7572 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007573 mApp, subId, "isManualNetworkSelectionAllowed");
7574
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007575 boolean isAllowed = true;
7576 final long identity = Binder.clearCallingIdentity();
7577 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007578 Phone phone = getPhone(subId);
7579 if (phone != null) {
7580 isAllowed = phone.isCspPlmnEnabled();
7581 }
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
7585 return isAllowed;
7586 }
7587
7588 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007589 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007590 // Verify that tha callingPackage belongs to the calling UID
7591 mApp.getSystemService(AppOpsManager.class)
7592 .checkPackage(Binder.getCallingUid(), callingPackage);
7593
Jordan Liu1e142fc2019-04-22 15:10:43 -07007594 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007595 try {
7596 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007597 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007598 } catch (SecurityException e) {
7599 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7600 // has carrier privileges on an active UICC
7601 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7602 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007603 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007604 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007605 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007606
7607 final long identity = Binder.clearCallingIdentity();
7608 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007609 UiccController uiccController = UiccController.getInstance();
7610 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007611 if (hasReadPermission) {
7612 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007613 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007614
7615 // Remove private info if the caller doesn't have access
7616 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7617 for (UiccCardInfo cardInfo : cardInfos) {
7618 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7619 // is available
7620 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7621 if (card == null || card.getUiccProfile() == null) {
7622 // assume no access if the card or profile is unavailable
7623 filteredInfos.add(cardInfo.getUnprivileged());
7624 continue;
7625 }
7626 UiccProfile profile = card.getUiccProfile();
7627 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7628 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7629 filteredInfos.add(cardInfo);
7630 } else {
7631 filteredInfos.add(cardInfo.getUnprivileged());
7632 }
7633 }
7634 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
7638 }
7639
7640 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007641 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007642 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7647 if (slots == null) {
7648 Rlog.i(LOG_TAG, "slots is null.");
7649 return null;
7650 }
7651
7652 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7653 for (int i = 0; i < slots.length; i++) {
7654 UiccSlot slot = slots[i];
7655 if (slot == null) {
7656 continue;
7657 }
7658
Jordan Liu7be7e652019-05-06 18:55:02 +00007659 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660 UiccCard card = slot.getUiccCard();
7661 if (card != null) {
7662 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007663 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007664 cardId = slot.getEid();
7665 if (TextUtils.isEmpty(cardId)) {
7666 cardId = slot.getIccId();
7667 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668 }
7669
Jordan Liu857451f2019-05-09 16:35:35 -07007670 if (cardId != null) {
7671 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7672 // if cardId is an EID, it's all digits so this is fine
7673 cardId = IccUtils.stripTrailingFs(cardId);
7674 }
7675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676 int cardState = 0;
7677 switch (slot.getCardState()) {
7678 case CARDSTATE_ABSENT:
7679 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7680 break;
7681 case CARDSTATE_PRESENT:
7682 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7683 break;
7684 case CARDSTATE_ERROR:
7685 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7686 break;
7687 case CARDSTATE_RESTRICTED:
7688 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7689 break;
7690 default:
7691 break;
7692
7693 }
7694
7695 infos[i] = new UiccSlotInfo(
7696 slot.isActive(),
7697 slot.isEuicc(),
7698 cardId,
7699 cardState,
7700 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007701 slot.isExtendedApduSupported(),
7702 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703 }
7704 return infos;
7705 } finally {
7706 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007707 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007708 }
7709
7710 @Override
7711 public boolean switchSlots(int[] physicalSlots) {
7712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713
7714 final long identity = Binder.clearCallingIdentity();
7715 try {
7716 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7717 } finally {
7718 Binder.restoreCallingIdentity(identity);
7719 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007720 }
Jack Yu4c988042018-02-27 15:30:01 -08007721
7722 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007723 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 return UiccController.getInstance().getCardIdForDefaultEuicc();
7727 } finally {
7728 Binder.restoreCallingIdentity(identity);
7729 }
7730 }
7731
Pengquan Meng85728fb2018-03-12 16:31:21 -07007732 /**
goneil47ffb6e2018-04-06 15:40:58 -07007733 * A test API to reload the UICC profile.
7734 *
7735 * <p>Requires that the calling app has permission
7736 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7737 * @hide
7738 */
7739 @Override
7740 public void refreshUiccProfile(int subId) {
7741 enforceModifyPermission();
7742
7743 final long identity = Binder.clearCallingIdentity();
7744 try {
7745 Phone phone = getPhone(subId);
7746 if (phone == null) {
7747 return;
7748 }
7749 UiccCard uiccCard = phone.getUiccCard();
7750 if (uiccCard == null) {
7751 return;
7752 }
7753 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7754 if (uiccProfile == null) {
7755 return;
7756 }
7757 uiccProfile.refresh();
7758 } finally {
7759 Binder.restoreCallingIdentity(identity);
7760 }
7761 }
7762
7763 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007764 * Returns false if the mobile data is disabled by default, otherwise return true.
7765 */
7766 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007767 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007768 }
7769
7770 /**
7771 * Returns true if the data roaming is enabled by default, i.e the system property
7772 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7773 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7774 */
7775 private boolean getDefaultDataRoamingEnabled(int subId) {
7776 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007777 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07007778 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007779 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7780 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7781 return isDataRoamingEnabled;
7782 }
7783
7784 /**
7785 * Returns the default network type for the given {@code subId}, if the default network type is
7786 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7787 */
7788 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007789 List<Integer> list = TelephonyProperties.default_network();
7790 int phoneId = mSubscriptionController.getPhoneId(subId);
7791 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7792 return list.get(phoneId);
7793 }
7794 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007795 }
fionaxua13278b2018-03-21 00:08:13 -07007796
7797 @Override
7798 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007799 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801
7802 final long identity = Binder.clearCallingIdentity();
7803 try {
7804 final Phone phone = getPhone(subId);
7805 if (phone == null) {
7806 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7807 return;
7808 }
chen xueaba88a2019-03-15 13:15:10 -07007809 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7810 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07007811 if (carrierPrivilegeRules == null) {
7812 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7813 } else {
7814 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 } finally {
7817 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007818 }
fionaxua13278b2018-03-21 00:08:13 -07007819 }
7820
7821 @Override
7822 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007823 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824
7825 final long identity = Binder.clearCallingIdentity();
7826 try {
7827 final Phone phone = getPhone(subId);
7828 if (phone == null) {
7829 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7830 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7831 }
7832 return phone.getCarrierIdListVersion();
7833 } finally {
7834 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007835 }
fionaxua13278b2018-03-21 00:08:13 -07007836 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007837
7838 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007839 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7840 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007842 mApp, subId, callingPackage, callingFeatureId,
7843 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007844 return -1;
7845 }
7846
7847 final long identity = Binder.clearCallingIdentity();
7848 try {
7849 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7850 } finally {
7851 Binder.restoreCallingIdentity(identity);
7852 }
7853 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007854
7855 @Override
7856 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007857 TelephonyPermissions
7858 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007859 mApp, subId, "getCdmaRoamingMode");
7860
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7864 } finally {
7865 Binder.restoreCallingIdentity(identity);
7866 }
7867 }
7868
7869 @Override
7870 public boolean setCdmaRoamingMode(int subId, int mode) {
7871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7872 mApp, subId, "setCdmaRoamingMode");
7873
7874 final long identity = Binder.clearCallingIdentity();
7875 try {
7876 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7877 } finally {
7878 Binder.restoreCallingIdentity(identity);
7879 }
7880 }
7881
7882 @Override
7883 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7885 mApp, subId, "setCdmaSubscriptionMode");
7886
7887 final long identity = Binder.clearCallingIdentity();
7888 try {
7889 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
7892 }
7893 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007894
sqianc5eccab2018-10-19 18:46:41 -07007895 @Override
sqian8c685422019-02-22 15:55:18 -08007896 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007897 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007899 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7900 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007901 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7902 }
7903 final long identity = Binder.clearCallingIdentity();
7904 try {
sqian854d44b2018-12-12 16:48:18 -08007905 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7906 for (Phone phone: PhoneFactory.getPhones()) {
7907 if (phone.getEmergencyNumberTracker() != null
7908 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7909 emergencyNumberListInternal.put(
7910 phone.getSubId(),
7911 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7912 }
sqian11b7a0e2018-12-05 18:48:28 -08007913 }
sqian854d44b2018-12-12 16:48:18 -08007914 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
sqianc5eccab2018-10-19 18:46:41 -07007918 }
7919
7920 @Override
sqian8c685422019-02-22 15:55:18 -08007921 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007922 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007923 if (!exactMatch) {
7924 TelephonyPermissions
7925 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007926 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007927 }
7928 final long identity = Binder.clearCallingIdentity();
7929 try {
sqian854d44b2018-12-12 16:48:18 -08007930 for (Phone phone: PhoneFactory.getPhones()) {
7931 if (phone.getEmergencyNumberTracker() != null
7932 && phone.getEmergencyNumberTracker() != null) {
7933 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7934 number, exactMatch)) {
7935 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007936 }
7937 }
sqian11b7a0e2018-12-05 18:48:28 -08007938 }
7939 return false;
7940 } finally {
7941 Binder.restoreCallingIdentity(identity);
7942 }
7943 }
7944
sqianf4ca7ed2019-01-15 18:32:07 -08007945 /**
7946 * Update emergency number list for test mode.
7947 */
7948 @Override
7949 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7950 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7951 "updateEmergencyNumberListTestMode");
7952
7953 final long identity = Binder.clearCallingIdentity();
7954 try {
7955 for (Phone phone: PhoneFactory.getPhones()) {
7956 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7957 if (tracker != null) {
7958 tracker.executeEmergencyNumberTestModeCommand(action, num);
7959 }
7960 }
7961 } finally {
7962 Binder.restoreCallingIdentity(identity);
7963 }
7964 }
7965
7966 /**
7967 * Get the full emergency number list for test mode.
7968 */
7969 @Override
7970 public List<String> getEmergencyNumberListTestMode() {
7971 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7972 "getEmergencyNumberListTestMode");
7973
7974 final long identity = Binder.clearCallingIdentity();
7975 try {
7976 Set<String> emergencyNumbers = new HashSet<>();
7977 for (Phone phone: PhoneFactory.getPhones()) {
7978 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7979 if (tracker != null) {
7980 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7981 emergencyNumbers.add(num.getNumber());
7982 }
7983 }
7984 }
7985 return new ArrayList<>(emergencyNumbers);
7986 } finally {
7987 Binder.restoreCallingIdentity(identity);
7988 }
7989 }
7990
chen xud6b45bd2018-10-30 22:27:10 -07007991 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007992 public int getEmergencyNumberDbVersion(int subId) {
7993 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7994
7995 final long identity = Binder.clearCallingIdentity();
7996 try {
7997 final Phone phone = getPhone(subId);
7998 if (phone == null) {
7999 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8000 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8001 }
8002 return phone.getEmergencyNumberDbVersion();
8003 } finally {
8004 Binder.restoreCallingIdentity(identity);
8005 }
8006 }
8007
8008 @Override
8009 public void notifyOtaEmergencyNumberDbInstalled() {
8010 enforceModifyPermission();
8011
8012 final long identity = Binder.clearCallingIdentity();
8013 try {
8014 for (Phone phone: PhoneFactory.getPhones()) {
8015 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8016 if (tracker != null) {
8017 tracker.updateOtaEmergencyNumberDatabase();
8018 }
8019 }
8020 } finally {
8021 Binder.restoreCallingIdentity(identity);
8022 }
8023 }
8024
8025 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008026 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008027 enforceActiveEmergencySessionPermission();
8028
8029 final long identity = Binder.clearCallingIdentity();
8030 try {
8031 for (Phone phone: PhoneFactory.getPhones()) {
8032 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8033 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008034 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8035 }
8036 }
8037 } finally {
8038 Binder.restoreCallingIdentity(identity);
8039 }
8040 }
8041
8042 @Override
8043 public void resetOtaEmergencyNumberDbFilePath() {
8044 enforceActiveEmergencySessionPermission();
8045
8046 final long identity = Binder.clearCallingIdentity();
8047 try {
8048 for (Phone phone: PhoneFactory.getPhones()) {
8049 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8050 if (tracker != null) {
8051 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008052 }
8053 }
8054 } finally {
8055 Binder.restoreCallingIdentity(identity);
8056 }
8057 }
8058
8059 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008060 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8061 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8062 Phone phone = getPhone(subId);
8063 if (phone == null) {
8064 return null;
8065 }
8066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 UiccProfile profile = UiccController.getInstance()
8069 .getUiccProfileForPhone(phone.getPhoneId());
8070 if (profile != null) {
8071 return profile.getCertsFromCarrierPrivilegeAccessRules();
8072 }
8073 } finally {
8074 Binder.restoreCallingIdentity(identity);
8075 }
8076 return null;
8077 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008078
8079 /**
8080 * Enable or disable a modem stack.
8081 */
8082 @Override
8083 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8084 enforceModifyPermission();
8085
8086 final long identity = Binder.clearCallingIdentity();
8087 try {
8088 Phone phone = PhoneFactory.getPhone(slotIndex);
8089 if (phone == null) {
8090 return false;
8091 } else {
8092 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8093 }
8094 } finally {
8095 Binder.restoreCallingIdentity(identity);
8096 }
8097 }
Michelecea4cf22018-12-21 15:00:11 -08008098
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008099 /**
8100 * Whether a modem stack is enabled or not.
8101 */
8102 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008103 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8104 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008105 Phone phone = PhoneFactory.getPhone(slotIndex);
8106 if (phone == null) return false;
8107
8108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008109 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8110 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008111 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8112 }
8113
8114 final long identity = Binder.clearCallingIdentity();
8115 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008116 try {
8117 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8118 } catch (NoSuchElementException ex) {
8119 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8120 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008121 } finally {
8122 Binder.restoreCallingIdentity(identity);
8123 }
8124 }
8125
Michelecea4cf22018-12-21 15:00:11 -08008126 @Override
Michele0ea7d782019-03-19 14:58:42 -07008127 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008128 enforceModifyPermission();
8129
8130 final long identity = Binder.clearCallingIdentity();
8131 try {
8132 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008133 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008134 .commit();
8135 } finally {
8136 Binder.restoreCallingIdentity(identity);
8137 }
8138 }
8139
8140 @Override
Michele0ea7d782019-03-19 14:58:42 -07008141 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008142 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008144 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8145 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008146 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008147 }
Michelecea4cf22018-12-21 15:00:11 -08008148
8149 final long identity = Binder.clearCallingIdentity();
8150 try {
Michele0ea7d782019-03-19 14:58:42 -07008151 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008152 } finally {
8153 Binder.restoreCallingIdentity(identity);
8154 }
8155 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008156
Michele0ea7d782019-03-19 14:58:42 -07008157 @TelephonyManager.IsMultiSimSupportedResult
8158 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008159 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8160 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8161 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008162 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8163 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008164 }
8165 // Check if the hardware supports multisim functionality. If usage of multisim is not
8166 // supported by the modem, indicate that it is restricted.
8167 PhoneCapability staticCapability =
8168 mPhoneConfigurationManager.getStaticPhoneCapability();
8169 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008170 loge("isMultiSimSupportedInternal: no static configuration available");
8171 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008172 }
Sarah Chin7caee492020-02-18 20:49:02 +00008173 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008174 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8175 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008176 }
8177 // Check if support of multiple SIMs is restricted by carrier
8178 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008179 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008180 }
8181
Michele0ea7d782019-03-19 14:58:42 -07008182 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008183 }
8184
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008185 /**
8186 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008187 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8188 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8189 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008190 * @param numOfSims number of active sims we want to switch to
8191 */
8192 @Override
8193 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008194 if (numOfSims == 1) {
8195 enforceModifyPermission();
8196 } else {
8197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8198 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8199 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008200 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008201
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008202 try {
Michele30b57b22019-03-01 12:01:14 -08008203 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008204 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008205 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8206 return;
8207 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008208 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8209 } finally {
8210 Binder.restoreCallingIdentity(identity);
8211 }
8212 }
8213
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008214 @Override
8215 public boolean isApplicationOnUicc(int subId, int appType) {
8216 enforceReadPrivilegedPermission("isApplicationOnUicc");
8217 Phone phone = getPhone(subId);
8218 if (phone == null) {
8219 return false;
8220 }
8221 final long identity = Binder.clearCallingIdentity();
8222 try {
8223 UiccCard uiccCard = phone.getUiccCard();
8224 if (uiccCard == null) {
8225 return false;
8226 }
8227 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8228 if (uiccProfile == null) {
8229 return false;
8230 }
8231 if (TelephonyManager.APPTYPE_SIM <= appType
8232 && appType <= TelephonyManager.APPTYPE_ISIM) {
8233 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8234 }
8235 return false;
8236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
8239 }
8240
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008241 /**
chen xub4baa772019-04-03 10:23:41 -07008242 * Get whether making changes to modem configurations will trigger reboot.
8243 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008244 */
8245 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008246 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8247 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008249 mApp, subId, callingPackage, callingFeatureId,
8250 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008251 return false;
8252 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008253 final long identity = Binder.clearCallingIdentity();
8254 try {
8255 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8256 } finally {
8257 Binder.restoreCallingIdentity(identity);
8258 }
8259 }
8260
Nathan Harold29f5f052019-02-15 13:41:57 -08008261 private void updateModemStateMetrics() {
8262 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8263 // TODO: check the state for each modem if the api is ready.
8264 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8265 }
8266
Pengquan Meng3889a572019-01-23 11:16:29 -08008267 @Override
8268 public int[] getSlotsMapping() {
8269 enforceReadPrivilegedPermission("getSlotsMapping");
8270
8271 final long identity = Binder.clearCallingIdentity();
8272 try {
8273 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8274 // All logical slots should have a mapping to a physical slot.
8275 int[] logicalSlotsMapping = new int[phoneCount];
8276 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8277 for (int i = 0; i < slotInfos.length; i++) {
8278 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8279 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8280 }
8281 }
8282 return logicalSlotsMapping;
8283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
8286 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008287
8288 /**
8289 * Get the IRadio HAL Version
8290 */
8291 @Override
8292 public int getRadioHalVersion() {
8293 Phone phone = getDefaultPhone();
8294 if (phone == null) return -1;
8295 HalVersion hv = phone.getHalVersion();
8296 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8297 return hv.major * 100 + hv.minor;
8298 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008299
8300 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008301 * Get the current calling package name.
8302 * @return the current calling package name
8303 */
8304 @Override
8305 public String getCurrentPackageName() {
8306 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8307 }
8308
8309 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008310 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8311 * corresponding network requests on a subId.
8312 *
8313 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008314 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008315 * 2) APN is un-metered for this subscription, or
8316 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008317 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008318 *
8319 * @return whether data is allowed for a apn type.
8320 *
8321 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008322 */
8323 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008324 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008325 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8326 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008327
8328 // Now that all security checks passes, perform the operation as ourselves.
8329 final long identity = Binder.clearCallingIdentity();
8330 try {
8331 Phone phone = getPhone(subId);
8332 if (phone == null) return false;
8333
Jack Yu41407ee2019-05-13 16:54:09 -07008334 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008335 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
8339 }
8340
8341 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008342 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008343 enforceReadPrivilegedPermission("isApnMetered");
8344
8345 // Now that all security checks passes, perform the operation as ourselves.
8346 final long identity = Binder.clearCallingIdentity();
8347 try {
8348 Phone phone = getPhone(subId);
8349 if (phone == null) return true; // By default return true.
8350
Jack Yu41407ee2019-05-13 16:54:09 -07008351 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008352 } finally {
8353 Binder.restoreCallingIdentity(identity);
8354 }
8355 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008356
8357 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008358 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8359 int subscriptionId, IBooleanConsumer resultCallback) {
8360 enforceModifyPermission();
8361 long token = Binder.clearCallingIdentity();
8362 try {
8363 Phone phone = getPhone(subscriptionId);
8364 if (phone == null) {
8365 try {
8366 if (resultCallback != null) {
8367 resultCallback.accept(false);
8368 }
8369 } catch (RemoteException e) {
8370 // ignore
8371 }
8372 return;
8373 }
8374 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8375 Pair.create(specifiers, (x) -> {
8376 try {
8377 if (resultCallback != null) {
8378 resultCallback.accept(x);
8379 }
8380 } catch (RemoteException e) {
8381 // ignore
8382 }
8383 });
8384 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8385 } finally {
8386 Binder.restoreCallingIdentity(token);
8387 }
8388 }
8389
8390 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008391 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008392 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008393 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8394 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8395 if (iccRecords == null) {
8396 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8397 return false;
8398 }
8399 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8400 }
8401
8402 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008403 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8404 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008405 if (callingPackage == null) {
8406 callingPackage = getCurrentPackageName();
8407 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008408 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8409 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008410 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8411 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008412 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8413 }
8414 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8415 Intent intent = new Intent();
8416 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8417 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8418 // Bring up choose default SMS subscription dialog right now
8419 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8420 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8421 mApp.startActivity(intent);
8422 }
chen xud5ca2d52019-05-28 15:20:57 -07008423
8424 @Override
8425 public String getMmsUAProfUrl(int subId) {
8426 //TODO investigate if this API should require proper permission check in R b/133791609
8427 final long identity = Binder.clearCallingIdentity();
8428 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008429 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8430 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8431 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8432 return carrierUAProfUrl;
8433 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008434 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8435 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008436 } finally {
8437 Binder.restoreCallingIdentity(identity);
8438 }
8439 }
8440
8441 @Override
8442 public String getMmsUserAgent(int subId) {
8443 //TODO investigate if this API should require proper permission check in R b/133791609
8444 final long identity = Binder.clearCallingIdentity();
8445 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008446 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8447 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8448 if (!TextUtils.isEmpty(carrierUserAgent)) {
8449 return carrierUserAgent;
8450 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008451 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8452 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008453 } finally {
8454 Binder.restoreCallingIdentity(identity);
8455 }
8456 }
Jack Yub07d4972019-05-28 16:12:25 -07008457
8458 @Override
8459 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8460 enforceModifyPermission();
8461
8462 // Now that all security checks passes, perform the operation as ourselves.
8463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 Phone phone = getPhone(subId);
8466 if (phone == null) return false;
8467
8468 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8469 } finally {
8470 Binder.restoreCallingIdentity(identity);
8471 }
8472 }
8473
8474 @Override
8475 public boolean isDataAllowedInVoiceCall(int subId) {
8476 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8477
8478 // Now that all security checks passes, perform the operation as ourselves.
8479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 Phone phone = getPhone(subId);
8482 if (phone == null) return false;
8483
8484 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8485 } finally {
8486 Binder.restoreCallingIdentity(identity);
8487 }
8488 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008489
changbettyd5c246e2019-12-24 15:40:37 +08008490 @Override
8491 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8492 enforceModifyPermission();
8493
8494 // Now that all security checks passes, perform the operation as ourselves.
8495 final long identity = Binder.clearCallingIdentity();
8496 try {
8497 Phone phone = getPhone(subId);
8498 if (phone == null) return false;
8499
8500 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8501 } finally {
8502 Binder.restoreCallingIdentity(identity);
8503 }
8504 }
8505
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008506 /**
8507 * Updates whether conference event pacakge handling is enabled.
8508 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8509 * otherwise.
8510 */
8511 @Override
8512 public void setCepEnabled(boolean isCepEnabled) {
8513 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8514
8515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8518 for (Phone phone : PhoneFactory.getPhones()) {
8519 Phone defaultPhone = phone.getImsPhone();
8520 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8521 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8522 ImsPhoneCallTracker imsPhoneCallTracker =
8523 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8524 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8525 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8526 + imsPhone.getMsisdn());
8527 }
8528 }
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
8531 }
8532 }
allenwtsu46dcc572020-01-08 18:24:03 +08008533
8534 /**
8535 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8536 *
8537 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8538 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8539 * before being read.
8540 */
8541 @Override
8542 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8543 isCompressed) {
8544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8545 mApp, subId, "notifyRcsAutoConfigurationReceived");
8546 try {
8547 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8548 if (configBinder == null) {
8549 Rlog.e(LOG_TAG, "null result for getImsConfig");
8550 } else {
8551 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8552 }
8553 } catch (RemoteException e) {
8554 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8555 }
8556 }
zoey chene02881a2019-12-30 16:11:23 +08008557
8558 @Override
8559 public boolean isIccLockEnabled(int subId) {
8560 enforceReadPrivilegedPermission("isIccLockEnabled");
8561
8562 // Now that all security checks passes, perform the operation as ourselves.
8563 final long identity = Binder.clearCallingIdentity();
8564 try {
8565 Phone phone = getPhone(subId);
8566 if (phone != null && phone.getIccCard() != null) {
8567 return phone.getIccCard().getIccLockEnabled();
8568 } else {
8569 return false;
8570 }
8571 } finally {
8572 Binder.restoreCallingIdentity(identity);
8573 }
8574 }
8575
8576 /**
8577 * Set the ICC pin lock enabled or disabled.
8578 *
8579 * @return an integer representing the status of IccLock enabled or disabled in the following
8580 * three cases:
8581 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8582 * successfully.
8583 * - Positive number and zero for remaining password attempts.
8584 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8585 *
8586 */
8587 @Override
8588 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8589 enforceModifyPermission();
8590
8591 Phone phone = getPhone(subId);
8592 if (phone == null) {
8593 return 0;
8594 }
8595 // Now that all security checks passes, perform the operation as ourselves.
8596 final long identity = Binder.clearCallingIdentity();
8597 try {
8598 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8599 new Pair<Boolean, String>(enabled, password), phone, null);
8600 return attemptsRemaining;
8601
8602 } catch (Exception e) {
8603 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8604 } finally {
8605 Binder.restoreCallingIdentity(identity);
8606 }
8607 return 0;
8608 }
8609
8610 /**
8611 * Change the ICC password used in ICC pin lock.
8612 *
8613 * @return an integer representing the status of IccLock changed in the following three cases:
8614 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8615 * - Positive number and zero for remaining password attempts.
8616 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8617 *
8618 */
8619 @Override
8620 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8621 enforceModifyPermission();
8622
8623 Phone phone = getPhone(subId);
8624 if (phone == null) {
8625 return 0;
8626 }
8627 // Now that all security checks passes, perform the operation as ourselves.
8628 final long identity = Binder.clearCallingIdentity();
8629 try {
8630 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8631 new Pair<String, String>(oldPassword, newPassword), phone, null);
8632 return attemptsRemaining;
8633
8634 } catch (Exception e) {
8635 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8636 } finally {
8637 Binder.restoreCallingIdentity(identity);
8638 }
8639 return 0;
8640 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008641
8642 /**
8643 * Request for receiving user activity notification
8644 */
8645 @Override
8646 public void requestUserActivityNotification() {
8647 if (!mNotifyUserActivity.get()
8648 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8649 mNotifyUserActivity.set(true);
8650 }
8651 }
8652
8653 /**
8654 * Called when userActivity is signalled in the power manager.
8655 * This is safe to call from any thread, with any window manager locks held or not.
8656 */
8657 @Override
8658 public void userActivity() {
8659 // ***************************************
8660 // * Inherited from PhoneWindowManager *
8661 // ***************************************
8662 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8663 // WITH ITS LOCKS HELD.
8664 //
8665 // This code must be VERY careful about the locks
8666 // it acquires.
8667 // In fact, the current code acquires way too many,
8668 // and probably has lurking deadlocks.
8669
8670 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8671 throw new SecurityException("Only the OS may call notifyUserActivity()");
8672 }
8673
8674 if (mNotifyUserActivity.getAndSet(false)) {
8675 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8676 USER_ACTIVITY_NOTIFICATION_DELAY);
8677 }
8678 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008679
8680 @Override
8681 public boolean canConnectTo5GInDsdsMode() {
8682 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008684}