blob: 8f88af6d10e41ce77ff5456272ed47ee4acd7a5d [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) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005803 try {
5804 try {
5805 mApp.enforceCallingOrSelfPermission(
5806 android.Manifest.permission.ACCESS_NETWORK_STATE,
5807 null);
5808 } catch (Exception e) {
5809 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
5810 "isDataEnabled");
5811 }
5812 } catch (Exception e) {
5813 enforceReadPrivilegedPermission("isDataEnabled");
5814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815
5816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 int phoneId = mSubscriptionController.getPhoneId(subId);
5819 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5820 Phone phone = PhoneFactory.getPhone(phoneId);
5821 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005822 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5824 return retVal;
5825 } else {
5826 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5827 return false;
5828 }
5829 } finally {
5830 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005831 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005832 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005833
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005834 /**
5835 * Check if data is enabled for a specific reason
5836 * @param subId Subscription index
5837 * @param reason the reason the data enable change is taking place
5838 * @return {@code true} if the overall data is enabled; {@code false} if not.
5839 */
5840 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005841 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005842 @TelephonyManager.DataEnabledReason int reason) {
5843 try {
5844 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5845 null);
5846 } catch (Exception e) {
5847 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005848 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005849 }
5850
5851
5852 final long identity = Binder.clearCallingIdentity();
5853 try {
5854 int phoneId = mSubscriptionController.getPhoneId(subId);
5855 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005856 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005857 + " reason=" + reason);
5858 }
5859 Phone phone = PhoneFactory.getPhone(phoneId);
5860 if (phone != null) {
5861 boolean retVal;
5862 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
5863 retVal = phone.isUserDataEnabled();
5864 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005865 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005866 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005867 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005868 return retVal;
5869 } else {
5870 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005871 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005872 + subId + " retVal=false");
5873 }
5874 return false;
5875 }
5876 } finally {
5877 Binder.restoreCallingIdentity(identity);
5878 }
5879 }
5880
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005881 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005882 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07005883 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5884 // Skip the check if it's one of these special uids
5885 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5886 }
5887
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005888 //load access rules from carrier configs, and check those as well: b/139133814
5889 SubscriptionController subController = SubscriptionController.getInstance();
5890 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5891 || subController == null) return privilegeFromSim;
5892
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005893 PackageManager pkgMgr = phone.getContext().getPackageManager();
5894 String[] packages = pkgMgr.getPackagesForUid(uid);
5895
5896 final long identity = Binder.clearCallingIdentity();
5897 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005898 int subId = phone.getSubId();
5899 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5900 // A test override is in place for the privileges for this subId, so don't try to
5901 // read the subscription privileges.
5902 return privilegeFromSim;
5903 }
5904 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005905 SubscriptionManager subManager = (SubscriptionManager)
5906 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5907 for (String pkg : packages) {
5908 if (subManager.canManageSubscription(subInfo, pkg)) {
5909 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5910 }
5911 }
5912 return privilegeFromSim;
5913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
5916 }
5917
5918 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5919 String pkgName) {
5920 //load access rules from carrier configs, and check those as well: b/139133814
5921 SubscriptionController subController = SubscriptionController.getInstance();
5922 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5923 || subController == null) return privilegeFromSim;
5924
5925 final long identity = Binder.clearCallingIdentity();
5926 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005927 int subId = phone.getSubId();
5928 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5929 // A test override is in place for the privileges for this subId, so don't try to
5930 // read the subscription privileges.
5931 return privilegeFromSim;
5932 }
5933 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005934 SubscriptionManager subManager = (SubscriptionManager)
5935 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5936 return subManager.canManageSubscription(subInfo, pkgName)
5937 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5938 } finally {
5939 Binder.restoreCallingIdentity(identity);
5940 }
5941 }
5942
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005943 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005944 public int getCarrierPrivilegeStatus(int subId) {
5945 final Phone phone = getPhone(subId);
5946 if (phone == null) {
5947 loge("getCarrierPrivilegeStatus: Invalid subId");
5948 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5949 }
5950 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005951 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005952 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005953 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5954 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005955
5956 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5957 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005958 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005959 }
Junda Liu29340342014-07-10 15:23:27 -07005960
5961 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005962 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005963 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005964 final Phone phone = getPhone(subId);
5965 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005966 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005967 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5968 }
5969 UiccProfile profile =
5970 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5971 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005972 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005973 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5974 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005975 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005976 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005977 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005978 }
5979
5980 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005981 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5982 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005983 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005984 }
5985
5986 int phoneId = SubscriptionManager.getPhoneId(subId);
5987 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005988 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005989 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005990 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5991 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005992 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5993 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5994 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005995 }
5996
5997 @Override
5998 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005999 if (TextUtils.isEmpty(pkgName))
6000 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006001 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6002 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6003 UiccCard card = UiccController.getInstance().getUiccCard(i);
6004 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006005 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006006 continue;
6007 }
6008
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006009 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6010 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6011 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006012 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6013 break;
6014 }
6015 }
6016
6017 return result;
Junda Liu29340342014-07-10 15:23:27 -07006018 }
Derek Tan89e89d42014-07-08 17:00:10 -07006019
6020 @Override
Junda Liue64de782015-04-16 17:19:16 -07006021 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6022 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6023 loge("phoneId " + phoneId + " is not valid.");
6024 return null;
6025 }
6026 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006027 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006028 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006029 return null ;
6030 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006031 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006032 }
6033
Amith Yamasani6e118872016-02-19 12:53:51 -08006034 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006035 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006036 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006037 List<String> privilegedPackages = new ArrayList<>();
6038 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006039 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6040 // has UICC in that slot.
6041 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006042 if (card.hasCarrierPrivilegeRules()) {
6043 if (packages == null) {
6044 // Only check packages in user 0 for now
6045 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006046 PackageManager.MATCH_DISABLED_COMPONENTS
6047 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006048 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006049 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006050 }
6051 for (int p = packages.size() - 1; p >= 0; p--) {
6052 PackageInfo pkgInfo = packages.get(p);
6053 if (pkgInfo != null && pkgInfo.packageName != null
6054 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006055 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006056 privilegedPackages.add(pkgInfo.packageName);
6057 }
6058 }
6059 }
6060 }
6061 return privilegedPackages;
6062 }
6063
chen xuf7e9fe82019-05-09 19:31:02 -07006064 @Override
6065 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006066 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6067
6068 final long identity = Binder.clearCallingIdentity();
6069
chen xuf7e9fe82019-05-09 19:31:02 -07006070 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006071 try {
6072 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6073 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6074 }
6075 } finally {
6076 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006077 }
6078 return privilegedPackages;
6079 }
6080
Wink Savilleb564aae2014-10-23 10:18:09 -07006081 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006082 final Phone phone = getPhone(subId);
6083 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006084 if (card == null) {
6085 loge("getIccId: No UICC");
6086 return null;
6087 }
6088 String iccId = card.getIccId();
6089 if (TextUtils.isEmpty(iccId)) {
6090 loge("getIccId: ICC ID is null or empty.");
6091 return null;
6092 }
6093 return iccId;
6094 }
6095
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006096 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006097 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6098 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006099 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006100 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 final String iccId = getIccId(subId);
6105 final Phone phone = getPhone(subId);
6106 if (phone == null) {
6107 return false;
6108 }
6109 final String subscriberId = phone.getSubscriberId();
6110
6111 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006112 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 + subscriberId + " to " + number);
6114 }
6115
6116 if (TextUtils.isEmpty(iccId)) {
6117 return false;
6118 }
6119
6120 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6121
6122 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6123 if (alphaTag == null) {
6124 editor.remove(alphaTagPrefKey);
6125 } else {
6126 editor.putString(alphaTagPrefKey, alphaTag);
6127 }
6128
6129 // Record both the line number and IMSI for this ICCID, since we need to
6130 // track all merged IMSIs based on line number
6131 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6132 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6133 if (number == null) {
6134 editor.remove(numberPrefKey);
6135 editor.remove(subscriberPrefKey);
6136 } else {
6137 editor.putString(numberPrefKey, number);
6138 editor.putString(subscriberPrefKey, subscriberId);
6139 }
6140
6141 editor.commit();
6142 return true;
6143 } finally {
6144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006145 }
Derek Tan7226c842014-07-02 17:42:23 -07006146 }
6147
6148 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006149 public String getLine1NumberForDisplay(int subId, String callingPackage,
6150 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006151 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006153 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006154 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006155 return null;
6156 }
Derek Tan97ebb422014-09-05 16:55:38 -07006157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 final long identity = Binder.clearCallingIdentity();
6159 try {
6160 String iccId = getIccId(subId);
6161 if (iccId != null) {
6162 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6163 if (DBG_MERGE) {
6164 log("getLine1NumberForDisplay returning "
6165 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6166 }
6167 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006168 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6170 return null;
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006173 }
Derek Tan7226c842014-07-02 17:42:23 -07006174 }
6175
6176 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006177 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6178 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006180 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006181 return null;
6182 }
Derek Tan97ebb422014-09-05 16:55:38 -07006183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184 final long identity = Binder.clearCallingIdentity();
6185 try {
6186 String iccId = getIccId(subId);
6187 if (iccId != null) {
6188 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6189 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6190 }
6191 return null;
6192 } finally {
6193 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006194 }
Derek Tan7226c842014-07-02 17:42:23 -07006195 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006196
6197 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006198 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6199 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006200 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6201 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006203 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006204 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006205 return null;
6206 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006207
Jordan Liub49b04b2019-05-06 14:45:15 -07006208 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6209 // the process, where TelephonyManager was instantiated.
6210 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006211 final long identity = Binder.clearCallingIdentity();
6212 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006213 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 final TelephonyManager tele = TelephonyManager.from(context);
6215 final SubscriptionManager sub = SubscriptionManager.from(context);
6216
6217 // Figure out what subscribers are currently active
6218 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219
Jordan Liub49b04b2019-05-06 14:45:15 -07006220 // Only consider subs which match the current subId
6221 // This logic can be simplified. See b/131189269 for progress.
6222 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006223 activeSubscriberIds.add(tele.getSubscriberId(subId));
6224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225
6226 // First pass, find a number override for an active subscriber
6227 String mergeNumber = null;
6228 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6229 for (String key : prefs.keySet()) {
6230 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6231 final String subscriberId = (String) prefs.get(key);
6232 if (activeSubscriberIds.contains(subscriberId)) {
6233 final String iccId = key.substring(
6234 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6235 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6236 mergeNumber = (String) prefs.get(numberKey);
6237 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006238 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 + " for active subscriber " + subscriberId);
6240 }
6241 if (!TextUtils.isEmpty(mergeNumber)) {
6242 break;
6243 }
6244 }
6245 }
6246 }
6247
6248 // Shortcut when no active merged subscribers
6249 if (TextUtils.isEmpty(mergeNumber)) {
6250 return null;
6251 }
6252
6253 // Second pass, find all subscribers under that line override
6254 final ArraySet<String> result = new ArraySet<>();
6255 for (String key : prefs.keySet()) {
6256 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6257 final String number = (String) prefs.get(key);
6258 if (mergeNumber.equals(number)) {
6259 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6260 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6261 final String subscriberId = (String) prefs.get(subscriberKey);
6262 if (!TextUtils.isEmpty(subscriberId)) {
6263 result.add(subscriberId);
6264 }
6265 }
6266 }
6267 }
6268
6269 final String[] resultArray = result.toArray(new String[result.size()]);
6270 Arrays.sort(resultArray);
6271 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006272 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6274 }
6275 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006276 } finally {
6277 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006278 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006279 }
6280
6281 @Override
zoey chen38003472019-12-13 17:16:31 +08006282 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6283 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006284
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 final TelephonyManager telephonyManager = mApp.getSystemService(
6288 TelephonyManager.class);
6289 String subscriberId = telephonyManager.getSubscriberId(subId);
6290 if (subscriberId == null) {
6291 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006292 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006293 + subId);
6294 }
6295 return null;
6296 }
6297
6298 final SubscriptionInfo info = SubscriptionController.getInstance()
6299 .getSubscriptionInfo(subId);
6300 final ParcelUuid groupUuid = info.getGroupUuid();
6301 // If it doesn't belong to any group, return just subscriberId of itself.
6302 if (groupUuid == null) {
6303 return new String[]{subscriberId};
6304 }
6305
6306 // Get all subscriberIds from the group.
6307 final List<String> mergedSubscriberIds = new ArrayList<>();
6308 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006309 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006310 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006311 for (SubscriptionInfo subInfo : groupInfos) {
6312 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6313 if (subscriberId != null) {
6314 mergedSubscriberIds.add(subscriberId);
6315 }
6316 }
6317
6318 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321
6322 }
6323 }
6324
6325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006326 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006327 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006328 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329
6330 final long identity = Binder.clearCallingIdentity();
6331 try {
6332 final Phone phone = getPhone(subId);
6333 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6334 } finally {
6335 Binder.restoreCallingIdentity(identity);
6336 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006337 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006338
6339 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006340 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006341 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6342 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006343 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6344 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345
6346 final long identity = Binder.clearCallingIdentity();
6347 try {
6348 final Phone phone = getPhone(subId);
6349 if (phone == null) {
6350 return false;
6351 }
6352 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6353 cdmaNonRoamingList);
6354 } finally {
6355 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006356 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006357 }
6358
6359 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006360 @Deprecated
6361 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6362 enforceModifyPermission();
6363
6364 int returnValue = 0;
6365 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006366 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006367 if(result.exception == null) {
6368 if (result.result != null) {
6369 byte[] responseData = (byte[])(result.result);
6370 if(responseData.length > oemResp.length) {
6371 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6372 responseData.length + "bytes. Buffer Size is " +
6373 oemResp.length + "bytes.");
6374 }
6375 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6376 returnValue = responseData.length;
6377 }
6378 } else {
6379 CommandException ex = (CommandException) result.exception;
6380 returnValue = ex.getCommandError().ordinal();
6381 if(returnValue > 0) returnValue *= -1;
6382 }
6383 } catch (RuntimeException e) {
6384 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6385 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6386 if(returnValue > 0) returnValue *= -1;
6387 }
6388
6389 return returnValue;
6390 }
6391
6392 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006393 public void setRadioCapability(RadioAccessFamily[] rafs) {
6394 try {
6395 ProxyController.getInstance().setRadioCapability(rafs);
6396 } catch (RuntimeException e) {
6397 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6398 }
6399 }
6400
6401 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006402 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006403 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006404 try {
6405 TelephonyPermissions
6406 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6407 mApp, phone.getSubId(), "getRadioAccessFamily");
6408 } catch (SecurityException e) {
6409 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6410 throw e;
6411 }
chen xub97461a2018-10-26 14:17:57 -07006412 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006413 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006414 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 final long identity = Binder.clearCallingIdentity();
6417 try {
chen xub97461a2018-10-26 14:17:57 -07006418 TelephonyPermissions
6419 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6420 mApp, phone.getSubId(), "getRadioAccessFamily");
6421 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422 } finally {
6423 Binder.restoreCallingIdentity(identity);
6424 }
chen xub97461a2018-10-26 14:17:57 -07006425 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006426 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006427
6428 @Override
6429 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006430 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432
6433 final long identity = Binder.clearCallingIdentity();
6434 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006435 ImsManager.getInstance(defaultPhone.getContext(),
6436 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006440 }
6441
6442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006443 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006444 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6446 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006447 return false;
6448 }
Svet Ganovb320e182015-04-16 12:30:10 -07006449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450 final long identity = Binder.clearCallingIdentity();
6451 try {
6452 // Check the user preference and the system-level IMS setting. Even if the user has
6453 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6454 // In the long run, we may instead need to check if there exists a connection service
6455 // which can support video calling.
6456 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006457 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458 return imsManager.isVtEnabledByPlatform()
6459 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6460 && imsManager.isVtEnabledByUser();
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006464 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006465
Andrew Leea1239f22015-03-02 17:44:07 -08006466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006467 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6468 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006470 mApp, subId, callingPackage, callingFeatureId,
6471 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 return false;
6473 }
6474
6475 final long identity = Binder.clearCallingIdentity();
6476 try {
6477 CarrierConfigManager configManager =
6478 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006479 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6481 } finally {
6482 Binder.restoreCallingIdentity(identity);
6483 }
Andrew Leea1239f22015-03-02 17:44:07 -08006484 }
6485
6486 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006487 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006489 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 return false;
6491 }
6492
6493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 CarrierConfigManager configManager =
6496 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006497 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6499 } finally {
6500 Binder.restoreCallingIdentity(identity);
6501 }
Andrew Leea1239f22015-03-02 17:44:07 -08006502 }
6503
Andrew Lee9431b832015-03-09 18:46:45 -07006504 @Override
6505 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006506 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006507 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006508 }
6509
6510 @Override
6511 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512 final long identity = Binder.clearCallingIdentity();
6513 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006514 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 } finally {
6516 Binder.restoreCallingIdentity(identity);
6517 }
Andrew Lee9431b832015-03-09 18:46:45 -07006518 }
6519
Hall Liuf6668912018-10-31 17:05:23 -07006520 /**
6521 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6522 * support for the feature and device firmware support.
6523 *
6524 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6525 */
6526 @Override
6527 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006529 final Phone phone = getPhone(subscriptionId);
6530 if (phone == null) {
6531 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6532 return false;
6533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006535 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6537 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006538 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 return isCarrierSupported && isDeviceSupported;
6540 } finally {
6541 Binder.restoreCallingIdentity(identity);
6542 }
Hall Liu98187582018-01-22 19:15:32 -08006543 }
6544
Hall Liuf6668912018-10-31 17:05:23 -07006545 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006546 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6547 * RTT setting, will return true if the device and carrier both support RTT.
6548 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006549 */
6550 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 final long identity = Binder.clearCallingIdentity();
6552 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006553 boolean isRttSupported = isRttSupported(subscriptionId);
6554 boolean isUserRttSettingOn = Settings.Secure.getInt(
6555 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6556 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6557 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6558 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006562 }
6563
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006564 @Deprecated
6565 @Override
6566 public String getDeviceId(String callingPackage) {
6567 return getDeviceIdWithFeature(callingPackage, null);
6568 }
6569
Sanket Padawe7310cc72015-01-14 09:53:20 -08006570 /**
6571 * Returns the unique device ID of phone, for example, the IMEI for
6572 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6573 *
6574 * <p>Requires Permission:
6575 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6576 */
6577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006578 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006579 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006580 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006581 return null;
6582 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006583 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006584 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006585 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006586 return null;
6587 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588
6589 final long identity = Binder.clearCallingIdentity();
6590 try {
6591 return phone.getDeviceId();
6592 } finally {
6593 Binder.restoreCallingIdentity(identity);
6594 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006595 }
6596
Ping Sunc67b7c22016-03-02 19:16:45 +08006597 /**
6598 * {@hide}
6599 * Returns the IMS Registration Status on a particular subid
6600 *
6601 * @param subId
6602 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006603 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006604 Phone phone = getPhone(subId);
6605 if (phone != null) {
6606 return phone.isImsRegistered();
6607 } else {
6608 return false;
6609 }
6610 }
6611
Santos Cordon7a1885b2015-02-03 11:15:19 -08006612 @Override
6613 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614 final long identity = Binder.clearCallingIdentity();
6615 try {
6616 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006620 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006621
Tyler Gunnf70ed162019-04-03 15:28:53 -07006622 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006623 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006624 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006626 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006627 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6628 }
6629 final long identity = Binder.clearCallingIdentity();
6630 try {
6631 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
6634 }
6635 }
6636
6637 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006638 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006639 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6640 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006641 final long identity = Binder.clearCallingIdentity();
6642 try {
6643 Phone phone = getPhone(subscriptionId);
6644 if (phone == null) {
6645 return null;
6646 }
6647 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6648 } finally {
6649 Binder.restoreCallingIdentity(identity);
6650 }
6651 }
6652
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006653 /**
6654 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006655 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006656 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 Phone phone = getPhone(subId);
6660 if (phone != null) {
6661 return phone.isWifiCallingEnabled();
6662 } else {
6663 return false;
6664 }
6665 } finally {
6666 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006667 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006668 }
6669
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006670 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006671 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006672 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006673 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674 final long identity = Binder.clearCallingIdentity();
6675 try {
6676 Phone phone = getPhone(subId);
6677 if (phone != null) {
6678 return phone.isVideoEnabled();
6679 } else {
6680 return false;
6681 }
6682 } finally {
6683 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006684 }
6685 }
6686
6687 /**
6688 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6689 * defined in {@link ImsRegistrationImplBase}.
6690 */
6691 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 final long identity = Binder.clearCallingIdentity();
6693 try {
6694 Phone phone = getPhone(subId);
6695 if (phone != null) {
6696 return phone.getImsRegistrationTech();
6697 } else {
6698 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6699 }
6700 } finally {
6701 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006702 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006703 }
6704
Stuart Scott8eef64f2015-04-08 15:13:54 -07006705 @Override
6706 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006707 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006708 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6709 return;
6710 }
6711
Svet Ganovcc087f82015-05-12 20:35:54 -07006712 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006713
Svet Ganovcc087f82015-05-12 20:35:54 -07006714 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006715 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6716 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006717 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006718 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006719 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006720 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006721 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6722 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006723 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006724 // There has been issues when Sms raw table somehow stores orphan
6725 // fragments. They lead to garbled message when new fragments come
6726 // in and combined with those stale ones. In case this happens again,
6727 // user can reset all network settings which will clean up this table.
6728 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006729 // Clean up IMS settings as well here.
6730 int slotId = getSlotIndex(subId);
6731 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6732 ImsManager.getInstance(mApp, slotId).factoryReset();
6733 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006734
6735 // Erase modem config if erase modem on network setting is enabled.
6736 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6737 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6738 if (configValue != null && Boolean.parseBoolean(configValue)) {
6739 sendEraseModemConfig(getDefaultPhone());
6740 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006741 } finally {
6742 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006743 }
6744 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006745
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006746 private void cleanUpSmsRawTable(Context context) {
6747 ContentResolver resolver = context.getContentResolver();
6748 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6749 resolver.delete(uri, null, null);
6750 }
6751
Narayan Kamath1c496c22015-04-16 14:40:19 +01006752 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006753 public String getSimLocaleForSubscriber(int subId) {
6754 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6755 final Phone phone = getPhone(subId);
6756 if (phone == null) {
6757 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006758 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 final long identity = Binder.clearCallingIdentity();
6761 try {
chen xu5d3637b2019-01-21 23:31:38 -08006762 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006763 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006764 if (info == null) {
6765 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6766 return null;
6767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768 // Try and fetch the locale from the carrier properties or from the SIM language
6769 // preferences (EF-PL and EF-LI)...
6770 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006772 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6773 if (localeFromDefaultSim != null) {
6774 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6775 if (DBG) log("Using locale from subId: " + subId + " locale: "
6776 + localeFromDefaultSim);
6777 return localeFromDefaultSim.toLanguageTag();
6778 } else {
6779 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 }
6781 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 // The SIM language preferences only store a language (e.g. fr = French), not an
6784 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6785 // the SIM and carrier preferences does not include a country we add the country
6786 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006787 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006789 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 return mccLocale.toLanguageTag();
6791 }
6792
6793 if (DBG) log("No locale found - returning null");
6794 return null;
6795 } finally {
6796 Binder.restoreCallingIdentity(identity);
6797 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006798 }
6799
6800 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006801 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006802 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006803 }
6804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 /**
6806 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6807 */
6808 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006809 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006810 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006811 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006812
Chenjie Yu1ba97252018-01-11 18:16:20 -08006813 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006814 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006815
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006816 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006817 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6818 * representing the state of the modem.
6819 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006820 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6821 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006822 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006823 */
6824 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006825 public void requestModemActivityInfo(ResultReceiver result) {
6826 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006827 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828
6829 final long identity = Binder.clearCallingIdentity();
6830 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006831 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 } finally {
6833 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006834 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006835 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006836
Siddharth Rayb8114062018-06-17 15:02:38 -07006837 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6838 // less than total activity duration.
6839 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6840 if (info == null) {
6841 return false;
6842 }
6843 int activityDurationMs =
6844 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6845 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006846 int[] txTimeMs = info.getTransmitTimeMillis();
6847 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6848 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006849 }
6850 return (info.isValid()
6851 && (info.getSleepTimeMillis() <= activityDurationMs)
6852 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006853 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006854 && (totalTxTimeMs <= activityDurationMs));
6855 }
6856
Jack Yu85bd38a2015-11-09 11:34:32 -08006857 /**
6858 * {@hide}
6859 * Returns the service state information on specified subscription.
6860 */
6861 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006862 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6863 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006865 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006866 return null;
6867 }
6868
Hall Liuf19c44f2018-11-27 14:38:17 -08006869 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6870 LocationAccessPolicy.checkLocationPermission(mApp,
6871 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6872 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006873 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006874 .setCallingPid(Binder.getCallingPid())
6875 .setCallingUid(Binder.getCallingUid())
6876 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006877 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006878 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006879 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6880 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006881 .build());
6882
6883 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6884 LocationAccessPolicy.checkLocationPermission(mApp,
6885 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6886 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006887 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006888 .setCallingPid(Binder.getCallingPid())
6889 .setCallingUid(Binder.getCallingUid())
6890 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006891 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006892 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006893 .setMinSdkVersionForFine(Integer.MAX_VALUE)
6894 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006895 .build());
6896 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6897 boolean hasFinePermission =
6898 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6899 boolean hasCoarsePermission =
6900 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 final long identity = Binder.clearCallingIdentity();
6903 try {
6904 final Phone phone = getPhone(subId);
6905 if (phone == null) {
6906 return null;
6907 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006908
Hall Liuf19c44f2018-11-27 14:38:17 -08006909 ServiceState ss = phone.getServiceState();
6910
6911 // Scrub out the location info in ServiceState depending on what level of access
6912 // the caller has.
6913 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006914 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6915 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 } finally {
6917 Binder.restoreCallingIdentity(identity);
6918 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006919 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006920
6921 /**
6922 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6923 *
6924 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6925 * voicemail ringtone.
6926 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6927 * PhoneAccount.
6928 */
6929 @Override
6930 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 final long identity = Binder.clearCallingIdentity();
6932 try {
6933 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6934 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006935 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
6941 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006942 }
6943
6944 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006945 * Sets the per-account voicemail ringtone.
6946 *
6947 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6948 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6949 *
6950 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6951 * voicemail ringtone.
6952 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6953 * PhoneAccount.
6954 */
6955 @Override
6956 public void setVoicemailRingtoneUri(String callingPackage,
6957 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006958 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006959 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006960 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6961 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6963 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6964 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966
6967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6970 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006971 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 }
6973 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6974 } finally {
6975 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006976 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006977 }
6978
6979 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006980 * Returns whether vibration is set for voicemail notification in Phone settings.
6981 *
6982 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6983 * voicemail vibration setting.
6984 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6985 */
6986 @Override
6987 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 final long identity = Binder.clearCallingIdentity();
6989 try {
6990 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6991 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006992 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6996 } finally {
6997 Binder.restoreCallingIdentity(identity);
6998 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006999 }
7000
Youhan Wange64578a2016-05-02 15:32:42 -07007001 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007002 * Sets the per-account voicemail vibration.
7003 *
7004 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7005 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7006 *
7007 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7008 * voicemail vibration setting.
7009 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7010 * specific PhoneAccount.
7011 */
7012 @Override
7013 public void setVoicemailVibrationEnabled(String callingPackage,
7014 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007015 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007017 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7018 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7020 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7021 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007022 }
7023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 final long identity = Binder.clearCallingIdentity();
7025 try {
7026 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7027 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007028 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 }
7030 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7031 } finally {
7032 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007033 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007034 }
7035
7036 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007037 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7038 *
7039 * @throws SecurityException if the caller does not have the required permission
7040 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007041 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007042 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007043 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007044 }
7045
7046 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007047 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7048 * permission.
7049 *
7050 * @throws SecurityException if the caller does not have the required permission
7051 */
7052 private void enforceSendSmsPermission() {
7053 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7054 }
7055
7056 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007057 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007058 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007059 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007060 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007061 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 final long identity = Binder.clearCallingIdentity();
7063 try {
7064 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007065 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 if (componentName == null) {
7067 throw new SecurityException(
7068 "Caller not current active visual voicemail package[null]");
7069 }
7070 String vvmPackage = componentName.getPackageName();
7071 if (!callingPackage.equals(vvmPackage)) {
7072 throw new SecurityException("Caller not current active visual voicemail package["
7073 + vvmPackage + "]");
7074 }
7075 } finally {
7076 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007077 }
7078 }
7079
7080 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007081 * Return the application ID for the app type.
7082 *
7083 * @param subId the subscription ID that this request applies to.
7084 * @param appType the uicc app type.
7085 * @return Application ID for specificied app type, or null if no uicc.
7086 */
7087 @Override
7088 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007089 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007090 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091
7092 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007093 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094 if (phone == null) {
7095 return null;
7096 }
7097 String aid = null;
7098 try {
7099 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7100 .getApplicationByType(appType).getAid();
7101 } catch (Exception e) {
7102 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7103 }
7104 return aid;
7105 } finally {
7106 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007107 }
Youhan Wange64578a2016-05-02 15:32:42 -07007108 }
7109
Youhan Wang4001d252016-05-11 10:29:41 -07007110 /**
7111 * Return the Electronic Serial Number.
7112 *
7113 * @param subId the subscription ID that this request applies to.
7114 * @return ESN or null if error.
7115 */
7116 @Override
7117 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007118 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007119 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120
7121 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007122 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123 if (phone == null) {
7124 return null;
7125 }
7126 String esn = null;
7127 try {
7128 esn = phone.getEsn();
7129 } catch (Exception e) {
7130 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7131 }
7132 return esn;
7133 } finally {
7134 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007135 }
Youhan Wang4001d252016-05-11 10:29:41 -07007136 }
7137
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007138 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007139 * Return the Preferred Roaming List Version.
7140 *
7141 * @param subId the subscription ID that this request applies to.
7142 * @return PRLVersion or null if error.
7143 */
7144 @Override
7145 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007146 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007147 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148
7149 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007150 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 if (phone == null) {
7152 return null;
7153 }
7154 String cdmaPrlVersion = null;
7155 try {
7156 cdmaPrlVersion = phone.getCdmaPrlVersion();
7157 } catch (Exception e) {
7158 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7159 }
7160 return cdmaPrlVersion;
7161 } finally {
7162 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007163 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007164 }
7165
7166 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007167 * Get snapshot of Telephony histograms
7168 * @return List of Telephony histograms
7169 * @hide
7170 */
7171 @Override
7172 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7174 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175
7176 final long identity = Binder.clearCallingIdentity();
7177 try {
7178 return RIL.getTelephonyRILTimingHistograms();
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
7181 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007182 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007183
7184 /**
7185 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007186 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7187 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007188 * Require system privileges. In the future we may add this to carrier APIs.
7189 *
Michele Berionne482f8202018-11-27 18:57:59 -08007190 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007191 */
7192 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007193 @TelephonyManager.SetCarrierRestrictionResult
7194 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007195 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007196 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007197
Michele Berionne482f8202018-11-27 18:57:59 -08007198 if (carrierRestrictionRules == null) {
7199 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007200 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 final long identity = Binder.clearCallingIdentity();
7203 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007204 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007205 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007209 }
7210
7211 /**
7212 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007213 * Get the allowed carrier list and the excluded carrier list, including the priority between
7214 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007215 * Require system privileges. In the future we may add this to carrier APIs.
7216 *
Michele Berionne482f8202018-11-27 18:57:59 -08007217 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007218 */
7219 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007220 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007221 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223
7224 final long identity = Binder.clearCallingIdentity();
7225 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007226 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7227 if (response instanceof CarrierRestrictionRules) {
7228 return (CarrierRestrictionRules) response;
7229 }
7230 // Response is an Exception of some kind,
7231 // which is signalled to the user as a NULL retval
7232 return null;
7233 } catch (Exception e) {
7234 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7235 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007239 }
7240
fionaxu59545b42016-05-25 15:53:37 -07007241 /**
fionaxu59545b42016-05-25 15:53:37 -07007242 * Action set from carrier signalling broadcast receivers to enable/disable radio
7243 * @param subId the subscription ID that this action applies to.
7244 * @param enabled control enable or disable radio.
7245 * {@hide}
7246 */
7247 @Override
7248 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7249 enforceModifyPermission();
7250 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251
7252 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007253 if (phone == null) {
7254 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7255 return;
7256 }
7257 try {
7258 phone.carrierActionSetRadioEnabled(enabled);
7259 } catch (Exception e) {
7260 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261 } finally {
7262 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007263 }
7264 }
7265
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007266 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007267 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7268 * network status based on which carrier apps could apply actions accordingly,
7269 * enable/disable default url handler for example.
7270 *
7271 * @param subId the subscription ID that this action applies to.
7272 * @param report control start/stop reporting the default network status.
7273 * {@hide}
7274 */
7275 @Override
7276 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7277 enforceModifyPermission();
7278 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279
7280 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007281 if (phone == null) {
7282 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7283 return;
7284 }
7285 try {
7286 phone.carrierActionReportDefaultNetworkStatus(report);
7287 } catch (Exception e) {
7288 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007289 } finally {
7290 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007291 }
7292 }
7293
7294 /**
fionaxud9622282017-07-17 17:51:30 -07007295 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7296 * @param subId the subscription ID that this action applies to.
7297 * {@hide}
7298 */
7299 @Override
7300 public void carrierActionResetAll(int subId) {
7301 enforceModifyPermission();
7302 final Phone phone = getPhone(subId);
7303 if (phone == null) {
7304 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7305 return;
7306 }
7307 try {
7308 phone.carrierActionResetAll();
7309 } catch (Exception e) {
7310 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7311 }
7312 }
7313
7314 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007315 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7316 * bug report is being generated.
7317 */
7318 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007319 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007320 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7321 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007322 writer.println("Permission Denial: can't dump Phone from pid="
7323 + Binder.getCallingPid()
7324 + ", uid=" + Binder.getCallingUid()
7325 + "without permission "
7326 + android.Manifest.permission.DUMP);
7327 return;
7328 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007329 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007330 }
Jack Yueb89b242016-06-22 13:27:47 -07007331
Brad Ebingerdac2f002018-04-03 15:17:52 -07007332 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007333 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7334 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7335 @NonNull String[] args) {
7336 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7337 this, in.getFileDescriptor(), out.getFileDescriptor(),
7338 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007339 }
7340
Jack Yueb89b242016-06-22 13:27:47 -07007341 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007342 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007343 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007344 * @param reason the reason the data enable change is taking place
7345 * @param enabled True if enabling the data, otherwise disabling.
7346 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007347 */
7348 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007349 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007350 boolean enabled) {
7351 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7352 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7353 try {
7354 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007355 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007356 } catch (SecurityException se) {
7357 enforceModifyPermission();
7358 }
7359 } else {
7360 enforceModifyPermission();
7361 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362
7363 final long identity = Binder.clearCallingIdentity();
7364 try {
7365 Phone phone = getPhone(subId);
7366 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007367 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7368 phone.carrierActionSetMeteredApnsEnabled(enabled);
7369 } else {
7370 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 }
7373 } finally {
7374 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007375 }
7376 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007377
7378 /**
7379 * Get Client request stats
7380 * @return List of Client Request Stats
7381 * @hide
7382 */
7383 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007384 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7385 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007387 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007388 return null;
7389 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007390 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 final long identity = Binder.clearCallingIdentity();
7393 try {
7394 if (phone != null) {
7395 return phone.getClientRequestStats();
7396 }
7397
7398 return null;
7399 } finally {
7400 Binder.restoreCallingIdentity(identity);
7401 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007402 }
7403
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007404 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007405 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007406 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007407 }
Jack Yueb4124c2017-02-16 15:32:43 -08007408
7409 /**
Grace Chen70990072017-03-24 17:21:30 -07007410 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007411 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007412 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007413 * @param state State of SIM (power down, power up, pass through)
7414 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7415 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7416 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007417 *
7418 **/
7419 @Override
Grace Chen70990072017-03-24 17:21:30 -07007420 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007421 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007422 Phone phone = PhoneFactory.getPhone(slotIndex);
7423
vagdeviaf9a5b92018-08-15 16:01:53 -07007424 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 final long identity = Binder.clearCallingIdentity();
7427 try {
7428 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007429 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 }
7431 } finally {
7432 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007433 }
7434 }
Shuo Qiandd210312017-04-12 22:11:33 +00007435
Tyler Gunn65d45c22017-06-05 11:22:26 -07007436 private boolean isUssdApiAllowed(int subId) {
7437 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007438 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007439 if (configManager == null) {
7440 return false;
7441 }
7442 PersistableBundle pb = configManager.getConfigForSubId(subId);
7443 if (pb == null) {
7444 return false;
7445 }
7446 return pb.getBoolean(
7447 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7448 }
7449
Shuo Qiandd210312017-04-12 22:11:33 +00007450 /**
7451 * Check if phone is in emergency callback mode
7452 * @return true if phone is in emergency callback mode
7453 * @param subId sub id
7454 */
goneil9c5f4872017-12-05 14:07:56 -08007455 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007456 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007457 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007458 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459
7460 final long identity = Binder.clearCallingIdentity();
7461 try {
7462 if (phone != null) {
7463 return phone.isInEcm();
7464 } else {
7465 return false;
7466 }
7467 } finally {
7468 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007469 }
7470 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007471
7472 /**
7473 * Get the current signal strength information for the given subscription.
7474 * Because this information is not updated when the device is in a low power state
7475 * it should not be relied-upon to be current.
7476 * @param subId Subscription index
7477 * @return the most recent cached signal strength info from the modem
7478 */
7479 @Override
7480 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 final long identity = Binder.clearCallingIdentity();
7482 try {
7483 Phone p = getPhone(subId);
7484 if (p == null) {
7485 return null;
7486 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 return p.getSignalStrength();
7489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007492 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007493
Pengquan Meng77b7f132018-08-22 14:49:57 -07007494 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007495 * Get the current modem radio state for the given slot.
7496 * @param slotIndex slot index.
7497 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007498 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007499 * @return the current radio power state from the modem
7500 */
7501 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007502 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007503 Phone phone = PhoneFactory.getPhone(slotIndex);
7504 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7506 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007507 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7508 }
7509
7510 final long identity = Binder.clearCallingIdentity();
7511 try {
7512 return phone.getRadioPowerState();
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
7515 }
7516 }
7517 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7518 }
7519
7520 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007521 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7522 *
7523 * <p>Requires one of the following permissions:
7524 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7525 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7526 * privileges.
7527 *
7528 * @param subId subscription id
7529 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7530 * {@code false}.
7531 */
7532 @Override
7533 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007534 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7535 null /* message */);
7536
Pengquan Menga1bb6272018-09-06 09:59:22 -07007537 boolean isEnabled = false;
7538 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007539 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007540 Phone phone = getPhone(subId);
7541 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007542 } catch (Exception e) {
7543 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7544 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007545 } finally {
7546 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007548 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007549 }
7550
7551
7552 /**
7553 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7554 *
7555 * <p> Requires permission:
7556 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7557 * privileges.
7558 *
7559 * @param subId subscription id
7560 * @param isEnabled {@code true} means enable, {@code false} means disable.
7561 */
7562 @Override
7563 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7565 mApp, subId, "setDataRoamingEnabled");
7566
Pengquan Menga1bb6272018-09-06 09:59:22 -07007567 final long identity = Binder.clearCallingIdentity();
7568 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007569 Phone phone = getPhone(subId);
7570 if (phone != null) {
7571 phone.setDataRoamingEnabled(isEnabled);
7572 }
7573 } finally {
7574 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007575 }
7576 }
7577
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007578 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007579 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007580 TelephonyPermissions
7581 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007582 mApp, subId, "isManualNetworkSelectionAllowed");
7583
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007584 boolean isAllowed = true;
7585 final long identity = Binder.clearCallingIdentity();
7586 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007587 Phone phone = getPhone(subId);
7588 if (phone != null) {
7589 isAllowed = phone.isCspPlmnEnabled();
7590 }
7591 } finally {
7592 Binder.restoreCallingIdentity(identity);
7593 }
7594 return isAllowed;
7595 }
7596
7597 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007598 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007599 // Verify that tha callingPackage belongs to the calling UID
7600 mApp.getSystemService(AppOpsManager.class)
7601 .checkPackage(Binder.getCallingUid(), callingPackage);
7602
Jordan Liu1e142fc2019-04-22 15:10:43 -07007603 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007604 try {
7605 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007606 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007607 } catch (SecurityException e) {
7608 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7609 // has carrier privileges on an active UICC
7610 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7611 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007612 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007613 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007614 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007615
7616 final long identity = Binder.clearCallingIdentity();
7617 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007618 UiccController uiccController = UiccController.getInstance();
7619 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007620 if (hasReadPermission) {
7621 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007622 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007623
7624 // Remove private info if the caller doesn't have access
7625 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7626 for (UiccCardInfo cardInfo : cardInfos) {
7627 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7628 // is available
7629 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7630 if (card == null || card.getUiccProfile() == null) {
7631 // assume no access if the card or profile is unavailable
7632 filteredInfos.add(cardInfo.getUnprivileged());
7633 continue;
7634 }
7635 UiccProfile profile = card.getUiccProfile();
7636 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7637 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7638 filteredInfos.add(cardInfo);
7639 } else {
7640 filteredInfos.add(cardInfo.getUnprivileged());
7641 }
7642 }
7643 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007644 } finally {
7645 Binder.restoreCallingIdentity(identity);
7646 }
7647 }
7648
7649 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007650 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007651 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007653 final long identity = Binder.clearCallingIdentity();
7654 try {
7655 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7656 if (slots == null) {
7657 Rlog.i(LOG_TAG, "slots is null.");
7658 return null;
7659 }
7660
7661 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7662 for (int i = 0; i < slots.length; i++) {
7663 UiccSlot slot = slots[i];
7664 if (slot == null) {
7665 continue;
7666 }
7667
Jordan Liu7be7e652019-05-06 18:55:02 +00007668 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669 UiccCard card = slot.getUiccCard();
7670 if (card != null) {
7671 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007672 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007673 cardId = slot.getEid();
7674 if (TextUtils.isEmpty(cardId)) {
7675 cardId = slot.getIccId();
7676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 }
7678
Jordan Liu857451f2019-05-09 16:35:35 -07007679 if (cardId != null) {
7680 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7681 // if cardId is an EID, it's all digits so this is fine
7682 cardId = IccUtils.stripTrailingFs(cardId);
7683 }
7684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 int cardState = 0;
7686 switch (slot.getCardState()) {
7687 case CARDSTATE_ABSENT:
7688 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7689 break;
7690 case CARDSTATE_PRESENT:
7691 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7692 break;
7693 case CARDSTATE_ERROR:
7694 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7695 break;
7696 case CARDSTATE_RESTRICTED:
7697 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7698 break;
7699 default:
7700 break;
7701
7702 }
7703
7704 infos[i] = new UiccSlotInfo(
7705 slot.isActive(),
7706 slot.isEuicc(),
7707 cardId,
7708 cardState,
7709 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007710 slot.isExtendedApduSupported(),
7711 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 }
7713 return infos;
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007716 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007717 }
7718
7719 @Override
7720 public boolean switchSlots(int[] physicalSlots) {
7721 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722
7723 final long identity = Binder.clearCallingIdentity();
7724 try {
7725 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7726 } finally {
7727 Binder.restoreCallingIdentity(identity);
7728 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007729 }
Jack Yu4c988042018-02-27 15:30:01 -08007730
7731 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007732 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007733 final long identity = Binder.clearCallingIdentity();
7734 try {
7735 return UiccController.getInstance().getCardIdForDefaultEuicc();
7736 } finally {
7737 Binder.restoreCallingIdentity(identity);
7738 }
7739 }
7740
Pengquan Meng85728fb2018-03-12 16:31:21 -07007741 /**
goneil47ffb6e2018-04-06 15:40:58 -07007742 * A test API to reload the UICC profile.
7743 *
7744 * <p>Requires that the calling app has permission
7745 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7746 * @hide
7747 */
7748 @Override
7749 public void refreshUiccProfile(int subId) {
7750 enforceModifyPermission();
7751
7752 final long identity = Binder.clearCallingIdentity();
7753 try {
7754 Phone phone = getPhone(subId);
7755 if (phone == null) {
7756 return;
7757 }
7758 UiccCard uiccCard = phone.getUiccCard();
7759 if (uiccCard == null) {
7760 return;
7761 }
7762 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7763 if (uiccProfile == null) {
7764 return;
7765 }
7766 uiccProfile.refresh();
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
7769 }
7770 }
7771
7772 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007773 * Returns false if the mobile data is disabled by default, otherwise return true.
7774 */
7775 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007776 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007777 }
7778
7779 /**
7780 * Returns true if the data roaming is enabled by default, i.e the system property
7781 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7782 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7783 */
7784 private boolean getDefaultDataRoamingEnabled(int subId) {
7785 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007786 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07007787 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007788 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7789 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7790 return isDataRoamingEnabled;
7791 }
7792
7793 /**
7794 * Returns the default network type for the given {@code subId}, if the default network type is
7795 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7796 */
7797 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007798 List<Integer> list = TelephonyProperties.default_network();
7799 int phoneId = mSubscriptionController.getPhoneId(subId);
7800 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7801 return list.get(phoneId);
7802 }
7803 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007804 }
fionaxua13278b2018-03-21 00:08:13 -07007805
7806 @Override
7807 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007808 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007809 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810
7811 final long identity = Binder.clearCallingIdentity();
7812 try {
7813 final Phone phone = getPhone(subId);
7814 if (phone == null) {
7815 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7816 return;
7817 }
chen xueaba88a2019-03-15 13:15:10 -07007818 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7819 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07007820 if (carrierPrivilegeRules == null) {
7821 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7822 } else {
7823 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 } finally {
7826 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007827 }
fionaxua13278b2018-03-21 00:08:13 -07007828 }
7829
7830 @Override
7831 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007832 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007833
7834 final long identity = Binder.clearCallingIdentity();
7835 try {
7836 final Phone phone = getPhone(subId);
7837 if (phone == null) {
7838 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7839 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7840 }
7841 return phone.getCarrierIdListVersion();
7842 } finally {
7843 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007844 }
fionaxua13278b2018-03-21 00:08:13 -07007845 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007846
7847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007848 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7849 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007851 mApp, subId, callingPackage, callingFeatureId,
7852 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007853 return -1;
7854 }
7855
7856 final long identity = Binder.clearCallingIdentity();
7857 try {
7858 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7859 } finally {
7860 Binder.restoreCallingIdentity(identity);
7861 }
7862 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007863
7864 @Override
7865 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007866 TelephonyPermissions
7867 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007868 mApp, subId, "getCdmaRoamingMode");
7869
7870 final long identity = Binder.clearCallingIdentity();
7871 try {
7872 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7873 } finally {
7874 Binder.restoreCallingIdentity(identity);
7875 }
7876 }
7877
7878 @Override
7879 public boolean setCdmaRoamingMode(int subId, int mode) {
7880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7881 mApp, subId, "setCdmaRoamingMode");
7882
7883 final long identity = Binder.clearCallingIdentity();
7884 try {
7885 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7886 } finally {
7887 Binder.restoreCallingIdentity(identity);
7888 }
7889 }
7890
7891 @Override
7892 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7894 mApp, subId, "setCdmaSubscriptionMode");
7895
7896 final long identity = Binder.clearCallingIdentity();
7897 try {
7898 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7899 } finally {
7900 Binder.restoreCallingIdentity(identity);
7901 }
7902 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007903
sqianc5eccab2018-10-19 18:46:41 -07007904 @Override
sqian8c685422019-02-22 15:55:18 -08007905 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007906 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007908 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7909 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007910 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7911 }
7912 final long identity = Binder.clearCallingIdentity();
7913 try {
sqian854d44b2018-12-12 16:48:18 -08007914 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7915 for (Phone phone: PhoneFactory.getPhones()) {
7916 if (phone.getEmergencyNumberTracker() != null
7917 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7918 emergencyNumberListInternal.put(
7919 phone.getSubId(),
7920 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7921 }
sqian11b7a0e2018-12-05 18:48:28 -08007922 }
sqian854d44b2018-12-12 16:48:18 -08007923 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007924 } finally {
7925 Binder.restoreCallingIdentity(identity);
7926 }
sqianc5eccab2018-10-19 18:46:41 -07007927 }
7928
7929 @Override
sqian8c685422019-02-22 15:55:18 -08007930 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007931 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007932 if (!exactMatch) {
7933 TelephonyPermissions
7934 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007935 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007936 }
7937 final long identity = Binder.clearCallingIdentity();
7938 try {
sqian854d44b2018-12-12 16:48:18 -08007939 for (Phone phone: PhoneFactory.getPhones()) {
7940 if (phone.getEmergencyNumberTracker() != null
7941 && phone.getEmergencyNumberTracker() != null) {
7942 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7943 number, exactMatch)) {
7944 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007945 }
7946 }
sqian11b7a0e2018-12-05 18:48:28 -08007947 }
7948 return false;
7949 } finally {
7950 Binder.restoreCallingIdentity(identity);
7951 }
7952 }
7953
sqianf4ca7ed2019-01-15 18:32:07 -08007954 /**
7955 * Update emergency number list for test mode.
7956 */
7957 @Override
7958 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7959 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7960 "updateEmergencyNumberListTestMode");
7961
7962 final long identity = Binder.clearCallingIdentity();
7963 try {
7964 for (Phone phone: PhoneFactory.getPhones()) {
7965 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7966 if (tracker != null) {
7967 tracker.executeEmergencyNumberTestModeCommand(action, num);
7968 }
7969 }
7970 } finally {
7971 Binder.restoreCallingIdentity(identity);
7972 }
7973 }
7974
7975 /**
7976 * Get the full emergency number list for test mode.
7977 */
7978 @Override
7979 public List<String> getEmergencyNumberListTestMode() {
7980 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7981 "getEmergencyNumberListTestMode");
7982
7983 final long identity = Binder.clearCallingIdentity();
7984 try {
7985 Set<String> emergencyNumbers = new HashSet<>();
7986 for (Phone phone: PhoneFactory.getPhones()) {
7987 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7988 if (tracker != null) {
7989 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7990 emergencyNumbers.add(num.getNumber());
7991 }
7992 }
7993 }
7994 return new ArrayList<>(emergencyNumbers);
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
7997 }
7998 }
7999
chen xud6b45bd2018-10-30 22:27:10 -07008000 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008001 public int getEmergencyNumberDbVersion(int subId) {
8002 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8003
8004 final long identity = Binder.clearCallingIdentity();
8005 try {
8006 final Phone phone = getPhone(subId);
8007 if (phone == null) {
8008 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8009 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8010 }
8011 return phone.getEmergencyNumberDbVersion();
8012 } finally {
8013 Binder.restoreCallingIdentity(identity);
8014 }
8015 }
8016
8017 @Override
8018 public void notifyOtaEmergencyNumberDbInstalled() {
8019 enforceModifyPermission();
8020
8021 final long identity = Binder.clearCallingIdentity();
8022 try {
8023 for (Phone phone: PhoneFactory.getPhones()) {
8024 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8025 if (tracker != null) {
8026 tracker.updateOtaEmergencyNumberDatabase();
8027 }
8028 }
8029 } finally {
8030 Binder.restoreCallingIdentity(identity);
8031 }
8032 }
8033
8034 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008035 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008036 enforceActiveEmergencySessionPermission();
8037
8038 final long identity = Binder.clearCallingIdentity();
8039 try {
8040 for (Phone phone: PhoneFactory.getPhones()) {
8041 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8042 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008043 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8044 }
8045 }
8046 } finally {
8047 Binder.restoreCallingIdentity(identity);
8048 }
8049 }
8050
8051 @Override
8052 public void resetOtaEmergencyNumberDbFilePath() {
8053 enforceActiveEmergencySessionPermission();
8054
8055 final long identity = Binder.clearCallingIdentity();
8056 try {
8057 for (Phone phone: PhoneFactory.getPhones()) {
8058 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8059 if (tracker != null) {
8060 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008061 }
8062 }
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
8065 }
8066 }
8067
8068 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008069 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8070 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8071 Phone phone = getPhone(subId);
8072 if (phone == null) {
8073 return null;
8074 }
8075 final long identity = Binder.clearCallingIdentity();
8076 try {
8077 UiccProfile profile = UiccController.getInstance()
8078 .getUiccProfileForPhone(phone.getPhoneId());
8079 if (profile != null) {
8080 return profile.getCertsFromCarrierPrivilegeAccessRules();
8081 }
8082 } finally {
8083 Binder.restoreCallingIdentity(identity);
8084 }
8085 return null;
8086 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008087
8088 /**
8089 * Enable or disable a modem stack.
8090 */
8091 @Override
8092 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8093 enforceModifyPermission();
8094
8095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 Phone phone = PhoneFactory.getPhone(slotIndex);
8098 if (phone == null) {
8099 return false;
8100 } else {
8101 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8102 }
8103 } finally {
8104 Binder.restoreCallingIdentity(identity);
8105 }
8106 }
Michelecea4cf22018-12-21 15:00:11 -08008107
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008108 /**
8109 * Whether a modem stack is enabled or not.
8110 */
8111 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008112 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8113 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008114 Phone phone = PhoneFactory.getPhone(slotIndex);
8115 if (phone == null) return false;
8116
8117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008118 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8119 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008120 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8121 }
8122
8123 final long identity = Binder.clearCallingIdentity();
8124 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008125 try {
8126 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8127 } catch (NoSuchElementException ex) {
8128 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8129 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008130 } finally {
8131 Binder.restoreCallingIdentity(identity);
8132 }
8133 }
8134
Michelecea4cf22018-12-21 15:00:11 -08008135 @Override
Michele0ea7d782019-03-19 14:58:42 -07008136 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008137 enforceModifyPermission();
8138
8139 final long identity = Binder.clearCallingIdentity();
8140 try {
8141 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008142 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008143 .commit();
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
8146 }
8147 }
8148
8149 @Override
Michele0ea7d782019-03-19 14:58:42 -07008150 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008151 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008153 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8154 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008155 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008156 }
Michelecea4cf22018-12-21 15:00:11 -08008157
8158 final long identity = Binder.clearCallingIdentity();
8159 try {
Michele0ea7d782019-03-19 14:58:42 -07008160 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008161 } finally {
8162 Binder.restoreCallingIdentity(identity);
8163 }
8164 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008165
Michele0ea7d782019-03-19 14:58:42 -07008166 @TelephonyManager.IsMultiSimSupportedResult
8167 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008168 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8169 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8170 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008171 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8172 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008173 }
8174 // Check if the hardware supports multisim functionality. If usage of multisim is not
8175 // supported by the modem, indicate that it is restricted.
8176 PhoneCapability staticCapability =
8177 mPhoneConfigurationManager.getStaticPhoneCapability();
8178 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008179 loge("isMultiSimSupportedInternal: no static configuration available");
8180 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008181 }
Sarah Chin7caee492020-02-18 20:49:02 +00008182 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008183 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8184 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008185 }
8186 // Check if support of multiple SIMs is restricted by carrier
8187 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008188 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008189 }
8190
Michele0ea7d782019-03-19 14:58:42 -07008191 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008192 }
8193
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008194 /**
8195 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008196 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8197 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8198 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008199 * @param numOfSims number of active sims we want to switch to
8200 */
8201 @Override
8202 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008203 if (numOfSims == 1) {
8204 enforceModifyPermission();
8205 } else {
8206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8207 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8208 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008209 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008210
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008211 try {
Michele30b57b22019-03-01 12:01:14 -08008212 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008213 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008214 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8215 return;
8216 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008217 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
8220 }
8221 }
8222
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008223 @Override
8224 public boolean isApplicationOnUicc(int subId, int appType) {
8225 enforceReadPrivilegedPermission("isApplicationOnUicc");
8226 Phone phone = getPhone(subId);
8227 if (phone == null) {
8228 return false;
8229 }
8230 final long identity = Binder.clearCallingIdentity();
8231 try {
8232 UiccCard uiccCard = phone.getUiccCard();
8233 if (uiccCard == null) {
8234 return false;
8235 }
8236 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8237 if (uiccProfile == null) {
8238 return false;
8239 }
8240 if (TelephonyManager.APPTYPE_SIM <= appType
8241 && appType <= TelephonyManager.APPTYPE_ISIM) {
8242 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8243 }
8244 return false;
8245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
8248 }
8249
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008250 /**
chen xub4baa772019-04-03 10:23:41 -07008251 * Get whether making changes to modem configurations will trigger reboot.
8252 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008253 */
8254 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008255 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8256 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008257 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008258 mApp, subId, callingPackage, callingFeatureId,
8259 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008260 return false;
8261 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008262 final long identity = Binder.clearCallingIdentity();
8263 try {
8264 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8265 } finally {
8266 Binder.restoreCallingIdentity(identity);
8267 }
8268 }
8269
Nathan Harold29f5f052019-02-15 13:41:57 -08008270 private void updateModemStateMetrics() {
8271 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8272 // TODO: check the state for each modem if the api is ready.
8273 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8274 }
8275
Pengquan Meng3889a572019-01-23 11:16:29 -08008276 @Override
8277 public int[] getSlotsMapping() {
8278 enforceReadPrivilegedPermission("getSlotsMapping");
8279
8280 final long identity = Binder.clearCallingIdentity();
8281 try {
8282 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8283 // All logical slots should have a mapping to a physical slot.
8284 int[] logicalSlotsMapping = new int[phoneCount];
8285 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8286 for (int i = 0; i < slotInfos.length; i++) {
8287 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8288 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8289 }
8290 }
8291 return logicalSlotsMapping;
8292 } finally {
8293 Binder.restoreCallingIdentity(identity);
8294 }
8295 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008296
8297 /**
8298 * Get the IRadio HAL Version
8299 */
8300 @Override
8301 public int getRadioHalVersion() {
8302 Phone phone = getDefaultPhone();
8303 if (phone == null) return -1;
8304 HalVersion hv = phone.getHalVersion();
8305 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8306 return hv.major * 100 + hv.minor;
8307 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008308
8309 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008310 * Get the current calling package name.
8311 * @return the current calling package name
8312 */
8313 @Override
8314 public String getCurrentPackageName() {
8315 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8316 }
8317
8318 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008319 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8320 * corresponding network requests on a subId.
8321 *
8322 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008323 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008324 * 2) APN is un-metered for this subscription, or
8325 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008326 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008327 *
8328 * @return whether data is allowed for a apn type.
8329 *
8330 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008331 */
8332 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008333 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008334 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8335 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008336
8337 // Now that all security checks passes, perform the operation as ourselves.
8338 final long identity = Binder.clearCallingIdentity();
8339 try {
8340 Phone phone = getPhone(subId);
8341 if (phone == null) return false;
8342
Jack Yu41407ee2019-05-13 16:54:09 -07008343 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008344 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8345 } finally {
8346 Binder.restoreCallingIdentity(identity);
8347 }
8348 }
8349
8350 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008351 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008352 enforceReadPrivilegedPermission("isApnMetered");
8353
8354 // Now that all security checks passes, perform the operation as ourselves.
8355 final long identity = Binder.clearCallingIdentity();
8356 try {
8357 Phone phone = getPhone(subId);
8358 if (phone == null) return true; // By default return true.
8359
Jack Yu41407ee2019-05-13 16:54:09 -07008360 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008361 } finally {
8362 Binder.restoreCallingIdentity(identity);
8363 }
8364 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008365
8366 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008367 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8368 int subscriptionId, IBooleanConsumer resultCallback) {
8369 enforceModifyPermission();
8370 long token = Binder.clearCallingIdentity();
8371 try {
8372 Phone phone = getPhone(subscriptionId);
8373 if (phone == null) {
8374 try {
8375 if (resultCallback != null) {
8376 resultCallback.accept(false);
8377 }
8378 } catch (RemoteException e) {
8379 // ignore
8380 }
8381 return;
8382 }
8383 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8384 Pair.create(specifiers, (x) -> {
8385 try {
8386 if (resultCallback != null) {
8387 resultCallback.accept(x);
8388 }
8389 } catch (RemoteException e) {
8390 // ignore
8391 }
8392 });
8393 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8394 } finally {
8395 Binder.restoreCallingIdentity(token);
8396 }
8397 }
8398
8399 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008400 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008401 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008402 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8403 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8404 if (iccRecords == null) {
8405 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8406 return false;
8407 }
8408 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8409 }
8410
8411 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008412 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8413 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008414 if (callingPackage == null) {
8415 callingPackage = getCurrentPackageName();
8416 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008417 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8418 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008419 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8420 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008421 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8422 }
8423 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8424 Intent intent = new Intent();
8425 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8426 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8427 // Bring up choose default SMS subscription dialog right now
8428 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8429 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8430 mApp.startActivity(intent);
8431 }
chen xud5ca2d52019-05-28 15:20:57 -07008432
8433 @Override
8434 public String getMmsUAProfUrl(int subId) {
8435 //TODO investigate if this API should require proper permission check in R b/133791609
8436 final long identity = Binder.clearCallingIdentity();
8437 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008438 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8439 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8440 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8441 return carrierUAProfUrl;
8442 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008443 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8444 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008445 } finally {
8446 Binder.restoreCallingIdentity(identity);
8447 }
8448 }
8449
8450 @Override
8451 public String getMmsUserAgent(int subId) {
8452 //TODO investigate if this API should require proper permission check in R b/133791609
8453 final long identity = Binder.clearCallingIdentity();
8454 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008455 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8456 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8457 if (!TextUtils.isEmpty(carrierUserAgent)) {
8458 return carrierUserAgent;
8459 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008460 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8461 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008462 } finally {
8463 Binder.restoreCallingIdentity(identity);
8464 }
8465 }
Jack Yub07d4972019-05-28 16:12:25 -07008466
8467 @Override
8468 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8469 enforceModifyPermission();
8470
8471 // Now that all security checks passes, perform the operation as ourselves.
8472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 Phone phone = getPhone(subId);
8475 if (phone == null) return false;
8476
8477 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8478 } finally {
8479 Binder.restoreCallingIdentity(identity);
8480 }
8481 }
8482
8483 @Override
8484 public boolean isDataAllowedInVoiceCall(int subId) {
8485 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8486
8487 // Now that all security checks passes, perform the operation as ourselves.
8488 final long identity = Binder.clearCallingIdentity();
8489 try {
8490 Phone phone = getPhone(subId);
8491 if (phone == null) return false;
8492
8493 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8494 } finally {
8495 Binder.restoreCallingIdentity(identity);
8496 }
8497 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008498
changbettyd5c246e2019-12-24 15:40:37 +08008499 @Override
8500 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8501 enforceModifyPermission();
8502
8503 // Now that all security checks passes, perform the operation as ourselves.
8504 final long identity = Binder.clearCallingIdentity();
8505 try {
8506 Phone phone = getPhone(subId);
8507 if (phone == null) return false;
8508
8509 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8510 } finally {
8511 Binder.restoreCallingIdentity(identity);
8512 }
8513 }
8514
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008515 /**
8516 * Updates whether conference event pacakge handling is enabled.
8517 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8518 * otherwise.
8519 */
8520 @Override
8521 public void setCepEnabled(boolean isCepEnabled) {
8522 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8523
8524 final long identity = Binder.clearCallingIdentity();
8525 try {
8526 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8527 for (Phone phone : PhoneFactory.getPhones()) {
8528 Phone defaultPhone = phone.getImsPhone();
8529 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8530 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8531 ImsPhoneCallTracker imsPhoneCallTracker =
8532 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8533 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8534 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8535 + imsPhone.getMsisdn());
8536 }
8537 }
8538 } finally {
8539 Binder.restoreCallingIdentity(identity);
8540 }
8541 }
allenwtsu46dcc572020-01-08 18:24:03 +08008542
8543 /**
8544 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8545 *
8546 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8547 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8548 * before being read.
8549 */
8550 @Override
8551 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8552 isCompressed) {
8553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8554 mApp, subId, "notifyRcsAutoConfigurationReceived");
8555 try {
8556 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8557 if (configBinder == null) {
8558 Rlog.e(LOG_TAG, "null result for getImsConfig");
8559 } else {
8560 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8561 }
8562 } catch (RemoteException e) {
8563 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8564 }
8565 }
zoey chene02881a2019-12-30 16:11:23 +08008566
8567 @Override
8568 public boolean isIccLockEnabled(int subId) {
8569 enforceReadPrivilegedPermission("isIccLockEnabled");
8570
8571 // Now that all security checks passes, perform the operation as ourselves.
8572 final long identity = Binder.clearCallingIdentity();
8573 try {
8574 Phone phone = getPhone(subId);
8575 if (phone != null && phone.getIccCard() != null) {
8576 return phone.getIccCard().getIccLockEnabled();
8577 } else {
8578 return false;
8579 }
8580 } finally {
8581 Binder.restoreCallingIdentity(identity);
8582 }
8583 }
8584
8585 /**
8586 * Set the ICC pin lock enabled or disabled.
8587 *
8588 * @return an integer representing the status of IccLock enabled or disabled in the following
8589 * three cases:
8590 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8591 * successfully.
8592 * - Positive number and zero for remaining password attempts.
8593 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8594 *
8595 */
8596 @Override
8597 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8598 enforceModifyPermission();
8599
8600 Phone phone = getPhone(subId);
8601 if (phone == null) {
8602 return 0;
8603 }
8604 // Now that all security checks passes, perform the operation as ourselves.
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8608 new Pair<Boolean, String>(enabled, password), phone, null);
8609 return attemptsRemaining;
8610
8611 } catch (Exception e) {
8612 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8613 } finally {
8614 Binder.restoreCallingIdentity(identity);
8615 }
8616 return 0;
8617 }
8618
8619 /**
8620 * Change the ICC password used in ICC pin lock.
8621 *
8622 * @return an integer representing the status of IccLock changed in the following three cases:
8623 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8624 * - Positive number and zero for remaining password attempts.
8625 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8626 *
8627 */
8628 @Override
8629 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8630 enforceModifyPermission();
8631
8632 Phone phone = getPhone(subId);
8633 if (phone == null) {
8634 return 0;
8635 }
8636 // Now that all security checks passes, perform the operation as ourselves.
8637 final long identity = Binder.clearCallingIdentity();
8638 try {
8639 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8640 new Pair<String, String>(oldPassword, newPassword), phone, null);
8641 return attemptsRemaining;
8642
8643 } catch (Exception e) {
8644 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8645 } finally {
8646 Binder.restoreCallingIdentity(identity);
8647 }
8648 return 0;
8649 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008650
8651 /**
8652 * Request for receiving user activity notification
8653 */
8654 @Override
8655 public void requestUserActivityNotification() {
8656 if (!mNotifyUserActivity.get()
8657 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8658 mNotifyUserActivity.set(true);
8659 }
8660 }
8661
8662 /**
8663 * Called when userActivity is signalled in the power manager.
8664 * This is safe to call from any thread, with any window manager locks held or not.
8665 */
8666 @Override
8667 public void userActivity() {
8668 // ***************************************
8669 // * Inherited from PhoneWindowManager *
8670 // ***************************************
8671 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8672 // WITH ITS LOCKS HELD.
8673 //
8674 // This code must be VERY careful about the locks
8675 // it acquires.
8676 // In fact, the current code acquires way too many,
8677 // and probably has lurking deadlocks.
8678
8679 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8680 throw new SecurityException("Only the OS may call notifyUserActivity()");
8681 }
8682
8683 if (mNotifyUserActivity.getAndSet(false)) {
8684 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8685 USER_ACTIVITY_NOTIFICATION_DELAY);
8686 }
8687 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008688
8689 @Override
8690 public boolean canConnectTo5GInDsdsMode() {
8691 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008693}