blob: 60efeb1d4f1893951ffac635fbee899ac871cca1 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Jordan Liu102b2772020-03-04 13:59:23 -0800123import com.android.internal.annotations.VisibleForTesting;
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
Derek Tan97ebb422014-09-05 16:55:38 -0700316 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
317 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800318 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800319 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700320
Michelecea4cf22018-12-21 15:00:11 -0800321 // String to store multi SIM allowed
322 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
323
Derek Tan740e1672017-06-27 14:56:27 -0700324 // The AID of ISD-R.
325 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
326
yinxub1bed742017-04-17 11:45:04 -0700327 private NetworkScanRequestTracker mNetworkScanRequestTracker;
328
David Kelly5e06a7f2018-03-12 14:10:59 +0000329 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
330 private static final int MANUFACTURER_CODE_LENGTH = 8;
331
Derek Tan89e89d42014-07-08 17:00:10 -0700332 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700333 * Experiment flag to enable erase modem config on reset network, default value is false
334 */
335 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
336 "reset_network_erase_modem_config_enabled";
337
338 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700339 * A request object to use for transmitting data to an ICC.
340 */
341 private static final class IccAPDUArgument {
342 public int channel, cla, command, p1, p2, p3;
343 public String data;
344
345 public IccAPDUArgument(int channel, int cla, int command,
346 int p1, int p2, int p3, String data) {
347 this.channel = channel;
348 this.cla = cla;
349 this.command = command;
350 this.p1 = p1;
351 this.p2 = p2;
352 this.p3 = p3;
353 this.data = data;
354 }
355 }
356
357 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700358 * A request object to use for transmitting data to an ICC.
359 */
360 private static final class ManualNetworkSelectionArgument {
361 public OperatorInfo operatorInfo;
362 public boolean persistSelection;
363
364 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
365 this.operatorInfo = operatorInfo;
366 this.persistSelection = persistSelection;
367 }
368 }
369
370 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
372 * request after sending. The main thread will notify the request when it is complete.
373 */
374 private static final class MainThreadRequest {
375 /** The argument to use for the request */
376 public Object argument;
377 /** The result of the request that is run on the main thread */
378 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800379 // The subscriber id that this request applies to. Defaults to
380 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
381 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 // In cases where subId is unavailable, the caller needs to specify the phone.
384 public Phone phone;
385
vagdeviaf9a5b92018-08-15 16:01:53 -0700386 public WorkSource workSource;
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 public MainThreadRequest(Object argument) {
389 this.argument = argument;
390 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800391
Nathan Harold92bed182018-10-12 18:16:49 -0700392 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
393 this.argument = argument;
394 if (phone != null) {
395 this.phone = phone;
396 }
397 this.workSource = workSource;
398 }
399
vagdeviaf9a5b92018-08-15 16:01:53 -0700400 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800401 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800402 if (subId != null) {
403 this.subId = subId;
404 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700405 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 }
408
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800409 private static final class IncomingThirdPartyCallArgs {
410 public final ComponentName component;
411 public final String callId;
412 public final String callerDisplayName;
413
414 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
415 String callerDisplayName) {
416 this.component = component;
417 this.callId = callId;
418 this.callerDisplayName = callerDisplayName;
419 }
420 }
421
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 /**
423 * A handler that processes messages on the main thread in the phone process. Since many
424 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
425 * inbound binder threads to the main thread in the phone process. The Binder thread
426 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
427 * on, which will be notified when the operation completes and will contain the result of the
428 * request.
429 *
430 * <p>If a MainThreadRequest object is provided in the msg.obj field,
431 * note that request.result must be set to something non-null for the calling thread to
432 * unblock.
433 */
434 private final class MainThreadHandler extends Handler {
435 @Override
436 public void handleMessage(Message msg) {
437 MainThreadRequest request;
438 Message onCompleted;
439 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800442 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443
444 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 case CMD_HANDLE_USSD_REQUEST: {
446 request = (MainThreadRequest) msg.obj;
447 final Phone phone = getPhoneFromRequest(request);
448 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
449 String ussdRequest = ussdObject.first;
450 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700451
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 if (!isUssdApiAllowed(request.subId)) {
453 // Carrier does not support use of this API, return failure.
454 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
455 UssdResponse response = new UssdResponse(ussdRequest, null);
456 Bundle returnData = new Bundle();
457 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
458 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700459
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 request.result = true;
461 notifyRequester(request);
462 return;
463 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700464
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 try {
466 request.result = phone != null
467 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
468 } catch (CallStateException cse) {
469 request.result = false;
470 }
471 // Wake up the requesting thread
472 notifyRequester(request);
473 break;
pkanwar32d516d2016-10-14 19:37:38 -0700474 }
475
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 final Phone phone = getPhoneFromRequest(request);
479 request.result = phone != null ?
480 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
481 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 if (uiccCard == null) {
492 loge("iccTransmitApduLogicalChannel: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700495 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
497 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700498 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 iccArgument.channel, iccArgument.cla, iccArgument.command,
500 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700502 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 break;
504
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 if (ar.result == null) {
513 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800514 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800516 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 } else {
518 loge("iccTransmitApduLogicalChannel: Unknown exception");
519 }
520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 break;
523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
525 request = (MainThreadRequest) msg.obj;
526 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 if (uiccCard == null) {
529 loge("iccTransmitApduBasicChannel: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 } else {
533 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
534 request);
535 uiccCard.iccTransmitApduBasicChannel(
536 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
537 iccArgument.p3, iccArgument.data, onCompleted);
538 }
539 break;
540
541 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
546 } else {
547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("iccTransmitApduBasicChannel: Empty response");
550 } else if (ar.exception instanceof CommandException) {
551 loge("iccTransmitApduBasicChannel: CommandException: " +
552 ar.exception);
553 } else {
554 loge("iccTransmitApduBasicChannel: Unknown exception");
555 }
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
560 case CMD_EXCHANGE_SIM_IO:
561 request = (MainThreadRequest) msg.obj;
562 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 if (uiccCard == null) {
565 loge("iccExchangeSimIO: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
570 request);
571 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
572 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
573 iccArgument.data, onCompleted);
574 }
575 break;
576
577 case EVENT_EXCHANGE_SIM_IO_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
580 if (ar.exception == null && ar.result != null) {
581 request.result = ar.result;
582 } else {
583 request.result = new IccIoResult(0x6f, 0, (byte[])null);
584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 break;
587
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 case CMD_SEND_ENVELOPE:
589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 if (uiccCard == null) {
592 loge("sendEnvelopeWithStatus: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
597 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
598 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 break;
600
601 case EVENT_SEND_ENVELOPE_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700604 if (ar.exception == null && ar.result != null) {
605 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
608 if (ar.result == null) {
609 loge("sendEnvelopeWithStatus: Empty response");
610 } else if (ar.exception instanceof CommandException) {
611 loge("sendEnvelopeWithStatus: CommandException: " +
612 ar.exception);
613 } else {
614 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
615 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 break;
619
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 case CMD_OPEN_CHANNEL:
621 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800623 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 if (uiccCard == null) {
625 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800626 request.result = new IccOpenLogicalChannelResponse(-1,
627 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800631 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
632 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case EVENT_OPEN_CHANNEL_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 int[] result = (int[]) ar.result;
642 int channelId = result[0];
643 byte[] selectResponse = null;
644 if (result.length > 1) {
645 selectResponse = new byte[result.length - 1];
646 for (int i = 1; i < result.length; ++i) {
647 selectResponse[i - 1] = (byte) result[i];
648 }
649 }
650 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 if (ar.result == null) {
654 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 if (ar.exception != null) {
657 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
658 }
659
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700661 if (ar.exception instanceof CommandException) {
662 CommandException.Error error =
663 ((CommandException) (ar.exception)).getCommandError();
664 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700665 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700666 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 }
669 }
670 openChannelResp = new IccOpenLogicalChannelResponse(
671 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700673 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
677 case CMD_CLOSE_CHANNEL:
678 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800679 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 if (uiccCard == null) {
681 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900682 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
686 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 break;
689
690 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800691 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
692 break;
693
694 case CMD_NV_READ_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800707 request.result = "";
708 if (ar.result == null) {
709 loge("nvReadItem: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("nvReadItem: CommandException: " +
712 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800714 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
Jake Hambye994d462014-02-03 13:10:13 -0800720 case CMD_NV_WRITE_ITEM:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
723 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800724 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700725 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_WRITE_ITEM_DONE:
729 handleNullReturnEvent(msg, "nvWriteItem");
730 break;
731
732 case CMD_NV_WRITE_CDMA_PRL:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
738 case EVENT_NV_WRITE_CDMA_PRL_DONE:
739 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
740 break;
741
chen xu6dac5ab2018-10-26 17:39:23 -0700742 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800743 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700744 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800745 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800746 break;
747
chen xu6dac5ab2018-10-26 17:39:23 -0700748 case EVENT_RESET_MODEM_CONFIG_DONE:
749 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800750 break;
751
Jake Hamby7c27be32014-03-03 13:25:59 -0800752 case CMD_GET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
761 if (ar.exception == null && ar.result != null) {
762 request.result = ar.result; // Integer
763 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800764 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800765 if (ar.result == null) {
766 loge("getPreferredNetworkType: Empty response");
767 } else if (ar.exception instanceof CommandException) {
768 loge("getPreferredNetworkType: CommandException: " +
769 ar.exception);
770 } else {
771 loge("getPreferredNetworkType: Unknown exception");
772 }
773 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800775 break;
776
777 case CMD_SET_PREFERRED_NETWORK_TYPE:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
780 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700781 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800782 break;
783
784 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
785 handleNullReturnEvent(msg, "setPreferredNetworkType");
786 break;
787
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000788 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
789 request = (MainThreadRequest)msg.obj;
790 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 break;
793
794 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
795 ar = (AsyncResult)msg.obj;
796 request = (MainThreadRequest)ar.userObj;
797 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700798 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000799 break;
800
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800801 case CMD_SET_VOICEMAIL_NUMBER:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
804 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800805 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
806 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800807 break;
808
809 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
810 handleNullReturnEvent(msg, "setVoicemailNumber");
811 break;
812
Stuart Scott54788802015-03-30 13:18:01 -0700813 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
816 request);
817 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
818 break;
819
820 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
821 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
822 break;
823
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 case CMD_PERFORM_NETWORK_SCAN:
825 request = (MainThreadRequest) msg.obj;
826 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
827 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
828 break;
829
Shuo Qian4a594052020-01-23 11:59:30 -0800830 case CMD_GET_CALL_FORWARDING:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
833 int callForwardingReason = (Integer) request.argument;
834 getPhoneFromRequest(request).getCallForwardingOption(
835 callForwardingReason, onCompleted);
836 break;
837
838 case EVENT_GET_CALL_FORWARDING_DONE:
839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 CallForwardingInfo callForwardingInfo = null;
842 if (ar.exception == null && ar.result != null) {
843 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
844 for (CallForwardInfo callForwardInfo : callForwardInfos) {
845 // Service Class is a bit mask per 3gpp 27.007. Search for
846 // any service for voice call.
847 if ((callForwardInfo.serviceClass
848 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
849 callForwardingInfo = new CallForwardingInfo(
850 callForwardInfo.serviceClass, callForwardInfo.reason,
851 callForwardInfo.number,
852 callForwardInfo.timeSeconds);
853 break;
854 }
855 }
856 // Didn't find a call forward info for voice call.
857 if (callForwardingInfo == null) {
858 callForwardingInfo = new CallForwardingInfo(
859 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
860 0 /* reason */, null /* number */, 0 /* timeout */);
861 }
862 } else {
863 if (ar.result == null) {
864 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
865 }
866 if (ar.exception != null) {
867 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
868 }
869 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
870 if (ar.exception instanceof CommandException) {
871 CommandException.Error error =
872 ((CommandException) (ar.exception)).getCommandError();
873 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
874 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
875 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
876 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
877 }
878 }
879 callForwardingInfo = new CallForwardingInfo(
880 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
881 }
882 request.result = callForwardingInfo;
883 notifyRequester(request);
884 break;
885
886 case CMD_SET_CALL_FORWARDING:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
889 CallForwardingInfo callForwardingInfoToSet =
890 (CallForwardingInfo) request.argument;
891 getPhoneFromRequest(request).setCallForwardingOption(
892 callForwardingInfoToSet.getStatus(),
893 callForwardingInfoToSet.getReason(),
894 callForwardingInfoToSet.getNumber(),
895 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
896 break;
897
898 case EVENT_SET_CALL_FORWARDING_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null) {
902 request.result = true;
903 } else {
904 request.result = false;
905 loge("setCallForwarding exception: " + ar.exception);
906 }
907 notifyRequester(request);
908 break;
909
910 case CMD_GET_CALL_WAITING:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
913 getPhoneFromRequest(request).getCallWaiting(onCompleted);
914 break;
915
916 case EVENT_GET_CALL_WAITING_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
920 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800921 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800922 // Service Class is a bit mask per 3gpp 27.007.
923 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800924 if (callForwardResults.length > 1
925 && ((callForwardResults[1]
926 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
927 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800928 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
929 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
930 } else {
931 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
932 }
933 } else {
934 if (ar.result == null) {
935 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
936 }
937 if (ar.exception != null) {
938 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
939 }
940 if (ar.exception instanceof CommandException) {
941 CommandException.Error error =
942 ((CommandException) (ar.exception)).getCommandError();
943 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
944 callForwardingStatus =
945 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
946 }
947 }
948 }
949 request.result = callForwardingStatus;
950 notifyRequester(request);
951 break;
952
953 case CMD_SET_CALL_WAITING:
954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
956 boolean isEnable = (Boolean) request.argument;
957 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
958 break;
959
960 case EVENT_SET_CALL_WAITING_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 if (ar.exception == null) {
964 request.result = true;
965 } else {
966 request.result = false;
967 loge("setCallWaiting exception: " + ar.exception);
968 }
969 notifyRequester(request);
970 break;
971
Shishir Agrawal302c8692015-06-19 13:49:39 -0700972 case EVENT_PERFORM_NETWORK_SCAN_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 CellNetworkScanResult cellScanResult;
976 if (ar.exception == null && ar.result != null) {
977 cellScanResult = new CellNetworkScanResult(
978 CellNetworkScanResult.STATUS_SUCCESS,
979 (List<OperatorInfo>) ar.result);
980 } else {
981 if (ar.result == null) {
982 loge("getCellNetworkScanResults: Empty response");
983 }
984 if (ar.exception != null) {
985 loge("getCellNetworkScanResults: Exception: " + ar.exception);
986 }
987 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
988 if (ar.exception instanceof CommandException) {
989 CommandException.Error error =
990 ((CommandException) (ar.exception)).getCommandError();
991 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
992 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
993 } else if (error == CommandException.Error.GENERIC_FAILURE) {
994 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
995 }
996 }
997 cellScanResult = new CellNetworkScanResult(errorCode, null);
998 }
999 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001001 break;
1002
1003 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1004 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001005 ManualNetworkSelectionArgument selArg =
1006 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001007 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1008 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001009 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1010 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001011 break;
1012
1013 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception == null) {
1017 request.result = true;
1018 } else {
1019 request.result = false;
1020 loge("setNetworkSelectionModeManual " + ar.exception);
1021 }
1022 notifyRequester(request);
1023 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001024 break;
1025
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001026 case CMD_GET_MODEM_ACTIVITY_INFO:
1027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001029 if (defaultPhone != null) {
1030 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001031 } else {
1032 ResultReceiver result = (ResultReceiver) request.argument;
1033 Bundle bundle = new Bundle();
1034 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1035 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1036 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001037 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001038 break;
1039
1040 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001043 ResultReceiver result = (ResultReceiver) request.argument;
1044
1045 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001046 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001047 // Update the last modem activity info and the result of the request.
1048 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1049 if (isModemActivityInfoValid(info)) {
1050 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1051 int[] txTimeMs = info.getTransmitTimeMillis();
1052 int[] lastModemTxTimeMs = mLastModemActivityInfo
1053 .getTransmitTimeMillis();
1054 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1055 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1056 }
1057 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1058 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1059 + mLastModemActivityInfo.getSleepTimeMillis());
1060 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1061 + mLastModemActivityInfo.getIdleTimeMillis());
1062 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1063 mLastModemActivityInfo.setReceiveTimeMillis(
1064 info.getReceiveTimeMillis()
1065 + mLastModemActivityInfo.getReceiveTimeMillis());
1066 }
1067 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1068 mLastModemActivityInfo.getSleepTimeMillis(),
1069 mLastModemActivityInfo.getIdleTimeMillis(),
1070 mLastModemActivityInfo.getTransmitTimeMillis(),
1071 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001072 } else {
1073 if (ar.result == null) {
1074 loge("queryModemActivityInfo: Empty response");
1075 } else if (ar.exception instanceof CommandException) {
1076 loge("queryModemActivityInfo: CommandException: " +
1077 ar.exception);
1078 } else {
1079 loge("queryModemActivityInfo: Unknown exception");
1080 }
1081 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001082 Bundle bundle = new Bundle();
1083 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1084 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001085 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001086 break;
1087
Meng Wang1a7c35a2016-05-05 20:56:15 -07001088 case CMD_SET_ALLOWED_CARRIERS:
1089 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001090 CarrierRestrictionRules argument =
1091 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001092 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001093 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001094 break;
1095
1096 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null && ar.result != null) {
1100 request.result = ar.result;
1101 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001102 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1103 if (ar.exception instanceof CommandException) {
1104 loge("setAllowedCarriers: CommandException: " + ar.exception);
1105 CommandException.Error error =
1106 ((CommandException) (ar.exception)).getCommandError();
1107 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1108 request.result =
1109 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1110 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001111 } else {
1112 loge("setAllowedCarriers: Unknown exception");
1113 }
1114 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001115 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001116 break;
1117
1118 case CMD_GET_ALLOWED_CARRIERS:
1119 request = (MainThreadRequest) msg.obj;
1120 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001121 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001122 break;
1123
1124 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1125 ar = (AsyncResult) msg.obj;
1126 request = (MainThreadRequest) ar.userObj;
1127 if (ar.exception == null && ar.result != null) {
1128 request.result = ar.result;
1129 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001130 request.result = new IllegalStateException(
1131 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001132 if (ar.result == null) {
1133 loge("getAllowedCarriers: Empty response");
1134 } else if (ar.exception instanceof CommandException) {
1135 loge("getAllowedCarriers: CommandException: " +
1136 ar.exception);
1137 } else {
1138 loge("getAllowedCarriers: Unknown exception");
1139 }
1140 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001141 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001142 break;
1143
Nathan Haroldb3014052017-01-25 15:57:32 -08001144 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result;
1149 } else {
1150 request.result = new IllegalArgumentException(
1151 "Failed to retrieve Forbidden Plmns");
1152 if (ar.result == null) {
1153 loge("getForbiddenPlmns: Empty response");
1154 } else {
1155 loge("getForbiddenPlmns: Unknown exception");
1156 }
1157 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001158 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001159 break;
1160
1161 case CMD_GET_FORBIDDEN_PLMNS:
1162 request = (MainThreadRequest) msg.obj;
1163 uiccCard = getUiccCardFromRequest(request);
1164 if (uiccCard == null) {
1165 loge("getForbiddenPlmns() UiccCard is null");
1166 request.result = new IllegalArgumentException(
1167 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001169 break;
1170 }
1171 Integer appType = (Integer) request.argument;
1172 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1173 if (uiccApp == null) {
1174 loge("getForbiddenPlmns() no app with specified type -- "
1175 + appType);
1176 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001177 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001178 break;
1179 } else {
1180 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1181 + " specified type -- " + appType);
1182 }
1183 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1184 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1185 onCompleted);
1186 break;
1187
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001188 case CMD_SWITCH_SLOTS:
1189 request = (MainThreadRequest) msg.obj;
1190 int[] physicalSlots = (int[]) request.argument;
1191 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1192 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1193 break;
1194
1195 case EVENT_SWITCH_SLOTS_DONE:
1196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
1198 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001199 notifyRequester(request);
1200 break;
1201 case CMD_GET_NETWORK_SELECTION_MODE:
1202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1204 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1205 break;
1206
1207 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 if (ar.exception != null) {
1211 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1212 } else {
1213 int mode = ((int[]) ar.result)[0];
1214 if (mode == 0) {
1215 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1216 } else {
1217 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1218 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001219 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001220 notifyRequester(request);
1221 break;
1222 case CMD_GET_CDMA_ROAMING_MODE:
1223 request = (MainThreadRequest) msg.obj;
1224 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1225 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1226 break;
1227 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1228 ar = (AsyncResult) msg.obj;
1229 request = (MainThreadRequest) ar.userObj;
1230 if (ar.exception != null) {
1231 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1232 } else {
1233 request.result = ((int[]) ar.result)[0];
1234 }
1235 notifyRequester(request);
1236 break;
1237 case CMD_SET_CDMA_ROAMING_MODE:
1238 request = (MainThreadRequest) msg.obj;
1239 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1240 int mode = (int) request.argument;
1241 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1242 break;
1243 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1244 ar = (AsyncResult) msg.obj;
1245 request = (MainThreadRequest) ar.userObj;
1246 request.result = ar.exception == null;
1247 notifyRequester(request);
1248 break;
1249 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1252 int subscriptionMode = (int) request.argument;
1253 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1254 break;
1255 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1256 ar = (AsyncResult) msg.obj;
1257 request = (MainThreadRequest) ar.userObj;
1258 request.result = ar.exception == null;
1259 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001260 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001261 case CMD_GET_ALL_CELL_INFO:
1262 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001263 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001264 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 case EVENT_GET_ALL_CELL_INFO_DONE:
1267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001269 // If a timeout occurs, the response will be null
1270 request.result = (ar.exception == null && ar.result != null)
1271 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001272 synchronized (request) {
1273 request.notifyAll();
1274 }
1275 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001276 case CMD_REQUEST_CELL_INFO_UPDATE:
1277 request = (MainThreadRequest) msg.obj;
1278 request.phone.requestCellInfoUpdate(request.workSource,
1279 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1280 break;
1281 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1285 try {
1286 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001287 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001288 cb.onError(
1289 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1290 ar.exception.getClass().getName(),
1291 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001294 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001295 } else {
1296 // use the result as returned
1297 cb.onCellInfo((List<CellInfo>) ar.result);
1298 }
1299 } catch (RemoteException re) {
1300 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1301 }
1302 break;
1303 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001304 request = (MainThreadRequest) msg.obj;
1305 WorkSource ws = (WorkSource) request.argument;
1306 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001307 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001308 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001309 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
1312 if (ar.exception == null) {
1313 request.result = ar.result;
1314 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001315 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001316 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001317 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001318 }
1319
1320 synchronized (request) {
1321 request.notifyAll();
1322 }
1323 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001324 case CMD_MODEM_REBOOT:
1325 request = (MainThreadRequest) msg.obj;
1326 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001327 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001328 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001329 case EVENT_CMD_MODEM_REBOOT_DONE:
1330 handleNullReturnEvent(msg, "rebootModem");
1331 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001332 case CMD_REQUEST_ENABLE_MODEM:
1333 request = (MainThreadRequest) msg.obj;
1334 boolean enable = (boolean) request.argument;
1335 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001336 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001337 PhoneConfigurationManager.getInstance()
1338 .enablePhone(request.phone, enable, onCompleted);
1339 break;
1340 case EVENT_ENABLE_MODEM_DONE:
1341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
1343 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001344 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001345 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001346 if ((boolean) request.result) {
1347 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1348 updateModemStateMetrics();
1349 } else {
1350 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1351 + ar.exception);
1352 }
1353 notifyRequester(request);
1354 break;
1355 case CMD_GET_MODEM_STATUS:
1356 request = (MainThreadRequest) msg.obj;
1357 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1358 PhoneConfigurationManager.getInstance()
1359 .getPhoneStatusFromModem(request.phone, onCompleted);
1360 break;
1361 case EVENT_GET_MODEM_STATUS_DONE:
1362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
1364 int id = request.phone.getPhoneId();
1365 if (ar.exception == null && ar.result != null) {
1366 request.result = ar.result;
1367 //update the cache as modem status has changed
1368 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1369 (boolean) request.result);
1370 } else {
1371 // Return true if modem status cannot be retrieved. For most cases,
1372 // modem status is on. And for older version modems, GET_MODEM_STATUS
1373 // and disable modem are not supported. Modem is always on.
1374 // TODO: this should be fixed in R to support a third
1375 // status UNKNOWN b/131631629
1376 request.result = true;
1377 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1378 + ar.exception);
1379 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001380 notifyRequester(request);
1381 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001382 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1383 request = (MainThreadRequest) msg.obj;
1384 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1385 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1386 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1387 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1388 break;
1389 }
1390 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1391 ar = (AsyncResult) msg.obj;
1392 request = (MainThreadRequest) ar.userObj;
1393 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1394 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1395 args.second.accept(ar.exception == null);
1396 notifyRequester(request);
1397 break;
1398 }
yincheng zhao2737e882019-09-06 17:06:54 -07001399 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null && ar.result != null) {
1403 request.result = ar.result;
1404 } else {
1405 request.result = -1;
1406 loge("Failed to set Forbidden Plmns");
1407 if (ar.result == null) {
1408 loge("setForbidenPlmns: Empty response");
1409 } else if (ar.exception != null) {
1410 loge("setForbiddenPlmns: Exception: " + ar.exception);
1411 request.result = -1;
1412 } else {
1413 loge("setForbiddenPlmns: Unknown exception");
1414 }
1415 }
1416 notifyRequester(request);
1417 break;
1418 case CMD_SET_FORBIDDEN_PLMNS:
1419 request = (MainThreadRequest) msg.obj;
1420 uiccCard = getUiccCardFromRequest(request);
1421 if (uiccCard == null) {
1422 loge("setForbiddenPlmns: UiccCard is null");
1423 request.result = -1;
1424 notifyRequester(request);
1425 break;
1426 }
1427 Pair<Integer, List<String>> setFplmnsArgs =
1428 (Pair<Integer, List<String>>) request.argument;
1429 appType = setFplmnsArgs.first;
1430 List<String> fplmns = setFplmnsArgs.second;
1431 uiccApp = uiccCard.getApplicationByType(appType);
1432 if (uiccApp == null) {
1433 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1434 request.result = -1;
1435 loge("Failed to get UICC App");
1436 notifyRequester(request);
1437 } else {
1438 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1439 ((SIMRecords) uiccApp.getIccRecords())
1440 .setForbiddenPlmns(onCompleted, fplmns);
1441 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001442 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001443 case CMD_ERASE_MODEM_CONFIG:
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1446 defaultPhone.eraseModemConfig(onCompleted);
1447 break;
1448 case EVENT_ERASE_MODEM_CONFIG_DONE:
1449 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001450 break;
zoey chene02881a2019-12-30 16:11:23 +08001451
1452 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1453 request = (MainThreadRequest) msg.obj;
1454 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1455 Pair<String, String> changed = (Pair<String, String>) request.argument;
1456 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1457 changed.first, changed.second, onCompleted);
1458 break;
1459 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 if (ar.exception == null) {
1463 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1464 } else {
1465 request.result = msg.arg1;
1466 }
1467 notifyRequester(request);
1468 break;
1469
1470 case CMD_SET_ICC_LOCK_ENABLED:
1471 request = (MainThreadRequest) msg.obj;
1472 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1473 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1474 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1475 enabled.first, enabled.second, onCompleted);
1476 break;
1477 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 if (ar.exception == null) {
1481 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1482 } else {
1483 request.result = msg.arg1;
1484 }
1485 notifyRequester(request);
1486 break;
1487
Peter Wangdafb9ac2020-01-15 14:13:38 -08001488 case MSG_NOTIFY_USER_ACTIVITY:
1489 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001490 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001491 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1492 getDefaultPhone().getContext().sendBroadcastAsUser(
1493 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1494 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 default:
1496 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1497 break;
1498 }
1499 }
Jake Hambye994d462014-02-03 13:10:13 -08001500
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 private void notifyRequester(MainThreadRequest request) {
1502 synchronized (request) {
1503 request.notifyAll();
1504 }
1505 }
1506
Jake Hambye994d462014-02-03 13:10:13 -08001507 private void handleNullReturnEvent(Message msg, String command) {
1508 AsyncResult ar = (AsyncResult) msg.obj;
1509 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null) {
1511 request.result = true;
1512 } else {
1513 request.result = false;
1514 if (ar.exception instanceof CommandException) {
1515 loge(command + ": CommandException: " + ar.exception);
1516 } else {
1517 loge(command + ": Unknown exception");
1518 }
1519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001520 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 }
1523
1524 /**
1525 * Posts the specified command to be executed on the main thread,
1526 * waits for the request to complete, and returns the result.
1527 * @see #sendRequestAsync
1528 */
1529 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001530 return sendRequest(
1531 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001532 }
1533
1534 /**
1535 * Posts the specified command to be executed on the main thread,
1536 * waits for the request to complete, and returns the result.
1537 * @see #sendRequestAsync
1538 */
1539 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1540 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001541 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
1544 /**
1545 * Posts the specified command to be executed on the main thread,
1546 * waits for the request to complete, and returns the result.
1547 * @see #sendRequestAsync
1548 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001549 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001550 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001551 }
1552
1553 /**
1554 * Posts the specified command to be executed on the main thread,
1555 * waits for the request to complete, and returns the result.
1556 * @see #sendRequestAsync
1557 */
Nathan Harold92bed182018-10-12 18:16:49 -07001558 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1559 return sendRequest(command, argument, subId, null, workSource);
1560 }
1561
1562 /**
1563 * Posts the specified command to be executed on the main thread,
1564 * waits for the request to complete, and returns the result.
1565 * @see #sendRequestAsync
1566 */
1567 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1568 return sendRequest(
1569 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1570 }
1571
1572 /**
1573 * Posts the specified command to be executed on the main thread,
1574 * waits for the request to complete, and returns the result.
1575 * @see #sendRequestAsync
1576 */
1577 private Object sendRequest(
1578 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1580 throw new RuntimeException("This method will deadlock if called from the main thread.");
1581 }
1582
Nathan Harold92bed182018-10-12 18:16:49 -07001583 MainThreadRequest request = null;
1584 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1585 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1586 } else if (phone != null) {
1587 request = new MainThreadRequest(argument, phone, workSource);
1588 } else {
1589 request = new MainThreadRequest(argument, subId, workSource);
1590 }
1591
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 Message msg = mMainThreadHandler.obtainMessage(command, request);
1593 msg.sendToTarget();
1594
1595 // Wait for the request to complete
1596 synchronized (request) {
1597 while (request.result == null) {
1598 try {
1599 request.wait();
1600 } catch (InterruptedException e) {
1601 // Do nothing, go back and wait until the request is complete
1602 }
1603 }
1604 }
1605 return request.result;
1606 }
1607
1608 /**
1609 * Asynchronous ("fire and forget") version of sendRequest():
1610 * Posts the specified command to be executed on the main thread, and
1611 * returns immediately.
1612 * @see #sendRequest
1613 */
1614 private void sendRequestAsync(int command) {
1615 mMainThreadHandler.sendEmptyMessage(command);
1616 }
1617
1618 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001619 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001620 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001621 */
1622 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001623 sendRequestAsync(command, argument, null, null);
1624 }
1625
1626 /**
1627 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1628 * @see {@link #sendRequest(int,Object)}
1629 */
1630 private void sendRequestAsync(
1631 int command, Object argument, Phone phone, WorkSource workSource) {
1632 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001633 Message msg = mMainThreadHandler.obtainMessage(command, request);
1634 msg.sendToTarget();
1635 }
1636
1637 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 * Initialize the singleton PhoneInterfaceManager instance.
1639 * This is only done once, at startup, from PhoneApp.onCreate().
1640 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001641 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 synchronized (PhoneInterfaceManager.class) {
1643 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001644 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 } else {
1646 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1647 }
1648 return sInstance;
1649 }
1650 }
1651
1652 /** Private constructor; @see init() */
Jordan Liu102b2772020-03-04 13:59:23 -08001653 @VisibleForTesting
1654 /* package */ PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001657 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001658 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1660 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001661 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001662 mTelephonySharedPreferences =
1663 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001664 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001665 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001666 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001667
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 publish();
1669 }
1670
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001671 private Phone getDefaultPhone() {
1672 Phone thePhone = getPhone(getDefaultSubscription());
1673 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1674 }
1675
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 private void publish() {
1677 if (DBG) log("publish: " + this);
1678
Peter Wangc035ce42020-01-08 21:00:22 -08001679 TelephonyFrameworkInitializer
1680 .getTelephonyServiceManager()
1681 .getTelephonyServiceRegisterer()
1682 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 }
1684
Stuart Scott584921c2015-01-15 17:10:34 -08001685 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001686 if (request.phone != null) {
1687 return request.phone;
1688 } else {
1689 return getPhoneFromSubId(request.subId);
1690 }
1691 }
1692
1693 private Phone getPhoneFromSubId(int subId) {
1694 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1695 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001696 }
1697
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001698 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1699 Phone phone = getPhoneFromRequest(request);
1700 return phone == null ? null :
1701 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1702 }
1703
Wink Saville36469e72014-06-11 15:17:00 -07001704 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001705 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001706 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708
Naina Nallurid63128d2019-09-17 14:10:30 -07001709 private void sendEraseModemConfig(Phone phone) {
1710 if (phone != null) {
1711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1712 mApp, phone.getSubId(), "eraseModemConfig");
1713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1716 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
1719 }
1720 }
1721 }
1722
Peter Wang44b186e2020-01-13 23:33:09 -08001723 private boolean isImsAvailableOnDevice() {
1724 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1725 if (pm == null) {
1726 // For some reason package manger is not available.. This will fail internally anyway,
1727 // so do not throw error and allow.
1728 return true;
1729 }
1730 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1731 }
1732
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001734 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001735 }
1736
Wink Savilleb564aae2014-10-23 10:18:09 -07001737 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 if (DBG) log("dial: " + number);
1739 // No permission check needed here: This is just a wrapper around the
1740 // ACTION_DIAL intent, which is available to any app since it puts up
1741 // the UI before it does anything.
1742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 String url = createTelUrl(number);
1746 if (url == null) {
1747 return;
1748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750 // PENDING: should we just silently fail if phone is offhook or ringing?
1751 PhoneConstants.State state = mCM.getState(subId);
1752 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1753 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1754 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1755 mApp.startActivity(intent);
1756 }
1757 } finally {
1758 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 }
1760 }
1761
1762 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001763 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001764 }
1765
Wink Savilleb564aae2014-10-23 10:18:09 -07001766 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 if (DBG) log("call: " + number);
1768
1769 // This is just a wrapper around the ACTION_CALL intent, but we still
1770 // need to do a permission check since we're calling startActivity()
1771 // from the context of the phone app.
1772 enforceCallPermission();
1773
Jordan Liu1617b712019-07-10 15:06:26 -07001774 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 != AppOpsManager.MODE_ALLOWED) {
1776 return;
1777 }
1778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779 final long identity = Binder.clearCallingIdentity();
1780 try {
1781 String url = createTelUrl(number);
1782 if (url == null) {
1783 return;
1784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 boolean isValid = false;
1787 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1788 if (slist != null) {
1789 for (SubscriptionInfo subInfoRecord : slist) {
1790 if (subInfoRecord.getSubscriptionId() == subId) {
1791 isValid = true;
1792 break;
1793 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001794 }
Wink Saville08874612014-08-31 19:19:58 -07001795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796 if (!isValid) {
1797 return;
1798 }
Wink Saville08874612014-08-31 19:19:58 -07001799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1801 intent.putExtra(SUBSCRIPTION_KEY, subId);
1802 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1803 mApp.startActivity(intent);
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
1806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
1808
Wink Savilleb564aae2014-10-23 10:18:09 -07001809 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001810 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001811 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1812 }
1813
Wink Savilleb564aae2014-10-23 10:18:09 -07001814 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001815 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001816 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1817 }
1818
Wink Savilleb564aae2014-10-23 10:18:09 -07001819 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001821
1822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1825 checkSimPin.start();
1826 return checkSimPin.unlockSim(null, pin);
1827 } finally {
1828 Binder.restoreCallingIdentity(identity);
1829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
1831
Wink Savilleb564aae2014-10-23 10:18:09 -07001832 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1838 checkSimPuk.start();
1839 return checkSimPuk.unlockSim(puk, pin);
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
1842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 }
1844
1845 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001846 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 * a synchronous one.
1848 */
1849 private static class UnlockSim extends Thread {
1850
1851 private final IccCard mSimCard;
1852
1853 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001854 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1855 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856
1857 // For replies from SimCard interface
1858 private Handler mHandler;
1859
1860 // For async handler to identify request type
1861 private static final int SUPPLY_PIN_COMPLETE = 100;
1862
1863 public UnlockSim(IccCard simCard) {
1864 mSimCard = simCard;
1865 }
1866
1867 @Override
1868 public void run() {
1869 Looper.prepare();
1870 synchronized (UnlockSim.this) {
1871 mHandler = new Handler() {
1872 @Override
1873 public void handleMessage(Message msg) {
1874 AsyncResult ar = (AsyncResult) msg.obj;
1875 switch (msg.what) {
1876 case SUPPLY_PIN_COMPLETE:
1877 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1878 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001879 mRetryCount = msg.arg1;
1880 if (ar.exception != null) {
1881 if (ar.exception instanceof CommandException &&
1882 ((CommandException)(ar.exception)).getCommandError()
1883 == CommandException.Error.PASSWORD_INCORRECT) {
1884 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1885 } else {
1886 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1887 }
1888 } else {
1889 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 mDone = true;
1892 UnlockSim.this.notifyAll();
1893 }
1894 break;
1895 }
1896 }
1897 };
1898 UnlockSim.this.notifyAll();
1899 }
1900 Looper.loop();
1901 }
1902
1903 /*
1904 * Use PIN or PUK to unlock SIM card
1905 *
1906 * If PUK is null, unlock SIM card with PIN
1907 *
1908 * If PUK is not null, unlock SIM card with PUK and set PIN code
1909 */
Wink Saville9de0f752013-10-22 19:04:03 -07001910 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911
1912 while (mHandler == null) {
1913 try {
1914 wait();
1915 } catch (InterruptedException e) {
1916 Thread.currentThread().interrupt();
1917 }
1918 }
1919 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1920
1921 if (puk == null) {
1922 mSimCard.supplyPin(pin, callback);
1923 } else {
1924 mSimCard.supplyPuk(puk, pin, callback);
1925 }
1926
1927 while (!mDone) {
1928 try {
1929 Log.d(LOG_TAG, "wait for done");
1930 wait();
1931 } catch (InterruptedException e) {
1932 // Restore the interrupted status
1933 Thread.currentThread().interrupt();
1934 }
1935 }
1936 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001937 int[] resultArray = new int[2];
1938 resultArray[0] = mResult;
1939 resultArray[1] = mRetryCount;
1940 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942 }
1943
1944 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001945 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001946
1947 }
1948
Wink Savilleb564aae2014-10-23 10:18:09 -07001949 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 // No permission check needed here: this call is harmless, and it's
1951 // needed for the ServiceState.requestStateUpdate() call (which is
1952 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001953 final long identity = Binder.clearCallingIdentity();
1954 try {
1955 final Phone phone = getPhone(subId);
1956 if (phone != null) {
1957 phone.updateServiceLocation();
1958 }
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001964 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001965 @Override
1966 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001967 return isRadioOnWithFeature(callingPackage, null);
1968 }
1969
1970
1971 @Override
1972 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1973 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1974 callingFeatureId);
1975 }
1976
1977 @Deprecated
1978 @Override
1979 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1980 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001981 }
1982
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001984 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1985 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001987 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001988 return false;
1989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990
1991 final long identity = Binder.clearCallingIdentity();
1992 try {
1993 return isRadioOnForSubscriber(subId);
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
1996 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001997 }
1998
1999 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 final Phone phone = getPhone(subId);
2003 if (phone != null) {
2004 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2005 } else {
2006 return false;
2007 }
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
2012
2013 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002014 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 }
Wink Saville36469e72014-06-11 15:17:00 -07002016
Wink Savilleb564aae2014-10-23 10:18:09 -07002017 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002019
2020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 final Phone phone = getPhone(subId);
2023 if (phone != null) {
2024 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2025 }
2026 } finally {
2027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002028 }
Wink Saville36469e72014-06-11 15:17:00 -07002029 }
2030
2031 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002032 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002033 }
2034
Wink Savilleb564aae2014-10-23 10:18:09 -07002035 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002036 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037
2038 final long identity = Binder.clearCallingIdentity();
2039 try {
2040 final Phone phone = getPhone(subId);
2041 if (phone == null) {
2042 return false;
2043 }
2044 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2045 toggleRadioOnOffForSubscriber(subId);
2046 }
2047 return true;
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 }
Wink Saville36469e72014-06-11 15:17:00 -07002052
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002053 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002054 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002055 /*
2056 * If any of the Radios are available, it will need to be
2057 * shutdown. So return true if any Radio is available.
2058 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059 final long identity = Binder.clearCallingIdentity();
2060 try {
2061 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2062 Phone phone = PhoneFactory.getPhone(i);
2063 if (phone != null && phone.isRadioAvailable()) return true;
2064 }
2065 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2066 return false;
2067 } finally {
2068 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002069 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002070 }
2071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002073 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074 enforceModifyPermission();
2075
2076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2079 logv("Shutting down Phone " + i);
2080 shutdownRadioUsingPhoneId(i);
2081 }
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002084 }
2085 }
2086
2087 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002088 Phone phone = PhoneFactory.getPhone(phoneId);
2089 if (phone != null && phone.isRadioAvailable()) {
2090 phone.shutdownRadio();
2091 }
2092 }
2093
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002095 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002096
2097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2100 if (defaultPhone != null) {
2101 defaultPhone.setRadioPower(turnOn);
2102 return true;
2103 } else {
2104 loge("There's no default phone.");
2105 return false;
2106 }
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002109 }
Wink Saville36469e72014-06-11 15:17:00 -07002110 }
2111
Wink Savilleb564aae2014-10-23 10:18:09 -07002112 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002114
2115 final long identity = Binder.clearCallingIdentity();
2116 try {
2117 final Phone phone = getPhone(subId);
2118 if (phone != null) {
2119 phone.setRadioPower(turnOn);
2120 return true;
2121 } else {
2122 return false;
2123 }
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
Wink Saville36469e72014-06-11 15:17:00 -07002129 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002130 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 public boolean enableDataConnectivity() {
2132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 int subId = mSubscriptionController.getDefaultDataSubId();
2137 final Phone phone = getPhone(subId);
2138 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002139 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002140 return true;
2141 } else {
2142 return false;
2143 }
2144 } finally {
2145 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 }
2148
Wink Saville36469e72014-06-11 15:17:00 -07002149 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002150 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 public boolean disableDataConnectivity() {
2152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002153
2154 final long identity = Binder.clearCallingIdentity();
2155 try {
2156 int subId = mSubscriptionController.getDefaultDataSubId();
2157 final Phone phone = getPhone(subId);
2158 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002159 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160 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
Sanket Padawe356d7632015-06-22 14:03:32 -07002169 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002170 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171 final long identity = Binder.clearCallingIdentity();
2172 try {
2173 final Phone phone = getPhone(subId);
2174 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002175 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 } else {
2177 return false;
2178 }
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
2184 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002185 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002186 }
2187
pkanwarae03a6b2016-11-06 20:37:09 -08002188 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 enforceCallPermission();
2190
2191 final long identity = Binder.clearCallingIdentity();
2192 try {
2193 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2194 return;
2195 }
2196 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2197 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
2200 }
pkanwar32d516d2016-10-14 19:37:38 -07002201 };
2202
Wink Savilleb564aae2014-10-23 10:18:09 -07002203 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2209 return false;
2210 }
2211 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002218 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
2220
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002221 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 final long identity = Binder.clearCallingIdentity();
2223 try {
2224 Phone phone = PhoneFactory.getPhone(slotIndex);
2225 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2226 PhoneConstantConversions.convertCallState(phone.getState());
2227 } finally {
2228 Binder.restoreCallingIdentity(identity);
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231
Sanket Padawe356d7632015-06-22 14:03:32 -07002232 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002233 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002234 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2235 }
2236
2237 @Override
2238 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002241 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 if (phone != null) {
2243 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2244 } else {
2245 return PhoneConstantConversions.convertDataState(
2246 PhoneConstants.DataState.DISCONNECTED);
2247 }
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002254 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002255 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2256 }
2257
2258 @Override
2259 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 final long identity = Binder.clearCallingIdentity();
2261 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002262 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263 if (phone != null) {
2264 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2265 } else {
2266 return TelephonyManager.DATA_ACTIVITY_NONE;
2267 }
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
2273 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002274 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002275 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002276 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002277
2278 LocationAccessPolicy.LocationPermissionResult locationResult =
2279 LocationAccessPolicy.checkLocationPermission(mApp,
2280 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2281 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002282 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002283 .setCallingPid(Binder.getCallingPid())
2284 .setCallingUid(Binder.getCallingUid())
2285 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002286 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002287 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2288 .build());
2289 switch (locationResult) {
2290 case DENIED_HARD:
2291 throw new SecurityException("Not allowed to access cell location");
2292 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002293 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2294 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002297 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002301 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002302 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303 } finally {
2304 Binder.restoreCallingIdentity(identity);
2305 }
Svetoslav64fad262015-04-14 14:35:21 -07002306 }
2307
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002309 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002310 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2311 // registered cell info, so return a NULL country instead.
2312 final long identity = Binder.clearCallingIdentity();
2313 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002314 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2315 // Get default phone in this case.
2316 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2317 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002318 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002319 // Todo: fix this when we can get the actual cellular network info when the device
2320 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002321 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002322 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2323 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002324 return "";
2325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326 Phone phone = PhoneFactory.getPhone(phoneId);
2327 if (phone != null) {
2328 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002329 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330 if (sst != null) {
2331 LocaleTracker lt = sst.getLocaleTracker();
2332 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002333 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2334 return lt.getCurrentCountry();
2335 } else if (emergencyNumberTracker != null) {
2336 return emergencyNumberTracker.getEmergencyCountryIso();
2337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338 }
2339 }
2340 }
2341 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002342 } finally {
2343 Binder.restoreCallingIdentity(identity);
2344 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002345 }
2346
2347 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002349 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002350 }
2351
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002353 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 mApp.enforceCallingOrSelfPermission(
2355 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 final Phone phone = getPhone(subId);
2360 if (phone != null) {
2361 phone.enableLocationUpdates();
2362 }
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 }
2367
2368 @Override
2369 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002370 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002371 }
2372
Sanket Padawe356d7632015-06-22 14:03:32 -07002373 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002374 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 mApp.enforceCallingOrSelfPermission(
2376 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 final Phone phone = getPhone(subId);
2381 if (phone != null) {
2382 phone.disableLocationUpdates();
2383 }
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
2388
Nathan Harold31d7ff32018-10-15 20:20:30 -07002389 /**
2390 * Returns the target SDK version number for a given package name.
2391 *
Nathan Haroldec184742019-07-10 17:04:16 -07002392 * This call MUST be invoked before clearing the calling UID.
2393 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002394 * @return target SDK if the package is found or INT_MAX.
2395 */
2396 private int getTargetSdk(String packageName) {
2397 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002398 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002399 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002400 if (ai != null) return ai.targetSdkVersion;
2401 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002402 loge("Failed to get package info for pkg="
2403 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002404 }
2405 return Integer.MAX_VALUE;
2406 }
2407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 @Override
2409 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002410 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2411 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002412 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002413 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2414 throw new SecurityException(
2415 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2416 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002417
Jordan Liu1617b712019-07-10 15:06:26 -07002418 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2420 return null;
2421 }
Svetoslav64fad262015-04-14 14:35:21 -07002422
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002423 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002425 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002426 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427
Nathan Haroldf180aac2018-06-01 18:43:55 -07002428 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2429 for (CellInfo ci : info) {
2430 if (ci instanceof CellInfoGsm) {
2431 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2432 } else if (ci instanceof CellInfoWcdma) {
2433 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002436 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 }
2438
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002439 private List<CellInfo> getCachedCellInfo() {
2440 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2441 for (Phone phone : PhoneFactory.getPhones()) {
2442 List<CellInfo> info = phone.getAllCellInfo();
2443 if (info != null) cellInfos.addAll(info);
2444 }
2445 return cellInfos;
2446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447
2448 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002449 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002450 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002451 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002452
2453 LocationAccessPolicy.LocationPermissionResult locationResult =
2454 LocationAccessPolicy.checkLocationPermission(mApp,
2455 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2456 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002457 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002458 .setCallingPid(Binder.getCallingPid())
2459 .setCallingUid(Binder.getCallingUid())
2460 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002461 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002462 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2463 .build());
2464 switch (locationResult) {
2465 case DENIED_HARD:
2466 throw new SecurityException("Not allowed to access cell info");
2467 case DENIED_SOFT:
2468 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 }
2470
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002471 final int targetSdk = getTargetSdk(callingPackage);
2472 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2473 return getCachedCellInfo();
2474 }
2475
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002476 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002477 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2481 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002482 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002483 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 if (info != null) cellInfos.addAll(info);
2485 }
2486 return cellInfos;
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490 }
2491
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002492 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002493 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2494 String callingFeatureId) {
2495 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2496 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002497 }
2498
2499 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002500 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2501 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002502 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002503 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002504 }
2505
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002506 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2507 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002508 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002509 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002510
2511 LocationAccessPolicy.LocationPermissionResult locationResult =
2512 LocationAccessPolicy.checkLocationPermission(mApp,
2513 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2514 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002515 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002516 .setCallingPid(Binder.getCallingPid())
2517 .setCallingUid(Binder.getCallingUid())
2518 .setMethod("requestCellInfoUpdate")
2519 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2520 .build());
2521 switch (locationResult) {
2522 case DENIED_HARD:
2523 throw new SecurityException("Not allowed to access cell info");
2524 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002525 try {
2526 cb.onCellInfo(new ArrayList<CellInfo>());
2527 } catch (RemoteException re) {
2528 // Drop without consequences
2529 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002530 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002531 }
2532
Nathan Harolda939a962019-05-09 10:13:47 -07002533
2534 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002535 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2536
2537 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2538 }
2539
2540 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002542 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002543 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002547 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 } finally {
2549 Binder.restoreCallingIdentity(identity);
2550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 }
2552
Shishir Agrawala9f32182016-04-12 12:00:16 -07002553 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002554 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002555 Phone phone = PhoneFactory.getPhone(slotIndex);
2556 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002557 return null;
2558 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002559 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002560 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002561 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002562 return null;
2563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 return phone.getImei();
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
2570 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002571 }
2572
2573 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002574 public String getTypeAllocationCodeForSlot(int slotIndex) {
2575 Phone phone = PhoneFactory.getPhone(slotIndex);
2576 String tac = null;
2577 if (phone != null) {
2578 String imei = phone.getImei();
2579 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2580 }
2581 return tac;
2582 }
2583
2584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002585 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002586 Phone phone = PhoneFactory.getPhone(slotIndex);
2587 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002588 return null;
2589 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002590
Jeff Davidson913390f2018-02-23 17:11:49 -08002591 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002592 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002594 return null;
2595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 return phone.getMeid();
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
2602 }
Jack Yu2af8d712017-03-15 17:14:14 -07002603 }
2604
2605 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002606 public String getManufacturerCodeForSlot(int slotIndex) {
2607 Phone phone = PhoneFactory.getPhone(slotIndex);
2608 String manufacturerCode = null;
2609 if (phone != null) {
2610 String meid = phone.getMeid();
2611 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2612 }
2613 return manufacturerCode;
2614 }
2615
2616 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002617 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2618 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002619 Phone phone = PhoneFactory.getPhone(slotIndex);
2620 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002621 return null;
2622 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002623 int subId = phone.getSubId();
2624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002625 mApp, subId, callingPackage, callingFeatureId,
2626 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002627 return null;
2628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629
2630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 return phone.getDeviceSvn();
2633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002636 }
2637
fionaxu43304da2017-11-27 22:51:16 -08002638 @Override
2639 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
2643 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
2646 }
fionaxu43304da2017-11-27 22:51:16 -08002647 }
2648
2649 @Override
2650 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 final Phone phone = getPhone(subId);
2654 return phone == null ? null : phone.getCarrierName();
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
fionaxu43304da2017-11-27 22:51:16 -08002658 }
2659
calvinpanffe225e2018-11-01 19:43:06 +08002660 @Override
chen xu0026ca62019-03-06 15:28:50 -08002661 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002666 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
2670 }
2671
2672 @Override
chen xu0026ca62019-03-06 15:28:50 -08002673 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002674 final long identity = Binder.clearCallingIdentity();
2675 try {
2676 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002677 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002678 } finally {
2679 Binder.restoreCallingIdentity(identity);
2680 }
2681 }
2682
chen xu651eec72018-11-11 19:03:44 -08002683 @Override
chen xu864e11c2018-12-06 22:10:03 -08002684 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2685 if (!isSubscriptionMccMnc) {
2686 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2687 }
chen xu651eec72018-11-11 19:03:44 -08002688 final Phone phone = PhoneFactory.getPhone(slotIndex);
2689 if (phone == null) {
2690 return TelephonyManager.UNKNOWN_CARRIER_ID;
2691 }
2692 final long identity = Binder.clearCallingIdentity();
2693 try {
2694 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
2698 }
2699
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 //
2701 // Internal helper methods.
2702 //
2703
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002704 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2706 *
2707 * @throws SecurityException if the caller does not have the required permission
2708 */
2709 private void enforceModifyPermission() {
2710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2711 }
2712
Shuo Qiancd19c462020-01-16 20:51:11 -08002713 /**
2714 * Make sure the caller is system.
2715 *
2716 * @throws SecurityException if the caller is not system.
2717 */
2718 private void enforceSystemCaller() {
2719 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2720 throw new SecurityException("Caller must be system");
2721 }
2722 }
2723
Shuo Qian3b6ee772019-11-13 17:43:31 -08002724 private void enforceActiveEmergencySessionPermission() {
2725 mApp.enforceCallingOrSelfPermission(
2726 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2727 }
2728
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 /**
2730 * Make sure the caller has the CALL_PHONE permission.
2731 *
2732 * @throws SecurityException if the caller does not have the required permission
2733 */
2734 private void enforceCallPermission() {
2735 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2736 }
2737
paulhu5a773602019-08-23 19:17:33 +08002738 private void enforceSettingsPermission() {
2739 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002740 }
2741
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 private String createTelUrl(String number) {
2743 if (TextUtils.isEmpty(number)) {
2744 return null;
2745 }
2746
Jake Hambye994d462014-02-03 13:10:13 -08002747 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 }
2749
Ihab Awadf9e92732013-12-05 18:02:52 -08002750 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2752 }
2753
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002754 private static void logv(String msg) {
2755 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2756 }
2757
Ihab Awadf9e92732013-12-05 18:02:52 -08002758 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2760 }
2761
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002762 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002764 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002765 }
2766
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002768 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 final Phone phone = PhoneFactory.getPhone(slotIndex);
2772 if (phone == null) {
2773 return PhoneConstants.PHONE_TYPE_NONE;
2774 } else {
2775 return phone.getPhoneType();
2776 }
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
2781
2782 /**
2783 * Returns the CDMA ERI icon index to display
2784 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002785 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002786 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2787 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2788 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002789 }
2790
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002792 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2793 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002795 mApp, subId, callingPackage, callingFeatureId,
2796 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002797 return -1;
2798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
2804 return phone.getCdmaEriIconIndex();
2805 } else {
2806 return -1;
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
2813 /**
2814 * Returns the CDMA ERI icon mode,
2815 * 0 - ON
2816 * 1 - FLASHING
2817 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002819 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2820 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2821 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002822 }
2823
Sanket Padawe356d7632015-06-22 14:03:32 -07002824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002825 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2826 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002828 mApp, subId, callingPackage, callingFeatureId,
2829 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002830 return -1;
2831 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832
2833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 final Phone phone = getPhone(subId);
2836 if (phone != null) {
2837 return phone.getCdmaEriIconMode();
2838 } else {
2839 return -1;
2840 }
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
2845
2846 /**
2847 * Returns the CDMA ERI text,
2848 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002850 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2851 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2852 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002853 }
2854
Sanket Padawe356d7632015-06-22 14:03:32 -07002855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002856 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2857 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002859 mApp, subId, callingPackage, callingFeatureId,
2860 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002861 return null;
2862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 final Phone phone = getPhone(subId);
2867 if (phone != null) {
2868 return phone.getCdmaEriText();
2869 } else {
2870 return null;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 }
2876
2877 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002878 * Returns the CDMA MDN.
2879 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002880 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002881 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2883 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884
2885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002888 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 return phone.getLine1Number();
2890 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002891 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 return null;
2893 }
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002896 }
2897 }
2898
2899 /**
2900 * Returns the CDMA MIN.
2901 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002902 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002903 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2905 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906
2907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 final Phone phone = getPhone(subId);
2910 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2911 return phone.getCdmaMin();
2912 } else {
2913 return null;
2914 }
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002917 }
2918 }
2919
Hall Liud892bec2018-11-30 14:51:45 -08002920 @Override
2921 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2922 INumberVerificationCallback callback, String callingPackage) {
2923 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2924 != PERMISSION_GRANTED) {
2925 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2926 }
2927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2928
2929 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2930 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2931 throw new SecurityException("Calling package must be configured in the device config");
2932 }
2933
2934 if (range == null) {
2935 throw new NullPointerException("Range must be non-null");
2936 }
2937
2938 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002939 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002940
2941 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2942 }
2943
Junda Liuca05d5d2014-08-14 22:36:34 -07002944 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 * Returns true if CDMA provisioning needs to run.
2946 */
2947 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 final long identity = Binder.clearCallingIdentity();
2949 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002950 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 }
2955
2956 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002957 * Sets the voice mail number of a given subId.
2958 */
2959 @Override
2960 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002961 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2962 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2967 new Pair<String, String>(alphaTag, number), new Integer(subId));
2968 return success;
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002972 }
2973
Ta-wei Yen87c49842016-05-13 21:19:52 -07002974 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002975 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002977 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2978 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002979 if (!TextUtils.equals(callingPackage, systemDialer)) {
2980 throw new SecurityException("caller must be system dialer");
2981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2986 if (phoneAccountHandle == null) {
2987 return null;
2988 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002989 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 } finally {
2991 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002992 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002993 }
2994
2995 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002996 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2997 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003000 mApp, subId, callingPackage, callingFeatureId,
3001 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003002 return null;
3003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003005 final long identity = Binder.clearCallingIdentity();
3006 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003007 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003011 }
3012
3013 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003014 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3015 VisualVoicemailSmsFilterSettings settings) {
3016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003021 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003025 }
3026
3027 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003028 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3029 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003038 }
3039
3040 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003041 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3042 String callingPackage, int subId) {
3043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044
3045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003048 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003052 }
3053
3054 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003055 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003056 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003057
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003061 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003065 }
3066
3067 @Override
3068 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3069 String number, int port, String text, PendingIntent sentIntent) {
3070 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003071 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003072 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003073 SmsController smsController = PhoneFactory.getSmsController();
3074 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3075 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003076 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003077
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003078 /**
fionaxu0152e512016-11-14 13:36:14 -08003079 * Sets the voice activation state of a given subId.
3080 */
3081 @Override
3082 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3084 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085
3086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 final Phone phone = getPhone(subId);
3089 if (phone != null) {
3090 phone.setVoiceActivationState(activationState);
3091 } else {
3092 loge("setVoiceActivationState fails with invalid subId: " + subId);
3093 }
3094 } finally {
3095 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003096 }
3097 }
3098
3099 /**
3100 * Sets the data activation state of a given subId.
3101 */
3102 @Override
3103 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3105 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106
3107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 final Phone phone = getPhone(subId);
3110 if (phone != null) {
3111 phone.setDataActivationState(activationState);
3112 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003113 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 }
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003117 }
3118 }
3119
3120 /**
3121 * Returns the voice activation state of a given subId.
3122 */
3123 @Override
3124 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126
fionaxu0152e512016-11-14 13:36:14 -08003127 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 if (phone != null) {
3131 return phone.getVoiceActivationState();
3132 } else {
3133 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3134 }
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003137 }
3138 }
3139
3140 /**
3141 * Returns the data activation state of a given subId.
3142 */
3143 @Override
3144 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146
fionaxu0152e512016-11-14 13:36:14 -08003147 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 if (phone != null) {
3151 return phone.getDataActivationState();
3152 } else {
3153 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3154 }
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003157 }
3158 }
3159
3160 /**
Wink Saville36469e72014-06-11 15:17:00 -07003161 * Returns the unread count of voicemails for a subId
3162 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003163 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003164 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3165 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003166 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003167 mApp, subId, callingPackage, callingFeatureId,
3168 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003169 return 0;
3170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 final Phone phone = getPhone(subId);
3174 if (phone != null) {
3175 return phone.getVoiceMessageCount();
3176 } else {
3177 return 0;
3178 }
3179 } finally {
3180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182 }
3183
3184 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003185 * returns true, if the device is in a state where both voice and data
3186 * are supported simultaneously. This can change based on location or network condition.
3187 */
3188 @Override
3189 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 final Phone phone = getPhone(subId);
3193 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003197 }
3198
3199 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003200 * Send the dialer code if called from the current default dialer or the caller has
3201 * carrier privilege.
3202 * @param inputCode The dialer code to send
3203 */
3204 @Override
3205 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003206 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003207 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003208 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3209 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003210 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003211 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003212 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003217 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
fionaxu235cc5e2017-03-06 22:25:57 -08003221 }
3222
Pengquan Menga1bb6272018-09-06 09:59:22 -07003223 @Override
3224 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003225 TelephonyPermissions
3226 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3227 mApp, subId, "getNetworkSelectionMode");
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 if (!isActiveSubscription(subId)) {
3231 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3232 }
3233 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003236 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003237 }
3238
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003240 public boolean isInEmergencySmsMode() {
3241 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 for (Phone phone : PhoneFactory.getPhones()) {
3245 if (phone.isInEmergencySmsMode()) {
3246 return true;
3247 }
3248 }
3249 } finally {
3250 Binder.restoreCallingIdentity(identity);
3251 }
3252 return false;
3253 }
3254
shilu366312e2019-12-17 09:28:10 -08003255 /**
3256 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3257 * @param subId The subscription to use to check the configuration.
3258 * @param c The callback that will be used to send the result.
3259 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003260 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003261 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3262 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003263 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3264 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003265
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003266 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3267 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3268 "IMS not available on device.");
3269 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 final long token = Binder.clearCallingIdentity();
3271 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003272 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003273 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003275 } catch (ImsException e) {
3276 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 } finally {
3278 Binder.restoreCallingIdentity(token);
3279 }
3280 }
3281
shilu366312e2019-12-17 09:28:10 -08003282 /**
3283 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3284 * @param subId The subscription to use to check the configuration.
3285 * @param c The callback that will be used to send the result.
3286 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003288 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003289 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3290 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003291 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3292 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3293 }
Meng Wangafbc5852019-09-19 17:37:13 -07003294 final long token = Binder.clearCallingIdentity();
3295 try {
3296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3297 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3298 .removeRegistrationCallbackForSubscription(c, subId);
3299 } catch (ImsException e) {
3300 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3301 + "is inactive, ignoring unregister.");
3302 // If the subscription is no longer active, just return, since the callback
3303 // will already have been removed internally.
3304 } finally {
3305 Binder.restoreCallingIdentity(token);
3306 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003307 }
3308
Brad Ebingera34a6c22019-10-22 17:36:18 -07003309 /**
3310 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3311 */
3312 @Override
3313 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3314 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3315 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3316 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3317 "IMS not available on device.");
3318 }
3319 final long token = Binder.clearCallingIdentity();
3320 try {
3321 Phone phone = getPhone(subId);
3322 if (phone == null) {
3323 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3324 + subId + "'");
3325 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3326 }
3327 phone.getImsRegistrationState(regState -> {
3328 try {
3329 consumer.accept((regState == null)
3330 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3331 } catch (RemoteException e) {
3332 // Ignore if the remote process is no longer available to call back.
3333 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3334 }
3335 });
3336 } finally {
3337 Binder.restoreCallingIdentity(token);
3338 }
3339 }
3340
3341 /**
3342 * Get the transport type for the IMS service registration state.
3343 */
3344 @Override
3345 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003346 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3347 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003348 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3349 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3350 "IMS not available on device.");
3351 }
3352 final long token = Binder.clearCallingIdentity();
3353 try {
3354 Phone phone = getPhone(subId);
3355 if (phone == null) {
3356 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3357 + subId + "'");
3358 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3359 }
3360 phone.getImsRegistrationTech(regTech -> {
3361 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3362 int regTechConverted = (regTech == null)
3363 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3364 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3365 regTechConverted);
3366 try {
3367 consumer.accept(regTechConverted);
3368 } catch (RemoteException e) {
3369 // Ignore if the remote process is no longer available to call back.
3370 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3371 }
3372 });
3373 } finally {
3374 Binder.restoreCallingIdentity(token);
3375 }
3376 }
3377
shilu366312e2019-12-17 09:28:10 -08003378 /**
3379 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3380 * @param subId The subscription to use to check the configuration.
3381 * @param c The callback that will be used to send the result.
3382 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003384 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3385 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003386 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3387 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003388 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3389 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3390 "IMS not available on device.");
3391 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003392 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3393 final long token = Binder.clearCallingIdentity();
3394 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003395 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003397 } catch (ImsException e) {
3398 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 } finally {
3400 Binder.restoreCallingIdentity(token);
3401 }
3402 }
3403
shilu366312e2019-12-17 09:28:10 -08003404 /**
3405 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3406 * @param subId The subscription to use to check the configuration.
3407 * @param c The callback that will be used to send the result.
3408 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003409 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003410 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003411 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3412 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003413 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3414 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3415 }
Meng Wangafbc5852019-09-19 17:37:13 -07003416
3417 final long token = Binder.clearCallingIdentity();
3418 try {
3419 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3420 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003421 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003422 } catch (ImsException e) {
3423 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3424 + "is inactive, ignoring unregister.");
3425 // If the subscription is no longer active, just return, since the callback
3426 // will already have been removed internally.
3427 } finally {
3428 Binder.restoreCallingIdentity(token);
3429 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003430 }
3431
3432 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003433 public boolean isCapable(int subId, int capability, int regTech) {
3434 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003435 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3436 final long token = Binder.clearCallingIdentity();
3437 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003439 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003440 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3442 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003443 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003444 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3445 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003446 } finally {
3447 Binder.restoreCallingIdentity(token);
3448 }
3449 }
3450
3451 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003452 public boolean isAvailable(int subId, int capability, int regTech) {
3453 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003454 final long token = Binder.clearCallingIdentity();
3455 try {
3456 Phone phone = getPhone(subId);
3457 if (phone == null) return false;
3458 return phone.isImsCapabilityAvailable(capability, regTech);
3459 } finally {
3460 Binder.restoreCallingIdentity(token);
3461 }
3462 }
3463
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003464 /**
3465 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3466 * subscription.
3467 * @param subId The subscription to use to check the configuration.
3468 * @param callback The callback that will be used to send the result.
3469 * @param capability The MmTelFeature capability that will be used to send the result.
3470 * @param transportType The transport type of the MmTelFeature capability.
3471 */
3472 @Override
3473 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3474 int transportType) {
3475 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3476 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3477 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3478 "IMS not available on device.");
3479 }
3480 final long token = Binder.clearCallingIdentity();
3481 try {
3482 int slotId = getSlotIndex(subId);
3483 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3484 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3485 + subId + "'");
3486 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3487 }
3488 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3489 transportType, aBoolean -> {
3490 try {
3491 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3492 } catch (RemoteException e) {
3493 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3494 + "running. Ignore");
3495 }
3496 });
3497 } finally {
3498 Binder.restoreCallingIdentity(token);
3499 }
3500 }
3501
shilu366312e2019-12-17 09:28:10 -08003502 /**
3503 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3504 * @param subId The subscription to use to check the configuration.
3505 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 @Override
3507 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003508 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3509 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003510
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3512 final long token = Binder.clearCallingIdentity();
3513 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003514 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003516 } catch (ImsException e) {
3517 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 } finally {
3519 Binder.restoreCallingIdentity(token);
3520 }
3521 }
3522
3523 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003524 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003526 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003530 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003532 } catch (ImsException e) {
3533 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
3537 }
3538
shilu366312e2019-12-17 09:28:10 -08003539 /**
3540 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3541 * @param subId The subscription to use to check the configuration.
3542 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003543 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003544 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003545 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3546 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003550 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3551 } catch (ImsException e) {
3552 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
3556 }
3557
3558 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003559 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003561 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003565 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003566 } catch (ImsException e) {
3567 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 } finally {
3569 Binder.restoreCallingIdentity(identity);
3570 }
3571 }
3572
shilu366312e2019-12-17 09:28:10 -08003573 /**
3574 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3575 * @param subId The subscription to use to check the configuration.
3576 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003577 @Override
3578 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003579 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3580 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003584 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003586 } catch (ImsException e) {
3587 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 } finally {
3589 Binder.restoreCallingIdentity(identity);
3590 }
3591 }
3592
3593 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003594 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003596 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003600 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003601 } catch (ImsException e) {
3602 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
3606 }
3607
shilu366312e2019-12-17 09:28:10 -08003608 /**
3609 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3610 * @param subId The subscription to use to check the configuration.
3611 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003612 @Override
3613 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003614 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3615 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003619 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003621 } catch (ImsException e) {
3622 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 } finally {
3624 Binder.restoreCallingIdentity(identity);
3625 }
3626 }
3627
3628 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003629 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003631 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003632 final long identity = Binder.clearCallingIdentity();
3633 try {
3634 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003635 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003636 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003637 } catch (ImsException e) {
3638 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 } finally {
3640 Binder.restoreCallingIdentity(identity);
3641 }
3642 }
3643
3644 @Override
3645 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3647 "setVoWiFiNonPersistent");
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003651 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003652 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003653 } catch (ImsException e) {
3654 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
3658 }
3659
shilu366312e2019-12-17 09:28:10 -08003660 /**
3661 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3662 * @param subId The subscription to use to check the configuration.
3663 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003664 @Override
3665 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003666 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3667 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003671 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003672 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003673 } catch (ImsException e) {
3674 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
3678 }
3679
3680 @Override
3681 public void setVoWiFiModeSetting(int subId, int mode) {
3682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3683 "setVoWiFiModeSetting");
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003687 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003689 } catch (ImsException e) {
3690 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
3694 }
3695
3696 @Override
3697 public int getVoWiFiRoamingModeSetting(int subId) {
3698 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003702 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003703 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003704 } catch (ImsException e) {
3705 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
3709 }
3710
3711 @Override
3712 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3714 "setVoWiFiRoamingModeSetting");
3715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003718 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003719 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003720 } catch (ImsException e) {
3721 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003722 } finally {
3723 Binder.restoreCallingIdentity(identity);
3724 }
3725 }
3726
3727 @Override
3728 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3730 "setRttCapabilityEnabled");
3731 final long identity = Binder.clearCallingIdentity();
3732 try {
3733 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003734 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3735 } catch (ImsException e) {
3736 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
3740 }
3741
shilu366312e2019-12-17 09:28:10 -08003742 /**
3743 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3744 * @param subId The subscription to use to check the configuration.
3745 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 @Override
3747 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003748 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3749 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003753 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003754 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003755 } catch (ImsException e) {
3756 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 } finally {
3758 Binder.restoreCallingIdentity(identity);
3759 }
3760 }
3761
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003762 @Override
3763 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3764 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3765 final long identity = Binder.clearCallingIdentity();
3766 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003767 if (!isImsAvailableOnDevice()) {
3768 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3769 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003770 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003771 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003772 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003773 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003774 } catch (ImsException e) {
3775 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
3779 }
3780
3781 @Override
3782 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3783 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3784 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3786 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3787 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003788 try {
3789 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003790 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003791 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003792 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003793 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3794 + "is inactive, ignoring unregister.");
3795 // If the subscription is no longer active, just return, since the callback will already
3796 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
3800 }
3801
allenwtsu99c623b2020-01-03 18:24:23 +08003802
3803 private void checkModifyPhoneStatePermission(int subId, String message) {
3804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3805 message);
3806 }
3807
3808 private boolean isImsProvisioningRequired(int subId, int capability,
3809 boolean isMmtelCapability) {
3810 Phone phone = getPhone(subId);
3811 if (phone == null) {
3812 loge("phone instance null for subid " + subId);
3813 return false;
3814 }
3815 if (isMmtelCapability) {
3816 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3817 return false;
3818 }
3819 } else {
3820 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3821 return false;
3822 }
3823 }
3824 return true;
3825 }
3826
3827 @Override
3828 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3829 boolean isProvisioned) {
3830 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3831
3832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3835 if (!isImsProvisioningRequired(subId, capability, false)) {
3836 return;
3837 }
3838
3839 // this capability requires provisioning, route to the correct API.
3840 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3841 switch (capability) {
3842 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3843 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3844 ims.setEabProvisioned(isProvisioned);
3845 break;
3846 default: {
3847 throw new IllegalArgumentException("Tried to set provisioning for "
3848 + "rcs capability '" + capability + "', which does not require "
3849 + "provisioning.");
3850 }
3851 }
3852 } finally {
3853 Binder.restoreCallingIdentity(identity);
3854 }
3855
3856 }
3857
3858
3859 @Override
3860 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3861 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3862 final long identity = Binder.clearCallingIdentity();
3863 try {
3864 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3865 if (!isImsProvisioningRequired(subId, capability, false)) {
3866 return true;
3867 }
3868
3869 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3870 switch (capability) {
3871 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3872 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3873 return ims.isEabProvisionedOnDevice();
3874
3875 default: {
3876 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3877 + "capability '" + capability + "', which does not require "
3878 + "provisioning.");
3879 }
3880 }
3881
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
3884 }
3885 }
3886
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003887 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003888 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3889 boolean isProvisioned) {
3890 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3891 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3892 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3893 }
allenwtsu99c623b2020-01-03 18:24:23 +08003894 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003898 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003899 return;
3900 }
3901
3902 // this capability requires provisioning, route to the correct API.
3903 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3904 switch (capability) {
3905 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3906 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3907 ims.setVolteProvisioned(isProvisioned);
3908 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3909 ims.setWfcProvisioned(isProvisioned);
3910 }
3911 break;
3912 }
3913 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3914 // There is currently no difference in VT provisioning type.
3915 ims.setVtProvisioned(isProvisioned);
3916 break;
3917 }
3918 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3919 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3920 // change the capability of the feature instead if needed.
3921 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3922 == isProvisioned) {
3923 // No change in provisioning.
3924 return;
3925 }
3926 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3927 try {
3928 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003929 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003930 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3931 + ", Exception" + e.getMessage());
3932 }
3933 break;
3934 }
3935 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003936 throw new IllegalArgumentException("Tried to set provisioning for "
3937 + "MmTel capability '" + capability + "', which does not require "
3938 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003939 }
3940 }
3941
3942 } finally {
3943 Binder.restoreCallingIdentity(identity);
3944 }
3945 }
3946
3947 @Override
3948 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3949 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3950 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3951 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3952 }
3953 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003957 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003958 return true;
3959 }
3960
3961 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3962 switch (capability) {
3963 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3964 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3965 return ims.isVolteProvisionedOnDevice();
3966 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3967 return ims.isWfcProvisionedOnDevice();
3968 }
3969 // This should never happen, since we are checking tech above to make sure it
3970 // is either LTE or IWLAN.
3971 throw new IllegalArgumentException("Invalid radio technology for voice "
3972 + "capability.");
3973 }
3974 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3975 // There is currently no difference in VT provisioning type.
3976 return ims.isVtProvisionedOnDevice();
3977 }
3978 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3979 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3980 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3981 }
3982 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003983 throw new IllegalArgumentException(
3984 "Tried to get provisioning for MmTel capability '" + capability
3985 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003986 }
3987 }
3988
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
3992 }
3993
3994 @Override
3995 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3996 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3997 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3998 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3999 }
4000 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4001 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4002 return (provisionedBits & capability) > 0;
4003 }
4004
4005 @Override
4006 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4007 boolean isProvisioned) {
4008 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4009 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4010 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4011 }
4012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4013 "setProvisioningStatusForCapability");
4014 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4015 // If the current provisioning status for capability already matches isProvisioned,
4016 // do nothing.
4017 if (((provisionedBits & capability) > 0) == isProvisioned) {
4018 return;
4019 }
4020 if (isProvisioned) {
4021 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4022 } else {
4023 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4024 }
4025 }
4026
4027 /**
4028 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4029 * technology. The bitfield should mirror the bitfield defined by
4030 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4031 */
4032 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4033 String key = getMmTelProvisioningKey(subId, tech);
4034 // Default is no capabilities are provisioned.
4035 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4036 }
4037
4038 /**
4039 * Sets the MmTel capability provisioning bitfield (defined by
4040 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4041 * technology specified.
4042 *
4043 * Note: This is a synchronous command and should not be called on UI thread.
4044 */
4045 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4046 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4047 String key = getMmTelProvisioningKey(subId, tech);
4048 editor.putInt(key, newField);
4049 editor.commit();
4050 }
4051
4052 private static String getMmTelProvisioningKey(int subId, int tech) {
4053 // resulting key is provision_ims_mmtel_{subId}_{tech}
4054 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4055 }
4056
4057 /**
4058 * Query CarrierConfig to see if the specified capability requires provisioning for the
4059 * carrier associated with the subscription id.
4060 */
4061 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4062 int capability) {
4063 CarrierConfigManager configManager = new CarrierConfigManager(context);
4064 PersistableBundle c = configManager.getConfigForSubId(subId);
4065 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004066 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004067 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4068 false);
4069 boolean requireVoiceVtProvisioning = c.getBoolean(
4070 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4071
4072 // First check to make sure that the capability requires provisioning.
4073 switch (capability) {
4074 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4075 // intentional fallthrough
4076 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4077 if (requireVoiceVtProvisioning) {
4078 // Voice and Video requires provisioning
4079 return true;
4080 }
4081 break;
4082 }
4083 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4084 if (requireUtProvisioning) {
4085 // UT requires provisioning
4086 return true;
4087 }
4088 break;
4089 }
4090 }
4091 return false;
4092 }
4093
allenwtsu99c623b2020-01-03 18:24:23 +08004094 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4095 int capability) {
4096 CarrierConfigManager configManager = new CarrierConfigManager(context);
4097 PersistableBundle c = configManager.getConfigForSubId(subId);
4098
4099 boolean requireRcsProvisioning = c.getBoolean(
4100 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4101
4102 // First check to make sure that the capability requires provisioning.
4103 switch (capability) {
4104 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4105 // intentional fallthrough
4106 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4107 if (requireRcsProvisioning) {
4108 // OPTION or PRESENCE requires provisioning
4109 return true;
4110 }
4111 break;
4112 }
4113 }
4114 return false;
4115 }
4116
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004117 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004118 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4120 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4121 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004122 enforceReadPrivilegedPermission("getImsProvisioningInt");
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004126 int slotId = getSlotIndex(subId);
4127 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4128 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4129 + subId + "' for key:" + key);
4130 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4131 }
4132 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004133 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004134 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4135 + subId + "' for key:" + key);
4136 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
4140 }
4141
4142 @Override
4143 public String getImsProvisioningString(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("getImsProvisioningString");
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, "getImsProvisioningString: called for an inactive subscription id '"
4154 + subId + "' for key:" + key);
4155 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4156 }
4157 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(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, "getImsProvisioningString: ImsService is not available for sub '"
4160 + subId + "' for key:" + key);
4161 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
4165 }
4166
4167 @Override
4168 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004169 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4170 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4171 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4173 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004177 int slotId = getSlotIndex(subId);
4178 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4179 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4180 + subId + "' for key:" + key);
4181 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4182 }
4183 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004184 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004185 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4186 + "' for key:" + key);
4187 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
4193 @Override
4194 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004195 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4196 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4197 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4199 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004200 final long identity = Binder.clearCallingIdentity();
4201 try {
4202 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004203 int slotId = getSlotIndex(subId);
4204 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4205 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4206 + subId + "' for key:" + key);
4207 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4208 }
4209 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004211 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4212 + "' for key:" + key);
4213 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
4217 }
4218
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004219 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 int slotId = SubscriptionManager.getSlotIndex(subId);
4221 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004222 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4223 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 }
4225 return slotId;
4226 }
4227
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004228 private int getSlotIndex(int subId) {
4229 int slotId = SubscriptionManager.getSlotIndex(subId);
4230 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4231 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4232 }
4233 return slotId;
4234 }
4235
Wink Saville36469e72014-06-11 15:17:00 -07004236 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004237 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004238 */
4239 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004240 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4241 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004242 final int targetSdk = getTargetSdk(callingPackage);
4243 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004244 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004245 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004246 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004247 mApp, subId, callingPackage, callingFeatureId,
4248 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004249 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4250 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 final Phone phone = getPhone(subId);
4255 if (phone != null) {
4256 return phone.getServiceState().getDataNetworkType();
4257 } else {
4258 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4259 }
4260 } finally {
4261 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004263 }
4264
4265 /**
4266 * Returns the data network type
4267 */
4268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4270 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4271 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004272 }
4273
4274 /**
4275 * Returns the data network type for a subId
4276 */
4277 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004278 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4279 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004281 mApp, subId, callingPackage, callingFeatureId,
4282 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004283 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4284 }
4285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 final long identity = Binder.clearCallingIdentity();
4287 try {
4288 final Phone phone = getPhone(subId);
4289 if (phone != null) {
4290 return phone.getServiceState().getDataNetworkType();
4291 } else {
4292 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4293 }
4294 } finally {
4295 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004297 }
4298
4299 /**
Wink Saville36469e72014-06-11 15:17:00 -07004300 * Returns the Voice network type for a subId
4301 */
4302 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004303 public int getVoiceNetworkTypeForSubscriber(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 Greenwalta5dcfcb2015-07-10 09:06:29 -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().getVoiceNetworkType();
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 /**
4325 * @return true if a ICC card is present
4326 */
4327 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004328 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004329 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4330 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004331 }
4332
4333 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004334 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004335 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004336 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004337 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338 final long identity = Binder.clearCallingIdentity();
4339 try {
4340 final Phone phone = PhoneFactory.getPhone(slotIndex);
4341 if (phone != null) {
4342 return phone.getIccCard().hasIccCard();
4343 } else {
4344 return false;
4345 }
4346 } finally {
4347 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004349 }
4350
4351 /**
4352 * Return if the current radio is LTE on CDMA. This
4353 * is a tri-state return value as for a period of time
4354 * the mode may be unknown.
4355 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004356 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004357 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004358 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004359 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004360 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004361 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4362 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4363 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004364 }
4365
Sanket Padawe356d7632015-06-22 14:03:32 -07004366 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004367 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4368 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004369 try {
4370 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4371 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004372 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4373 }
4374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375 final long identity = Binder.clearCallingIdentity();
4376 try {
4377 final Phone phone = getPhone(subId);
4378 if (phone == null) {
4379 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4380 } else {
4381 return phone.getLteOnCdmaMode();
4382 }
4383 } finally {
4384 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004385 }
Wink Saville36469e72014-06-11 15:17:00 -07004386 }
4387
Wink Saville36469e72014-06-11 15:17:00 -07004388 /**
4389 * {@hide}
4390 * Returns Default subId, 0 in the case of single standby.
4391 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004392 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004393 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004394 }
4395
Shishir Agrawala9f32182016-04-12 12:00:16 -07004396 private int getSlotForDefaultSubscription() {
4397 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4398 }
4399
Wink Savilleb564aae2014-10-23 10:18:09 -07004400 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004401 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004402 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004403
Pengquan Menge92a50d2018-09-21 15:54:48 -07004404 private boolean isActiveSubscription(int subId) {
4405 return mSubscriptionController.isActiveSubId(subId);
4406 }
4407
Ihab Awadf2177b72013-11-25 13:33:23 -08004408 /**
4409 * @see android.telephony.TelephonyManager.WifiCallingChoices
4410 */
4411 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 final long identity = Binder.clearCallingIdentity();
4413 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004414 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004415 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4416 getWhenToMakeWifiCallsDefaultPreference());
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004420 }
4421
4422 /**
4423 * @see android.telephony.TelephonyManager.WifiCallingChoices
4424 */
4425 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 final long identity = Binder.clearCallingIdentity();
4427 try {
4428 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004429 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
4433 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004434 }
4435
Sailesh Nepald1e68152013-12-12 19:08:02 -08004436 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004437 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004438 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004439 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004440
Jordan Liu4c733742019-02-28 12:03:40 -08004441 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4442 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4443 if (phoneId == -1) {
4444 throw new IllegalArgumentException("Given slot index: " + slotIndex
4445 + " does not correspond to an active phone");
4446 }
4447 return PhoneFactory.getPhone(phoneId);
4448 }
4449
Shishir Agrawal566b7612013-10-28 14:41:00 -07004450 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004451 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4452 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4454 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004456 if (DBG) {
4457 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4458 }
4459 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4460 p2);
4461 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004462
Jordan Liu4c733742019-02-28 12:03:40 -08004463
4464 @Override
4465 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4466 int slotIndex, String callingPackage, String aid, int p2) {
4467 enforceModifyPermission();
4468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4469 if (DBG) {
4470 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4471 }
4472 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4473 callingPackage, aid, p2);
4474 }
4475
4476 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4477 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 final long identity = Binder.clearCallingIdentity();
4479 try {
4480 if (TextUtils.equals(ISDR_AID, aid)) {
4481 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004482 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4483 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004484 if (bestComponent == null
4485 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4486 loge("The calling package is not allowed to access ISD-R.");
4487 throw new SecurityException(
4488 "The calling package is not allowed to access ISD-R.");
4489 }
Derek Tan740e1672017-06-27 14:56:27 -07004490 }
Derek Tan740e1672017-06-27 14:56:27 -07004491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004493 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4494 null /* workSource */);
4495 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 return response;
4497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004500 }
4501
4502 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004503 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4505 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004506 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4507 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4508 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004509
Jordan Liu4c733742019-02-28 12:03:40 -08004510 @Override
4511 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4512 enforceModifyPermission();
4513 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4514 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4515 channel);
4516 }
4517
4518 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 final long identity = Binder.clearCallingIdentity();
4520 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521 if (channel < 0) {
4522 return false;
4523 }
Jordan Liu4c733742019-02-28 12:03:40 -08004524 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4525 null /* workSource */);
4526 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004527 return success;
4528 } finally {
4529 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004530 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004531 }
4532
4533 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004534 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004535 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4537 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004538 if (DBG) {
4539 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4540 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4541 + p3 + " data=" + data);
4542 }
4543 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4544 command, p1, p2, p3, data);
4545 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004546
Jordan Liu4c733742019-02-28 12:03:40 -08004547 @Override
4548 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4549 int command, int p1, int p2, int p3, String data) {
4550 enforceModifyPermission();
4551 if (DBG) {
4552 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4553 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4554 + p3 + " data=" + data);
4555 }
4556 return iccTransmitApduLogicalChannelWithPermission(
4557 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4558 data);
4559 }
4560
4561 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4562 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563 final long identity = Binder.clearCallingIdentity();
4564 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004565 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566 return "";
4567 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004570 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4571 null /* workSource */);
4572 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 // Append the returned status code to the end of the response payload.
4575 String s = Integer.toHexString(
4576 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4577 if (response.payload != null) {
4578 s = IccUtils.bytesToHexString(response.payload) + s;
4579 }
4580 return s;
4581 } finally {
4582 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004583 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004584 }
Jake Hambye994d462014-02-03 13:10:13 -08004585
Evan Charltonc66da362014-05-16 14:06:40 -07004586 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004587 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4588 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4590 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004592 if (DBG) {
4593 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4594 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4595 }
4596 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4597 cla, command, p1, p2, p3, data);
4598 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004599
Jordan Liu4c733742019-02-28 12:03:40 -08004600 @Override
4601 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4602 int command, int p1, int p2, int p3, String data) {
4603 enforceModifyPermission();
4604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4605 if (DBG) {
4606 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4607 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4608 + " data=" + data);
4609 }
4610
4611 return iccTransmitApduBasicChannelWithPermission(
4612 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4613 p2, p3, data);
4614 }
4615
4616 // open APDU basic channel assuming the caller has sufficient permissions
4617 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4618 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004619 final long identity = Binder.clearCallingIdentity();
4620 try {
4621 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4622 && TextUtils.equals(ISDR_AID, data)) {
4623 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004624 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4625 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 if (bestComponent == null
4627 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4628 loge("The calling package is not allowed to select ISD-R.");
4629 throw new SecurityException(
4630 "The calling package is not allowed to select ISD-R.");
4631 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004632 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004634 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004635 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4636 null /* workSource */);
4637 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639 // Append the returned status code to the end of the response payload.
4640 String s = Integer.toHexString(
4641 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4642 if (response.payload != null) {
4643 s = IccUtils.bytesToHexString(response.payload) + s;
4644 }
4645 return s;
4646 } finally {
4647 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004648 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004649 }
4650
4651 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004652 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004653 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4655 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 final long identity = Binder.clearCallingIdentity();
4658 try {
4659 if (DBG) {
4660 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4661 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4662 }
4663
4664 IccIoResult response =
4665 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4666 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4667 subId);
4668
4669 if (DBG) {
4670 log("Exchange SIM_IO [R]" + response);
4671 }
4672
4673 byte[] result = null;
4674 int length = 2;
4675 if (response.payload != null) {
4676 length = 2 + response.payload.length;
4677 result = new byte[length];
4678 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4679 } else {
4680 result = new byte[length];
4681 }
4682
4683 result[length - 1] = (byte) response.sw2;
4684 result[length - 2] = (byte) response.sw1;
4685 return result;
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004688 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004689 }
4690
Nathan Haroldb3014052017-01-25 15:57:32 -08004691 /**
4692 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4693 * on a particular subscription
4694 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004695 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4696 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004698 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004699 return null;
4700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701
4702 final long identity = Binder.clearCallingIdentity();
4703 try {
4704 if (appType != TelephonyManager.APPTYPE_USIM
4705 && appType != TelephonyManager.APPTYPE_SIM) {
4706 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4707 return null;
4708 }
4709 Object response = sendRequest(
4710 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4711 if (response instanceof String[]) {
4712 return (String[]) response;
4713 }
yincheng zhao2737e882019-09-06 17:06:54 -07004714 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004715 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004716 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 } finally {
4718 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004719 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004720 }
4721
yincheng zhao2737e882019-09-06 17:06:54 -07004722 /**
4723 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4724 * subscription.
4725 *
4726 * @param subId the id of the subscription.
4727 * @param appType the uicc app type, must be USIM or SIM.
4728 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4729 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004730 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004731 * @return number of fplmns that is successfully written to the SIM.
4732 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004733 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4734 String callingFeatureId) {
4735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4736 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004737 if (DBG) logv("no permissions for setForbiddenplmns");
4738 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4739 }
4740 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4741 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4742 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4743 }
4744 if (fplmns == null) {
4745 throw new IllegalArgumentException("Fplmn List provided is null");
4746 }
4747 for (String fplmn : fplmns) {
4748 if (!CellIdentity.isValidPlmn(fplmn)) {
4749 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4750 }
4751 }
4752 final long identity = Binder.clearCallingIdentity();
4753 try {
4754 Object response = sendRequest(
4755 CMD_SET_FORBIDDEN_PLMNS,
4756 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4757 subId);
4758 return (int) response;
4759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
4762 }
4763
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004764 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004765 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4767 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4772 if (response.payload == null) {
4773 return "";
4774 }
Evan Charltonc66da362014-05-16 14:06:40 -07004775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 // Append the returned status code to the end of the response payload.
4777 String s = Integer.toHexString(
4778 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4779 s = IccUtils.bytesToHexString(response.payload) + s;
4780 return s;
4781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
Evan Charltonc66da362014-05-16 14:06:40 -07004784 }
4785
Jake Hambye994d462014-02-03 13:10:13 -08004786 /**
4787 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4788 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4789 *
4790 * @param itemID the ID of the item to read
4791 * @return the NV item as a String, or null on error.
4792 */
4793 @Override
4794 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4797 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798
4799 final long identity = Binder.clearCallingIdentity();
4800 try {
4801 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004802 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4804 return value;
4805 } finally {
4806 Binder.restoreCallingIdentity(identity);
4807 }
Jake Hambye994d462014-02-03 13:10:13 -08004808 }
4809
4810 /**
4811 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4812 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4813 *
4814 * @param itemID the ID of the item to read
4815 * @param itemValue the value to write, as a String
4816 * @return true on success; false on any failure
4817 */
4818 @Override
4819 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004820 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4822 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823
4824 final long identity = Binder.clearCallingIdentity();
4825 try {
4826 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4827 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004828 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4830 return success;
4831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
Jake Hambye994d462014-02-03 13:10:13 -08004834 }
4835
4836 /**
4837 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4838 * Used for device configuration by some CDMA operators.
4839 *
4840 * @param preferredRoamingList byte array containing the new PRL
4841 * @return true on success; false on any failure
4842 */
4843 @Override
4844 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4846 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847
4848 final long identity = Binder.clearCallingIdentity();
4849 try {
4850 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4851 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4852 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4853 return success;
4854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
Jake Hambye994d462014-02-03 13:10:13 -08004857 }
4858
4859 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004860 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004861 * Used for device configuration by some CDMA operators.
4862 *
chen xu6dac5ab2018-10-26 17:39:23 -07004863 * @param slotIndex - device slot.
4864 *
Jake Hambye994d462014-02-03 13:10:13 -08004865 * @return true on success; false on any failure
4866 */
4867 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004868 public boolean resetModemConfig(int slotIndex) {
4869 Phone phone = PhoneFactory.getPhone(slotIndex);
4870 if (phone != null) {
4871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4872 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873
chen xu6dac5ab2018-10-26 17:39:23 -07004874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4877 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4878 return success;
4879 } finally {
4880 Binder.restoreCallingIdentity(identity);
4881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004882 }
chen xu6dac5ab2018-10-26 17:39:23 -07004883 return false;
4884 }
4885
4886 /**
4887 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4888 *
4889 * @param slotIndex - device slot.
4890 *
4891 * @return true on success; false on any failure
4892 */
4893 @Override
4894 public boolean rebootModem(int slotIndex) {
4895 Phone phone = PhoneFactory.getPhone(slotIndex);
4896 if (phone != null) {
4897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4898 mApp, phone.getSubId(), "rebootModem");
4899
4900 final long identity = Binder.clearCallingIdentity();
4901 try {
4902 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4903 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4904 return success;
4905 } finally {
4906 Binder.restoreCallingIdentity(identity);
4907 }
4908 }
4909 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004910 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004911
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004912 public String[] getPcscfAddress(String apnType, String callingPackage,
4913 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004914 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4916 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004917 return new String[0];
4918 }
4919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004920 final long identity = Binder.clearCallingIdentity();
4921 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004922 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 } finally {
4924 Binder.restoreCallingIdentity(identity);
4925 }
Wink Saville36469e72014-06-11 15:17:00 -07004926 }
4927
Brad Ebinger51f743a2017-01-23 13:50:20 -08004928 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004929 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4930 * {@link #disableIms(int)}.
4931 * @param slotIndex device slot.
4932 */
4933 public void resetIms(int slotIndex) {
4934 enforceModifyPermission();
4935
4936 final long identity = Binder.clearCallingIdentity();
4937 try {
4938 if (mImsResolver == null) {
4939 // may happen if the does not support IMS.
4940 return;
4941 }
4942 mImsResolver.disableIms(slotIndex);
4943 mImsResolver.enableIms(slotIndex);
4944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
4947 }
4948
4949 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004950 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4951 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004952 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004953 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004955
4956 final long identity = Binder.clearCallingIdentity();
4957 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004958 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004959 // may happen if the device does not support IMS.
4960 return;
4961 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004962 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 } finally {
4964 Binder.restoreCallingIdentity(identity);
4965 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004966 }
4967
4968 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004969 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4970 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004971 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004972 public void disableIms(int slotId) {
4973 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974
4975 final long identity = Binder.clearCallingIdentity();
4976 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004977 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004978 // may happen if the device does not support IMS.
4979 return;
4980 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004981 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 } finally {
4983 Binder.restoreCallingIdentity(identity);
4984 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004985 }
4986
4987 /**
4988 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4989 * feature or {@link null} if the service is not available. If the feature is available, the
4990 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4991 */
4992 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004993 IImsServiceFeatureCallback callback) {
4994 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995
4996 final long identity = Binder.clearCallingIdentity();
4997 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004998 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004999 // may happen if the device does not support IMS.
5000 return null;
5001 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005002 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 } finally {
5004 Binder.restoreCallingIdentity(identity);
5005 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005006 }
5007
5008 /**
5009 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5010 * feature during emergency calling or {@link null} if the service is not available. If the
5011 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5012 * listener for feature updates.
5013 */
5014 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5015 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016
5017 final long identity = Binder.clearCallingIdentity();
5018 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005019 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005020 // may happen if the device does not support IMS.
5021 return null;
5022 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005023 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005027 }
5028
Brad Ebinger5f64b052017-12-14 14:26:15 -08005029 /**
5030 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005031 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005032 */
5033 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5034 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035
5036 final long identity = Binder.clearCallingIdentity();
5037 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005038 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005039 // may happen if the device does not support IMS.
5040 return null;
5041 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005042 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 } finally {
5044 Binder.restoreCallingIdentity(identity);
5045 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005046 }
5047
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005048 /**
5049 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005050 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005051 */
5052 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5053 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054
5055 final long identity = Binder.clearCallingIdentity();
5056 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005057 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005058 // may happen if the device does not support IMS.
5059 return null;
5060 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005061 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062 } finally {
5063 Binder.restoreCallingIdentity(identity);
5064 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005065 }
5066
Brad Ebinger884c07b2018-02-15 16:17:40 -08005067 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005068 * Sets the ImsService Package Name that Telephony will bind to.
5069 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005070 * @param slotIndex the slot ID that the ImsService should bind for.
5071 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005072 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005073 * @param featureTypes An integer array of feature types associated with a packageName.
5074 * @param packageName The name of the package that the current configuration will be replaced
5075 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005076 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005077 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005078 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5079 int[] featureTypes, String packageName) {
5080 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5081 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5083 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005084 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 final long identity = Binder.clearCallingIdentity();
5087 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005088 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005089 // may happen if the device does not support IMS.
5090 return false;
5091 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005092 Map<Integer, String> featureConfig = new HashMap<>();
5093 for (int featureType : featureTypes) {
5094 featureConfig.put(featureType, packageName);
5095 }
5096 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5097 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005101 }
5102
5103 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005104 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005105 *
5106 * @param slotId The slot that the ImsService is associated with.
5107 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5108 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005109 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005110 * @return the package name of the ImsService configuration.
5111 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005112 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5113 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005114 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005115 TelephonyPermissions
5116 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5117 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5118 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 final long identity = Binder.clearCallingIdentity();
5121 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005122 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005123 // may happen if the device does not support IMS.
5124 return "";
5125 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005126 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005127 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5128 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 } finally {
5130 Binder.restoreCallingIdentity(identity);
5131 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005132 }
5133
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005134 /**
5135 * Get the MmTelFeature state associated with the requested subscription id.
5136 * @param subId The subscription that the MmTelFeature is associated with.
5137 * @param callback A callback with an integer containing the
5138 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5139 */
5140 @Override
5141 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5142 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5143 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5144 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5145 "IMS not available on device.");
5146 }
5147 final long token = Binder.clearCallingIdentity();
5148 try {
5149 int slotId = getSlotIndex(subId);
5150 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5151 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5152 + subId + "'");
5153 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5154 }
5155 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5156 try {
5157 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5158 } catch (RemoteException e) {
5159 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5160 + "Ignore");
5161 }
5162 });
5163 } finally {
5164 Binder.restoreCallingIdentity(token);
5165 }
5166 }
5167
Wink Saville36469e72014-06-11 15:17:00 -07005168 public void setImsRegistrationState(boolean registered) {
5169 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170
5171 final long identity = Binder.clearCallingIdentity();
5172 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005173 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Wink Saville36469e72014-06-11 15:17:00 -07005177 }
5178
5179 /**
Stuart Scott54788802015-03-30 13:18:01 -07005180 * Set the network selection mode to automatic.
5181 *
5182 */
5183 @Override
5184 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5186 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187
5188 final long identity = Binder.clearCallingIdentity();
5189 try {
shilufc958392020-01-20 11:36:01 -08005190 if (!isActiveSubscription(subId)) {
5191 return;
5192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5194 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5195 } finally {
5196 Binder.restoreCallingIdentity(identity);
5197 }
Stuart Scott54788802015-03-30 13:18:01 -07005198 }
5199
Pengquan Mengea84e042018-09-20 14:57:26 -07005200 /**
5201 * Ask the radio to connect to the input network and change selection mode to manual.
5202 *
5203 * @param subId the id of the subscription.
5204 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5205 * the operator to attach to.
5206 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5207 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5208 * normal network selection next time.
5209 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005210 */
5211 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005212 public boolean setNetworkSelectionModeManual(
5213 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5215 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005216
5217 if (!isActiveSubscription(subId)) {
5218 return false;
5219 }
5220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
5222 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005223 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005225 if (DBG) {
5226 log("setNetworkSelectionModeManual: subId: " + subId
5227 + " operator: " + operatorInfo);
5228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
5232 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005233 }
shilu84f6e8b2019-12-19 13:58:01 -08005234 /**
5235 * Get the manual network selection
5236 *
5237 * @param subId the id of the subscription.
5238 *
5239 * @return the previously saved user selected PLMN
5240 */
5241 @Override
5242 public String getManualNetworkSelectionPlmn(int subId) {
5243 TelephonyPermissions
5244 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5245 mApp, subId, "getManualNetworkSelectionPlmn");
5246
5247 final long identity = Binder.clearCallingIdentity();
5248 try {
5249 if (!isActiveSubscription(subId)) {
5250 return "";
5251 }
5252
5253 final Phone phone = getPhone(subId);
5254 if (phone == null) {
5255 return "";
5256 }
5257 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5258 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5259 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
5263 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005264
5265 /**
5266 * Scans for available networks.
5267 */
5268 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005269 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5270 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5272 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005273 LocationAccessPolicy.LocationPermissionResult locationResult =
5274 LocationAccessPolicy.checkLocationPermission(mApp,
5275 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5276 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005277 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005278 .setCallingPid(Binder.getCallingPid())
5279 .setCallingUid(Binder.getCallingUid())
5280 .setMethod("getCellNetworkScanResults")
5281 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5282 .build());
5283 switch (locationResult) {
5284 case DENIED_HARD:
5285 throw new SecurityException("Not allowed to access scan results -- location");
5286 case DENIED_SOFT:
5287 return null;
5288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289
Pengquan Menga1bb6272018-09-06 09:59:22 -07005290 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 try {
5292 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005293 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295 } finally {
5296 Binder.restoreCallingIdentity(identity);
5297 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005298 }
5299
5300 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005301 * Get the call forwarding info, given the call forwarding reason.
5302 */
5303 @Override
5304 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5305 enforceReadPrivilegedPermission("getCallForwarding");
5306 long identity = Binder.clearCallingIdentity();
5307 try {
5308 if (DBG) {
5309 log("getCallForwarding: subId " + subId
5310 + " callForwardingReason" + callForwardingReason);
5311 }
5312 return (CallForwardingInfo) sendRequest(
5313 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
5317 }
5318
5319 /**
5320 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5321 * reason, the number to forward, and the timeout before the forwarding is attempted.
5322 */
5323 @Override
5324 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5325 enforceModifyPermission();
5326 long identity = Binder.clearCallingIdentity();
5327 try {
5328 if (DBG) {
5329 log("setCallForwarding: subId " + subId
5330 + " callForwardingInfo" + callForwardingInfo);
5331 }
5332 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
5336 }
5337
5338 /**
5339 * Get the call forwarding info, given the call forwarding reason.
5340 */
5341 @Override
5342 public int getCallWaitingStatus(int subId) {
5343 enforceReadPrivilegedPermission("getCallForwarding");
5344 long identity = Binder.clearCallingIdentity();
5345 try {
5346 if (DBG) log("getCallWaitingStatus: subId " + subId);
5347 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
5350 }
5351 }
5352
5353 /**
5354 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5355 * reason, the number to forward, and the timeout before the forwarding is attempted.
5356 */
5357 @Override
5358 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5359 enforceModifyPermission();
5360 long identity = Binder.clearCallingIdentity();
5361 try {
5362 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5363 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5364 } finally {
5365 Binder.restoreCallingIdentity(identity);
5366 }
5367 }
5368
5369 /**
yinxub1bed742017-04-17 11:45:04 -07005370 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005371 *
yinxub1bed742017-04-17 11:45:04 -07005372 * @param subId id of the subscription
5373 * @param request contains the radio access networks with bands/channels to scan
5374 * @param messenger callback messenger for scan results or errors
5375 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005376 * @return the id of the requested scan which can be used to stop the scan.
5377 */
5378 @Override
5379 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005380 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5382 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005383 LocationAccessPolicy.LocationPermissionResult locationResult =
5384 LocationAccessPolicy.checkLocationPermission(mApp,
5385 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5386 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005387 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005388 .setCallingPid(Binder.getCallingPid())
5389 .setCallingUid(Binder.getCallingUid())
5390 .setMethod("requestNetworkScan")
5391 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5392 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005393 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005394 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005395 if (e != null) {
5396 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5397 throw e;
5398 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005399 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005400 return TelephonyScanManager.INVALID_SCAN_ID;
5401 }
5402 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 }
Hall Liu912dfd32019-04-25 14:02:26 -07005404 int callingUid = Binder.getCallingUid();
5405 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005406 final long identity = Binder.clearCallingIdentity();
5407 try {
5408 return mNetworkScanRequestTracker.startNetworkScan(
5409 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005410 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
yinxu504e1392017-04-12 16:03:22 -07005414 }
5415
Hall Liub2ac8ef2019-02-28 15:56:23 -08005416 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005417 NetworkScanRequest request, int subId) {
5418 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5419 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5420 boolean hasNetworkScanPermission =
5421 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5422 == PERMISSION_GRANTED;
5423
5424 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5425 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5426 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005427 }
5428
5429 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5430 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005431 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5432 return new SecurityException("Specific channels must not be"
5433 + " scanned without location access.");
5434 }
5435 }
5436 }
5437
Hall Liub2ac8ef2019-02-28 15:56:23 -08005438 return null;
5439 }
5440
yinxu504e1392017-04-12 16:03:22 -07005441 /**
5442 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005443 *
5444 * @param subId id of the subscription
5445 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005446 */
5447 @Override
5448 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5450 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451
Hall Liu912dfd32019-04-25 14:02:26 -07005452 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453 final long identity = Binder.clearCallingIdentity();
5454 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005455 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458 }
yinxu504e1392017-04-12 16:03:22 -07005459 }
5460
5461 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005462 * Get the calculated preferred network type.
5463 * Used for debugging incorrect network type.
5464 *
5465 * @return the preferred network type, defined in RILConstants.java.
5466 */
5467 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005468 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005469 final Phone defaultPhone = getDefaultPhone();
5470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005471 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005472 return RILConstants.PREFERRED_NETWORK_MODE;
5473 }
5474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 final long identity = Binder.clearCallingIdentity();
5476 try {
5477 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005478 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
Junda Liu84d15a22014-07-02 11:21:04 -07005482 }
5483
5484 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005485 * Get the preferred network type.
5486 * Used for device configuration by some CDMA operators.
5487 *
5488 * @return the preferred network type, defined in RILConstants.java.
5489 */
5490 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005491 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005492 TelephonyPermissions
5493 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5494 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495
5496 final long identity = Binder.clearCallingIdentity();
5497 try {
5498 if (DBG) log("getPreferredNetworkType");
5499 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5500 int networkType = (result != null ? result[0] : -1);
5501 if (DBG) log("getPreferredNetworkType: " + networkType);
5502 return networkType;
5503 } finally {
5504 Binder.restoreCallingIdentity(identity);
5505 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005506 }
5507
5508 /**
5509 * Set the preferred network type.
5510 * Used for device configuration by some CDMA operators.
5511 *
5512 * @param networkType the preferred network type, defined in RILConstants.java.
5513 * @return true on success; false on any failure.
5514 */
5515 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005516 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5518 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519
5520 final long identity = Binder.clearCallingIdentity();
5521 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005522 Settings.Global.putInt(mApp.getContentResolver(),
5523 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5524 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005527 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005528 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005529
5530 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005531 * Get the allowed network types that store in the telephony provider.
5532 *
5533 * @param subId the id of the subscription.
5534 * @return allowedNetworkTypes the allowed network types.
5535 */
5536 @Override
5537 public long getAllowedNetworkTypes(int subId) {
5538 TelephonyPermissions
5539 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5540 mApp, subId, "getAllowedNetworkTypes");
5541
5542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 return SubscriptionManager.getLongSubscriptionProperty(
5545 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
5549 }
5550
5551 /**
5552 * Set the allowed network types.
5553 *
5554 * @param subId the id of the subscription.
5555 * @param allowedNetworkTypes the allowed network types.
5556 * @return true on success; false on any failure.
5557 */
5558 @Override
5559 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5561 mApp, subId, "setAllowedNetworkTypes");
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 SubscriptionManager.setSubscriptionProperty(subId,
5565 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5566 String.valueOf(allowedNetworkTypes));
5567 return setPreferredNetworkTypesInternal(subId);
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
5571 }
5572
5573 private boolean setPreferredNetworkTypesInternal(int subId) {
5574 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5575 Settings.Global.getInt(mApp.getContentResolver(),
5576 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5577 RILConstants.PREFERRED_NETWORK_MODE));
5578 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5579 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5580 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5581 (int) (networkTypeBitMask & allowedNetworkTypes));
5582
5583 if (DBG) {
5584 log("setPreferredNetworkTypesInternal: subId " + subId
5585 + " networkTypes " + networkTypeBitMask
5586 + " allowedNetworkTypes " + allowedNetworkTypes
5587 + " networkMode " + networkMode);
5588 }
5589
5590 Boolean success = (Boolean) sendRequest(
5591 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5592 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5593 return success;
5594 }
5595
5596 /**
Miaoa84611c2019-03-15 09:21:10 +08005597 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005598 *
Miaoa84611c2019-03-15 09:21:10 +08005599 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005600 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005601 * @hide
5602 */
5603 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005604 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005605 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005607 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 try {
Miaoa84611c2019-03-15 09:21:10 +08005609 if (phone != null) {
5610 return phone.hasMatchedTetherApnSetting();
5611 } else {
5612 return false;
5613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 } finally {
5615 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005616 }
Junda Liu475951f2014-11-07 16:45:03 -08005617 }
5618
5619 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005620 * Set mobile data enabled
5621 * Used by the user through settings etc to turn on/off mobile data
5622 *
5623 * @param enable {@code true} turn turn data on, else {@code false}
5624 */
5625 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005626 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5628 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629
5630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 int phoneId = mSubscriptionController.getPhoneId(subId);
5633 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5634 Phone phone = PhoneFactory.getPhone(phoneId);
5635 if (phone != null) {
5636 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005637 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005639 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 }
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005643 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005644 }
5645
5646 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005647 * Enable or disable always reporting signal strength changes from radio.
5648 *
5649 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5650 */
5651 @Override
5652 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5653 enforceModifyPermission();
5654 enforceSystemCaller();
5655
5656 final long identity = Binder.clearCallingIdentity();
5657 final Phone phone = getPhone(subId);
5658 try {
5659 if (phone != null) {
5660 if (DBG) {
5661 log("setAlwaysReportSignalStrength: subId=" + subId
5662 + " isEnable=" + isEnable);
5663 }
5664 phone.setAlwaysReportSignalStrength(isEnable);
5665 } else {
5666 loge("setAlwaysReportSignalStrength: no phone found for subId="
5667 + subId);
5668 }
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
5672 }
5673
5674 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005675 * Get the user enabled state of Mobile Data.
5676 *
5677 * TODO: remove and use isUserDataEnabled.
5678 * This can't be removed now because some vendor codes
5679 * calls through ITelephony directly while they should
5680 * use TelephonyManager.
5681 *
5682 * @return true on enabled
5683 */
5684 @Override
5685 public boolean getDataEnabled(int subId) {
5686 return isUserDataEnabled(subId);
5687 }
5688
5689 /**
5690 * Get whether mobile data is enabled per user setting.
5691 *
5692 * There are other factors deciding whether mobile data is actually enabled, but they are
5693 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005694 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005695 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005696 *
5697 * @return {@code true} if data is enabled else {@code false}
5698 */
5699 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005700 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005701 try {
5702 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5703 null);
5704 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5706 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708
5709 final long identity = Binder.clearCallingIdentity();
5710 try {
5711 int phoneId = mSubscriptionController.getPhoneId(subId);
5712 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5713 Phone phone = PhoneFactory.getPhone(phoneId);
5714 if (phone != null) {
5715 boolean retVal = phone.isUserDataEnabled();
5716 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5717 return retVal;
5718 } else {
5719 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5720 return false;
5721 }
5722 } finally {
5723 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005724 }
5725 }
5726
5727 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005728 * Checks if the device is capable of mobile data by considering whether whether the
5729 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5730 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005731 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005732 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005733 */
5734 @Override
5735 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005736 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737
5738 final long identity = Binder.clearCallingIdentity();
5739 try {
5740 int phoneId = mSubscriptionController.getPhoneId(subId);
5741 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5742 Phone phone = PhoneFactory.getPhone(phoneId);
5743 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005744 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5746 return retVal;
5747 } else {
5748 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5749 return false;
5750 }
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005753 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005754 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005755
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005756 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5757 Phone phone) {
5758 //load access rules from carrier configs, and check those as well: b/139133814
5759 SubscriptionController subController = SubscriptionController.getInstance();
5760 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5761 || subController == null) return privilegeFromSim;
5762
5763 int uid = Binder.getCallingUid();
5764 PackageManager pkgMgr = phone.getContext().getPackageManager();
5765 String[] packages = pkgMgr.getPackagesForUid(uid);
5766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5770 SubscriptionManager subManager = (SubscriptionManager)
5771 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5772 for (String pkg : packages) {
5773 if (subManager.canManageSubscription(subInfo, pkg)) {
5774 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5775 }
5776 }
5777 return privilegeFromSim;
5778 } finally {
5779 Binder.restoreCallingIdentity(identity);
5780 }
5781 }
5782
5783 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5784 String pkgName) {
5785 //load access rules from carrier configs, and check those as well: b/139133814
5786 SubscriptionController subController = SubscriptionController.getInstance();
5787 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5788 || subController == null) return privilegeFromSim;
5789
5790 final long identity = Binder.clearCallingIdentity();
5791 try {
5792 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5793 SubscriptionManager subManager = (SubscriptionManager)
5794 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5795 return subManager.canManageSubscription(subInfo, pkgName)
5796 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
5800 }
5801
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005802 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005803 public int getCarrierPrivilegeStatus(int subId) {
5804 final Phone phone = getPhone(subId);
5805 if (phone == null) {
5806 loge("getCarrierPrivilegeStatus: Invalid subId");
5807 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5808 }
5809 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005810 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005811 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005812 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5813 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005814
5815 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5816 card.getCarrierPrivilegeStatusForCurrentTransaction(
5817 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005818 }
Junda Liu29340342014-07-10 15:23:27 -07005819
5820 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005821 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005822 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005823 final Phone phone = getPhone(subId);
5824 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005825 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005826 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5827 }
5828 UiccProfile profile =
5829 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5830 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005831 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005832 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5833 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005834 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005835 profile.getCarrierPrivilegeStatusForUid(
5836 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005837 }
5838
5839 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005840 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5841 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005842 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005843 }
5844
5845 int phoneId = SubscriptionManager.getPhoneId(subId);
5846 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005847 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005848 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005849 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5850 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005851 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5852 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5853 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005854 }
5855
5856 @Override
5857 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005858 if (TextUtils.isEmpty(pkgName))
5859 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005860 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5861 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5862 UiccCard card = UiccController.getInstance().getUiccCard(i);
5863 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005864 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005865 continue;
5866 }
5867
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005868 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5869 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5870 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005871 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5872 break;
5873 }
5874 }
5875
5876 return result;
Junda Liu29340342014-07-10 15:23:27 -07005877 }
Derek Tan89e89d42014-07-08 17:00:10 -07005878
5879 @Override
Junda Liue64de782015-04-16 17:19:16 -07005880 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5881 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5882 loge("phoneId " + phoneId + " is not valid.");
5883 return null;
5884 }
5885 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005886 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005887 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005888 return null ;
5889 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005890 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005891 }
5892
Amith Yamasani6e118872016-02-19 12:53:51 -08005893 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005894 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005895 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005896 List<String> privilegedPackages = new ArrayList<>();
5897 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005898 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5899 // has UICC in that slot.
5900 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005901 if (card.hasCarrierPrivilegeRules()) {
5902 if (packages == null) {
5903 // Only check packages in user 0 for now
5904 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005905 PackageManager.MATCH_DISABLED_COMPONENTS
5906 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005907 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005908 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005909 }
5910 for (int p = packages.size() - 1; p >= 0; p--) {
5911 PackageInfo pkgInfo = packages.get(p);
5912 if (pkgInfo != null && pkgInfo.packageName != null
5913 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005914 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005915 privilegedPackages.add(pkgInfo.packageName);
5916 }
5917 }
5918 }
5919 }
5920 return privilegedPackages;
5921 }
5922
chen xuf7e9fe82019-05-09 19:31:02 -07005923 @Override
5924 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005925 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5926
5927 final long identity = Binder.clearCallingIdentity();
5928
chen xuf7e9fe82019-05-09 19:31:02 -07005929 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005930 try {
5931 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5932 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5933 }
5934 } finally {
5935 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005936 }
5937 return privilegedPackages;
5938 }
5939
Wink Savilleb564aae2014-10-23 10:18:09 -07005940 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005941 final Phone phone = getPhone(subId);
5942 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005943 if (card == null) {
5944 loge("getIccId: No UICC");
5945 return null;
5946 }
5947 String iccId = card.getIccId();
5948 if (TextUtils.isEmpty(iccId)) {
5949 loge("getIccId: ICC ID is null or empty.");
5950 return null;
5951 }
5952 return iccId;
5953 }
5954
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005955 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005956 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5957 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005958 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005959 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 final long identity = Binder.clearCallingIdentity();
5962 try {
5963 final String iccId = getIccId(subId);
5964 final Phone phone = getPhone(subId);
5965 if (phone == null) {
5966 return false;
5967 }
5968 final String subscriberId = phone.getSubscriberId();
5969
5970 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005971 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 + subscriberId + " to " + number);
5973 }
5974
5975 if (TextUtils.isEmpty(iccId)) {
5976 return false;
5977 }
5978
5979 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5980
5981 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5982 if (alphaTag == null) {
5983 editor.remove(alphaTagPrefKey);
5984 } else {
5985 editor.putString(alphaTagPrefKey, alphaTag);
5986 }
5987
5988 // Record both the line number and IMSI for this ICCID, since we need to
5989 // track all merged IMSIs based on line number
5990 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5991 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5992 if (number == null) {
5993 editor.remove(numberPrefKey);
5994 editor.remove(subscriberPrefKey);
5995 } else {
5996 editor.putString(numberPrefKey, number);
5997 editor.putString(subscriberPrefKey, subscriberId);
5998 }
5999
6000 editor.commit();
6001 return true;
6002 } finally {
6003 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006004 }
Derek Tan7226c842014-07-02 17:42:23 -07006005 }
6006
6007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006008 public String getLine1NumberForDisplay(int subId, String callingPackage,
6009 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006010 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006012 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006013 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006014 return null;
6015 }
Derek Tan97ebb422014-09-05 16:55:38 -07006016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 final long identity = Binder.clearCallingIdentity();
6018 try {
6019 String iccId = getIccId(subId);
6020 if (iccId != null) {
6021 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6022 if (DBG_MERGE) {
6023 log("getLine1NumberForDisplay returning "
6024 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6025 }
6026 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6029 return null;
6030 } finally {
6031 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006032 }
Derek Tan7226c842014-07-02 17:42:23 -07006033 }
6034
6035 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006036 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6037 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006039 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006040 return null;
6041 }
Derek Tan97ebb422014-09-05 16:55:38 -07006042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043 final long identity = Binder.clearCallingIdentity();
6044 try {
6045 String iccId = getIccId(subId);
6046 if (iccId != null) {
6047 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6048 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6049 }
6050 return null;
6051 } finally {
6052 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006053 }
Derek Tan7226c842014-07-02 17:42:23 -07006054 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006055
6056 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006057 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6058 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006059 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6060 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006062 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006063 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006064 return null;
6065 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006066
Jordan Liub49b04b2019-05-06 14:45:15 -07006067 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6068 // the process, where TelephonyManager was instantiated.
6069 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006070 final long identity = Binder.clearCallingIdentity();
6071 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006072 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 final TelephonyManager tele = TelephonyManager.from(context);
6074 final SubscriptionManager sub = SubscriptionManager.from(context);
6075
6076 // Figure out what subscribers are currently active
6077 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078
Jordan Liub49b04b2019-05-06 14:45:15 -07006079 // Only consider subs which match the current subId
6080 // This logic can be simplified. See b/131189269 for progress.
6081 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006082 activeSubscriberIds.add(tele.getSubscriberId(subId));
6083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084
6085 // First pass, find a number override for an active subscriber
6086 String mergeNumber = null;
6087 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6088 for (String key : prefs.keySet()) {
6089 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6090 final String subscriberId = (String) prefs.get(key);
6091 if (activeSubscriberIds.contains(subscriberId)) {
6092 final String iccId = key.substring(
6093 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6094 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6095 mergeNumber = (String) prefs.get(numberKey);
6096 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006097 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 + " for active subscriber " + subscriberId);
6099 }
6100 if (!TextUtils.isEmpty(mergeNumber)) {
6101 break;
6102 }
6103 }
6104 }
6105 }
6106
6107 // Shortcut when no active merged subscribers
6108 if (TextUtils.isEmpty(mergeNumber)) {
6109 return null;
6110 }
6111
6112 // Second pass, find all subscribers under that line override
6113 final ArraySet<String> result = new ArraySet<>();
6114 for (String key : prefs.keySet()) {
6115 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6116 final String number = (String) prefs.get(key);
6117 if (mergeNumber.equals(number)) {
6118 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6119 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6120 final String subscriberId = (String) prefs.get(subscriberKey);
6121 if (!TextUtils.isEmpty(subscriberId)) {
6122 result.add(subscriberId);
6123 }
6124 }
6125 }
6126 }
6127
6128 final String[] resultArray = result.toArray(new String[result.size()]);
6129 Arrays.sort(resultArray);
6130 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006131 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6133 }
6134 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006135 } finally {
6136 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006137 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006138 }
6139
6140 @Override
zoey chen38003472019-12-13 17:16:31 +08006141 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6142 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006143
6144 final long identity = Binder.clearCallingIdentity();
6145 try {
6146 final TelephonyManager telephonyManager = mApp.getSystemService(
6147 TelephonyManager.class);
6148 String subscriberId = telephonyManager.getSubscriberId(subId);
6149 if (subscriberId == null) {
6150 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006151 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006152 + subId);
6153 }
6154 return null;
6155 }
6156
6157 final SubscriptionInfo info = SubscriptionController.getInstance()
6158 .getSubscriptionInfo(subId);
6159 final ParcelUuid groupUuid = info.getGroupUuid();
6160 // If it doesn't belong to any group, return just subscriberId of itself.
6161 if (groupUuid == null) {
6162 return new String[]{subscriberId};
6163 }
6164
6165 // Get all subscriberIds from the group.
6166 final List<String> mergedSubscriberIds = new ArrayList<>();
6167 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006168 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6169 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006170 for (SubscriptionInfo subInfo : groupInfos) {
6171 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6172 if (subscriberId != null) {
6173 mergedSubscriberIds.add(subscriberId);
6174 }
6175 }
6176
6177 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6178 } finally {
6179 Binder.restoreCallingIdentity(identity);
6180
6181 }
6182 }
6183
6184 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006185 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006186 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006187 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188
6189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 final Phone phone = getPhone(subId);
6192 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6193 } finally {
6194 Binder.restoreCallingIdentity(identity);
6195 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006196 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006197
6198 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006199 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006200 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6201 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006202 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6203 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204
6205 final long identity = Binder.clearCallingIdentity();
6206 try {
6207 final Phone phone = getPhone(subId);
6208 if (phone == null) {
6209 return false;
6210 }
6211 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6212 cdmaNonRoamingList);
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006215 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006216 }
6217
6218 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006219 @Deprecated
6220 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6221 enforceModifyPermission();
6222
6223 int returnValue = 0;
6224 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006225 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006226 if(result.exception == null) {
6227 if (result.result != null) {
6228 byte[] responseData = (byte[])(result.result);
6229 if(responseData.length > oemResp.length) {
6230 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6231 responseData.length + "bytes. Buffer Size is " +
6232 oemResp.length + "bytes.");
6233 }
6234 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6235 returnValue = responseData.length;
6236 }
6237 } else {
6238 CommandException ex = (CommandException) result.exception;
6239 returnValue = ex.getCommandError().ordinal();
6240 if(returnValue > 0) returnValue *= -1;
6241 }
6242 } catch (RuntimeException e) {
6243 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6244 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6245 if(returnValue > 0) returnValue *= -1;
6246 }
6247
6248 return returnValue;
6249 }
6250
6251 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006252 public void setRadioCapability(RadioAccessFamily[] rafs) {
6253 try {
6254 ProxyController.getInstance().setRadioCapability(rafs);
6255 } catch (RuntimeException e) {
6256 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6257 }
6258 }
6259
6260 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006261 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006262 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006263 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006264 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006265 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006266 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 final long identity = Binder.clearCallingIdentity();
6268 try {
chen xub97461a2018-10-26 14:17:57 -07006269 TelephonyPermissions
6270 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6271 mApp, phone.getSubId(), "getRadioAccessFamily");
6272 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
chen xub97461a2018-10-26 14:17:57 -07006276 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006277 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006278
6279 @Override
6280 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006281 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006282 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283
6284 final long identity = Binder.clearCallingIdentity();
6285 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006286 ImsManager.getInstance(defaultPhone.getContext(),
6287 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006291 }
6292
6293 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006294 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006295 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6297 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006298 return false;
6299 }
Svet Ganovb320e182015-04-16 12:30:10 -07006300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 final long identity = Binder.clearCallingIdentity();
6302 try {
6303 // Check the user preference and the system-level IMS setting. Even if the user has
6304 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6305 // In the long run, we may instead need to check if there exists a connection service
6306 // which can support video calling.
6307 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006308 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 return imsManager.isVtEnabledByPlatform()
6310 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6311 && imsManager.isVtEnabledByUser();
6312 } finally {
6313 Binder.restoreCallingIdentity(identity);
6314 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006315 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006316
Andrew Leea1239f22015-03-02 17:44:07 -08006317 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006318 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6319 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006321 mApp, subId, callingPackage, callingFeatureId,
6322 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 return false;
6324 }
6325
6326 final long identity = Binder.clearCallingIdentity();
6327 try {
6328 CarrierConfigManager configManager =
6329 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006330 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
Andrew Leea1239f22015-03-02 17:44:07 -08006335 }
6336
6337 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006338 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006340 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341 return false;
6342 }
6343
6344 final long identity = Binder.clearCallingIdentity();
6345 try {
6346 CarrierConfigManager configManager =
6347 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006348 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006349 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6350 } finally {
6351 Binder.restoreCallingIdentity(identity);
6352 }
Andrew Leea1239f22015-03-02 17:44:07 -08006353 }
6354
Andrew Lee9431b832015-03-09 18:46:45 -07006355 @Override
6356 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006357 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006358 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006359 }
6360
6361 @Override
6362 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363 final long identity = Binder.clearCallingIdentity();
6364 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006365 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006366 } finally {
6367 Binder.restoreCallingIdentity(identity);
6368 }
Andrew Lee9431b832015-03-09 18:46:45 -07006369 }
6370
Hall Liuf6668912018-10-31 17:05:23 -07006371 /**
6372 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6373 * support for the feature and device firmware support.
6374 *
6375 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6376 */
6377 @Override
6378 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006380 final Phone phone = getPhone(subscriptionId);
6381 if (phone == null) {
6382 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6383 return false;
6384 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006386 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6388 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006389 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 return isCarrierSupported && isDeviceSupported;
6391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
Hall Liu98187582018-01-22 19:15:32 -08006394 }
6395
Hall Liuf6668912018-10-31 17:05:23 -07006396 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006397 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6398 * RTT setting, will return true if the device and carrier both support RTT.
6399 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006400 */
6401 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 final long identity = Binder.clearCallingIdentity();
6403 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006404 boolean isRttSupported = isRttSupported(subscriptionId);
6405 boolean isUserRttSettingOn = Settings.Secure.getInt(
6406 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6407 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6408 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6409 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 } finally {
6411 Binder.restoreCallingIdentity(identity);
6412 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006413 }
6414
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006415 @Deprecated
6416 @Override
6417 public String getDeviceId(String callingPackage) {
6418 return getDeviceIdWithFeature(callingPackage, null);
6419 }
6420
Sanket Padawe7310cc72015-01-14 09:53:20 -08006421 /**
6422 * Returns the unique device ID of phone, for example, the IMEI for
6423 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6424 *
6425 * <p>Requires Permission:
6426 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6427 */
6428 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006429 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006430 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006431 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006432 return null;
6433 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006434 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006435 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006436 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006437 return null;
6438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439
6440 final long identity = Binder.clearCallingIdentity();
6441 try {
6442 return phone.getDeviceId();
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006446 }
6447
Ping Sunc67b7c22016-03-02 19:16:45 +08006448 /**
6449 * {@hide}
6450 * Returns the IMS Registration Status on a particular subid
6451 *
6452 * @param subId
6453 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006454 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006455 Phone phone = getPhone(subId);
6456 if (phone != null) {
6457 return phone.isImsRegistered();
6458 } else {
6459 return false;
6460 }
6461 }
6462
Santos Cordon7a1885b2015-02-03 11:15:19 -08006463 @Override
6464 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006471 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006472
Tyler Gunnf70ed162019-04-03 15:28:53 -07006473 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006474 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006475 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006477 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006478 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6479 }
6480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
6486 }
6487
6488 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006489 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6490 final long identity = Binder.clearCallingIdentity();
6491 try {
6492 Phone phone = getPhone(subscriptionId);
6493 if (phone == null) {
6494 return null;
6495 }
6496 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
6500 }
6501
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006502 /**
6503 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006504 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006505 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 Phone phone = getPhone(subId);
6509 if (phone != null) {
6510 return phone.isWifiCallingEnabled();
6511 } else {
6512 return false;
6513 }
6514 } finally {
6515 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006516 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006517 }
6518
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006519 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006520 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006521 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006522 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523 final long identity = Binder.clearCallingIdentity();
6524 try {
6525 Phone phone = getPhone(subId);
6526 if (phone != null) {
6527 return phone.isVideoEnabled();
6528 } else {
6529 return false;
6530 }
6531 } finally {
6532 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006533 }
6534 }
6535
6536 /**
6537 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6538 * defined in {@link ImsRegistrationImplBase}.
6539 */
6540 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 final long identity = Binder.clearCallingIdentity();
6542 try {
6543 Phone phone = getPhone(subId);
6544 if (phone != null) {
6545 return phone.getImsRegistrationTech();
6546 } else {
6547 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6548 }
6549 } finally {
6550 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006551 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006552 }
6553
Stuart Scott8eef64f2015-04-08 15:13:54 -07006554 @Override
6555 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006556 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006557 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6558 return;
6559 }
6560
Svet Ganovcc087f82015-05-12 20:35:54 -07006561 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006562
Svet Ganovcc087f82015-05-12 20:35:54 -07006563 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006564 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6565 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006566 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006567 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006568 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006569 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6570 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006571 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006572 // There has been issues when Sms raw table somehow stores orphan
6573 // fragments. They lead to garbled message when new fragments come
6574 // in and combined with those stale ones. In case this happens again,
6575 // user can reset all network settings which will clean up this table.
6576 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006577 // Clean up IMS settings as well here.
6578 int slotId = getSlotIndex(subId);
6579 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6580 ImsManager.getInstance(mApp, slotId).factoryReset();
6581 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006582
6583 // Erase modem config if erase modem on network setting is enabled.
6584 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6585 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6586 if (configValue != null && Boolean.parseBoolean(configValue)) {
6587 sendEraseModemConfig(getDefaultPhone());
6588 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006589 } finally {
6590 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006591 }
6592 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006593
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006594 private void cleanUpSmsRawTable(Context context) {
6595 ContentResolver resolver = context.getContentResolver();
6596 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6597 resolver.delete(uri, null, null);
6598 }
6599
Narayan Kamath1c496c22015-04-16 14:40:19 +01006600 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006601 public String getSimLocaleForSubscriber(int subId) {
6602 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6603 final Phone phone = getPhone(subId);
6604 if (phone == null) {
6605 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006606 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608 final long identity = Binder.clearCallingIdentity();
6609 try {
chen xu5d3637b2019-01-21 23:31:38 -08006610 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006611 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006612 if (info == null) {
6613 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6614 return null;
6615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 // Try and fetch the locale from the carrier properties or from the SIM language
6617 // preferences (EF-PL and EF-LI)...
6618 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006620 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6621 if (localeFromDefaultSim != null) {
6622 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6623 if (DBG) log("Using locale from subId: " + subId + " locale: "
6624 + localeFromDefaultSim);
6625 return localeFromDefaultSim.toLanguageTag();
6626 } else {
6627 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 }
6629 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631 // The SIM language preferences only store a language (e.g. fr = French), not an
6632 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6633 // the SIM and carrier preferences does not include a country we add the country
6634 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006635 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006637 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638 return mccLocale.toLanguageTag();
6639 }
6640
6641 if (DBG) log("No locale found - returning null");
6642 return null;
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006646 }
6647
6648 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006649 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6650 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006651 }
6652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 /**
6654 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6655 */
6656 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006657 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6658 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006659 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006660
Chenjie Yu1ba97252018-01-11 18:16:20 -08006661 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006662 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006663
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006664 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006665 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6666 * representing the state of the modem.
6667 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006668 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6669 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006670 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006671 */
6672 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006673 public void requestModemActivityInfo(ResultReceiver result) {
6674 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006675 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676
6677 final long identity = Binder.clearCallingIdentity();
6678 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006679 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 } finally {
6681 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006682 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006683 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006684
Siddharth Rayb8114062018-06-17 15:02:38 -07006685 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6686 // less than total activity duration.
6687 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6688 if (info == null) {
6689 return false;
6690 }
6691 int activityDurationMs =
6692 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6693 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006694 int[] txTimeMs = info.getTransmitTimeMillis();
6695 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6696 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006697 }
6698 return (info.isValid()
6699 && (info.getSleepTimeMillis() <= activityDurationMs)
6700 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006701 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006702 && (totalTxTimeMs <= activityDurationMs));
6703 }
6704
Jack Yu85bd38a2015-11-09 11:34:32 -08006705 /**
6706 * {@hide}
6707 * Returns the service state information on specified subscription.
6708 */
6709 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006710 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6711 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006713 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006714 return null;
6715 }
6716
Hall Liuf19c44f2018-11-27 14:38:17 -08006717 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6718 LocationAccessPolicy.checkLocationPermission(mApp,
6719 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6720 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006721 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006722 .setCallingPid(Binder.getCallingPid())
6723 .setCallingUid(Binder.getCallingUid())
6724 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006725 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006726 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6727 .build());
6728
6729 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6730 LocationAccessPolicy.checkLocationPermission(mApp,
6731 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6732 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006733 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006734 .setCallingPid(Binder.getCallingPid())
6735 .setCallingUid(Binder.getCallingUid())
6736 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006737 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006738 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6739 .build());
6740 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6741 boolean hasFinePermission =
6742 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6743 boolean hasCoarsePermission =
6744 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 final long identity = Binder.clearCallingIdentity();
6747 try {
6748 final Phone phone = getPhone(subId);
6749 if (phone == null) {
6750 return null;
6751 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006752
Hall Liuf19c44f2018-11-27 14:38:17 -08006753 ServiceState ss = phone.getServiceState();
6754
6755 // Scrub out the location info in ServiceState depending on what level of access
6756 // the caller has.
6757 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006758 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6759 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 } finally {
6761 Binder.restoreCallingIdentity(identity);
6762 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006763 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006764
6765 /**
6766 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6767 *
6768 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6769 * voicemail ringtone.
6770 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6771 * PhoneAccount.
6772 */
6773 @Override
6774 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 final long identity = Binder.clearCallingIdentity();
6776 try {
6777 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6778 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006779 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006786 }
6787
6788 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006789 * Sets the per-account voicemail ringtone.
6790 *
6791 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6792 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6793 *
6794 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6795 * voicemail ringtone.
6796 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6797 * PhoneAccount.
6798 */
6799 @Override
6800 public void setVoicemailRingtoneUri(String callingPackage,
6801 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006802 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006803 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006804 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6805 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6807 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6808 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006809 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810
6811 final long identity = Binder.clearCallingIdentity();
6812 try {
6813 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6814 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006815 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 }
6817 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006820 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006821 }
6822
6823 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006824 * Returns whether vibration is set for voicemail notification in Phone settings.
6825 *
6826 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6827 * voicemail vibration setting.
6828 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6829 */
6830 @Override
6831 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 final long identity = Binder.clearCallingIdentity();
6833 try {
6834 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6835 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006836 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006843 }
6844
Youhan Wange64578a2016-05-02 15:32:42 -07006845 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006846 * Sets the per-account voicemail vibration.
6847 *
6848 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6849 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6850 *
6851 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6852 * voicemail vibration setting.
6853 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6854 * specific PhoneAccount.
6855 */
6856 @Override
6857 public void setVoicemailVibrationEnabled(String callingPackage,
6858 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006859 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006860 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006861 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6862 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6864 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6865 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006866 }
6867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 final long identity = Binder.clearCallingIdentity();
6869 try {
6870 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6871 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006872 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 }
6874 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006877 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006878 }
6879
6880 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006881 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6882 *
6883 * @throws SecurityException if the caller does not have the required permission
6884 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006885 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006886 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006887 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006888 }
6889
6890 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006891 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6892 * permission.
6893 *
6894 * @throws SecurityException if the caller does not have the required permission
6895 */
6896 private void enforceSendSmsPermission() {
6897 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6898 }
6899
6900 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006901 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006902 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006903 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006904 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006905 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 final long identity = Binder.clearCallingIdentity();
6907 try {
6908 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006909 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 if (componentName == null) {
6911 throw new SecurityException(
6912 "Caller not current active visual voicemail package[null]");
6913 }
6914 String vvmPackage = componentName.getPackageName();
6915 if (!callingPackage.equals(vvmPackage)) {
6916 throw new SecurityException("Caller not current active visual voicemail package["
6917 + vvmPackage + "]");
6918 }
6919 } finally {
6920 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006921 }
6922 }
6923
6924 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006925 * Return the application ID for the app type.
6926 *
6927 * @param subId the subscription ID that this request applies to.
6928 * @param appType the uicc app type.
6929 * @return Application ID for specificied app type, or null if no uicc.
6930 */
6931 @Override
6932 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006933 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006934 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006935
6936 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006937 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938 if (phone == null) {
6939 return null;
6940 }
6941 String aid = null;
6942 try {
6943 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6944 .getApplicationByType(appType).getAid();
6945 } catch (Exception e) {
6946 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6947 }
6948 return aid;
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006951 }
Youhan Wange64578a2016-05-02 15:32:42 -07006952 }
6953
Youhan Wang4001d252016-05-11 10:29:41 -07006954 /**
6955 * Return the Electronic Serial Number.
6956 *
6957 * @param subId the subscription ID that this request applies to.
6958 * @return ESN or null if error.
6959 */
6960 @Override
6961 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006962 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006963 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964
6965 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006966 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 if (phone == null) {
6968 return null;
6969 }
6970 String esn = null;
6971 try {
6972 esn = phone.getEsn();
6973 } catch (Exception e) {
6974 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6975 }
6976 return esn;
6977 } finally {
6978 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006979 }
Youhan Wang4001d252016-05-11 10:29:41 -07006980 }
6981
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006982 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006983 * Return the Preferred Roaming List Version.
6984 *
6985 * @param subId the subscription ID that this request applies to.
6986 * @return PRLVersion or null if error.
6987 */
6988 @Override
6989 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006990 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006991 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992
6993 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006994 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 if (phone == null) {
6996 return null;
6997 }
6998 String cdmaPrlVersion = null;
6999 try {
7000 cdmaPrlVersion = phone.getCdmaPrlVersion();
7001 } catch (Exception e) {
7002 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7003 }
7004 return cdmaPrlVersion;
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007007 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007008 }
7009
7010 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007011 * Get snapshot of Telephony histograms
7012 * @return List of Telephony histograms
7013 * @hide
7014 */
7015 @Override
7016 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7018 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 return RIL.getTelephonyRILTimingHistograms();
7023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007026 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007027
7028 /**
7029 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007030 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7031 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007032 * Require system privileges. In the future we may add this to carrier APIs.
7033 *
Michele Berionne482f8202018-11-27 18:57:59 -08007034 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007035 */
7036 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007037 @TelephonyManager.SetCarrierRestrictionResult
7038 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007039 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007040 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007041
Michele Berionne482f8202018-11-27 18:57:59 -08007042 if (carrierRestrictionRules == null) {
7043 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007044 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 final long identity = Binder.clearCallingIdentity();
7047 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007048 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007049 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007053 }
7054
7055 /**
7056 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007057 * Get the allowed carrier list and the excluded carrier list, including the priority between
7058 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007059 * Require system privileges. In the future we may add this to carrier APIs.
7060 *
Michele Berionne482f8202018-11-27 18:57:59 -08007061 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007062 */
7063 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007064 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007065 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007066 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067
7068 final long identity = Binder.clearCallingIdentity();
7069 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007070 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7071 if (response instanceof CarrierRestrictionRules) {
7072 return (CarrierRestrictionRules) response;
7073 }
7074 // Response is an Exception of some kind,
7075 // which is signalled to the user as a NULL retval
7076 return null;
7077 } catch (Exception e) {
7078 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7079 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 } finally {
7081 Binder.restoreCallingIdentity(identity);
7082 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007083 }
7084
fionaxu59545b42016-05-25 15:53:37 -07007085 /**
7086 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7087 * @param subId the subscription ID that this action applies to.
7088 * @param enabled control enable or disable metered apns.
7089 * {@hide}
7090 */
7091 @Override
7092 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7093 enforceModifyPermission();
7094 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095
7096 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007097 if (phone == null) {
7098 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7099 return;
7100 }
7101 try {
7102 phone.carrierActionSetMeteredApnsEnabled(enabled);
7103 } catch (Exception e) {
7104 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 } finally {
7106 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007107 }
7108 }
7109
7110 /**
7111 * Action set from carrier signalling broadcast receivers to enable/disable radio
7112 * @param subId the subscription ID that this action applies to.
7113 * @param enabled control enable or disable radio.
7114 * {@hide}
7115 */
7116 @Override
7117 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7118 enforceModifyPermission();
7119 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120
7121 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007122 if (phone == null) {
7123 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7124 return;
7125 }
7126 try {
7127 phone.carrierActionSetRadioEnabled(enabled);
7128 } catch (Exception e) {
7129 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130 } finally {
7131 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007132 }
7133 }
7134
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007135 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007136 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7137 * network status based on which carrier apps could apply actions accordingly,
7138 * enable/disable default url handler for example.
7139 *
7140 * @param subId the subscription ID that this action applies to.
7141 * @param report control start/stop reporting the default network status.
7142 * {@hide}
7143 */
7144 @Override
7145 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7146 enforceModifyPermission();
7147 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148
7149 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007150 if (phone == null) {
7151 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7152 return;
7153 }
7154 try {
7155 phone.carrierActionReportDefaultNetworkStatus(report);
7156 } catch (Exception e) {
7157 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 } finally {
7159 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007160 }
7161 }
7162
7163 /**
fionaxud9622282017-07-17 17:51:30 -07007164 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7165 * @param subId the subscription ID that this action applies to.
7166 * {@hide}
7167 */
7168 @Override
7169 public void carrierActionResetAll(int subId) {
7170 enforceModifyPermission();
7171 final Phone phone = getPhone(subId);
7172 if (phone == null) {
7173 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7174 return;
7175 }
7176 try {
7177 phone.carrierActionResetAll();
7178 } catch (Exception e) {
7179 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7180 }
7181 }
7182
7183 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007184 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7185 * bug report is being generated.
7186 */
7187 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007188 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007189 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7190 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007191 writer.println("Permission Denial: can't dump Phone from pid="
7192 + Binder.getCallingPid()
7193 + ", uid=" + Binder.getCallingUid()
7194 + "without permission "
7195 + android.Manifest.permission.DUMP);
7196 return;
7197 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007198 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007199 }
Jack Yueb89b242016-06-22 13:27:47 -07007200
Brad Ebingerdac2f002018-04-03 15:17:52 -07007201 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007202 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7203 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7204 @NonNull String[] args) {
7205 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7206 this, in.getFileDescriptor(), out.getFileDescriptor(),
7207 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007208 }
7209
Jack Yueb89b242016-06-22 13:27:47 -07007210 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007211 * Policy control of data connection. Usually used when data limit is passed.
7212 * @param enabled True if enabling the data, otherwise disabling.
7213 * @param subId Subscription index
7214 * {@hide}
7215 */
7216 @Override
7217 public void setPolicyDataEnabled(boolean enabled, int subId) {
7218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219
7220 final long identity = Binder.clearCallingIdentity();
7221 try {
7222 Phone phone = getPhone(subId);
7223 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007224 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225 }
7226 } finally {
7227 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007228 }
7229 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007230
7231 /**
7232 * Get Client request stats
7233 * @return List of Client Request Stats
7234 * @hide
7235 */
7236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007237 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7238 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007240 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007241 return null;
7242 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007243 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007245 final long identity = Binder.clearCallingIdentity();
7246 try {
7247 if (phone != null) {
7248 return phone.getClientRequestStats();
7249 }
7250
7251 return null;
7252 } finally {
7253 Binder.restoreCallingIdentity(identity);
7254 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007255 }
7256
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007257 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007258 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007259 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007260 }
Jack Yueb4124c2017-02-16 15:32:43 -08007261
7262 /**
Grace Chen70990072017-03-24 17:21:30 -07007263 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007264 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007265 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007266 * @param state State of SIM (power down, power up, pass through)
7267 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7268 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7269 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007270 *
7271 **/
7272 @Override
Grace Chen70990072017-03-24 17:21:30 -07007273 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007274 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007275 Phone phone = PhoneFactory.getPhone(slotIndex);
7276
vagdeviaf9a5b92018-08-15 16:01:53 -07007277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279 final long identity = Binder.clearCallingIdentity();
7280 try {
7281 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007282 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007283 }
7284 } finally {
7285 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007286 }
7287 }
Shuo Qiandd210312017-04-12 22:11:33 +00007288
Tyler Gunn65d45c22017-06-05 11:22:26 -07007289 private boolean isUssdApiAllowed(int subId) {
7290 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007291 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007292 if (configManager == null) {
7293 return false;
7294 }
7295 PersistableBundle pb = configManager.getConfigForSubId(subId);
7296 if (pb == null) {
7297 return false;
7298 }
7299 return pb.getBoolean(
7300 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7301 }
7302
Shuo Qiandd210312017-04-12 22:11:33 +00007303 /**
7304 * Check if phone is in emergency callback mode
7305 * @return true if phone is in emergency callback mode
7306 * @param subId sub id
7307 */
goneil9c5f4872017-12-05 14:07:56 -08007308 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007309 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007310 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007311 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312
7313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 if (phone != null) {
7316 return phone.isInEcm();
7317 } else {
7318 return false;
7319 }
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007322 }
7323 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007324
7325 /**
7326 * Get the current signal strength information for the given subscription.
7327 * Because this information is not updated when the device is in a low power state
7328 * it should not be relied-upon to be current.
7329 * @param subId Subscription index
7330 * @return the most recent cached signal strength info from the modem
7331 */
7332 @Override
7333 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334 final long identity = Binder.clearCallingIdentity();
7335 try {
7336 Phone p = getPhone(subId);
7337 if (p == null) {
7338 return null;
7339 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 return p.getSignalStrength();
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007345 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007346
Pengquan Meng77b7f132018-08-22 14:49:57 -07007347 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007348 * Get the current modem radio state for the given slot.
7349 * @param slotIndex slot index.
7350 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007351 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007352 * @return the current radio power state from the modem
7353 */
7354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007355 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007356 Phone phone = PhoneFactory.getPhone(slotIndex);
7357 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7359 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007360 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7361 }
7362
7363 final long identity = Binder.clearCallingIdentity();
7364 try {
7365 return phone.getRadioPowerState();
7366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
7369 }
7370 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7371 }
7372
7373 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007374 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7375 *
7376 * <p>Requires one of the following permissions:
7377 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7378 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7379 * privileges.
7380 *
7381 * @param subId subscription id
7382 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7383 * {@code false}.
7384 */
7385 @Override
7386 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007387 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7388 null /* message */);
7389
Pengquan Menga1bb6272018-09-06 09:59:22 -07007390 boolean isEnabled = false;
7391 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007392 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007393 Phone phone = getPhone(subId);
7394 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007395 } catch (Exception e) {
7396 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7397 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007398 } finally {
7399 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007400 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007401 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007402 }
7403
7404
7405 /**
7406 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7407 *
7408 * <p> Requires permission:
7409 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7410 * privileges.
7411 *
7412 * @param subId subscription id
7413 * @param isEnabled {@code true} means enable, {@code false} means disable.
7414 */
7415 @Override
7416 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7418 mApp, subId, "setDataRoamingEnabled");
7419
Pengquan Menga1bb6272018-09-06 09:59:22 -07007420 final long identity = Binder.clearCallingIdentity();
7421 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007422 Phone phone = getPhone(subId);
7423 if (phone != null) {
7424 phone.setDataRoamingEnabled(isEnabled);
7425 }
7426 } finally {
7427 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007428 }
7429 }
7430
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007431 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007432 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007433 TelephonyPermissions
7434 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007435 mApp, subId, "isManualNetworkSelectionAllowed");
7436
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007437 boolean isAllowed = true;
7438 final long identity = Binder.clearCallingIdentity();
7439 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007440 Phone phone = getPhone(subId);
7441 if (phone != null) {
7442 isAllowed = phone.isCspPlmnEnabled();
7443 }
7444 } finally {
7445 Binder.restoreCallingIdentity(identity);
7446 }
7447 return isAllowed;
7448 }
7449
7450 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007451 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu102b2772020-03-04 13:59:23 -08007452 try {
7453 PackageManager pm = mApp.getPackageManager();
7454 if (Binder.getCallingUid() != pm.getPackageUid(callingPackage, 0)) {
7455 throw new SecurityException("Calling package " + callingPackage + " does not match "
7456 + "calling UID");
7457 }
7458 } catch (PackageManager.NameNotFoundException e) {
7459 throw new SecurityException("Invalid calling package. e=" + e);
7460 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007461 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007462 try {
7463 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007464 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007465 } catch (SecurityException e) {
7466 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7467 // has carrier privileges on an active UICC
7468 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7469 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007470 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007471 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007472 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007473
7474 final long identity = Binder.clearCallingIdentity();
7475 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007476 UiccController uiccController = UiccController.getInstance();
7477 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007478 if (hasReadPermission) {
7479 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007480 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007481
7482 // Remove private info if the caller doesn't have access
7483 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7484 for (UiccCardInfo cardInfo : cardInfos) {
7485 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7486 // is available
7487 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7488 if (card == null || card.getUiccProfile() == null) {
7489 // assume no access if the card or profile is unavailable
7490 filteredInfos.add(cardInfo.getUnprivileged());
7491 continue;
7492 }
7493 UiccProfile profile = card.getUiccProfile();
7494 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7495 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7496 filteredInfos.add(cardInfo);
7497 } else {
7498 filteredInfos.add(cardInfo.getUnprivileged());
7499 }
7500 }
7501 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007502 } finally {
7503 Binder.restoreCallingIdentity(identity);
7504 }
7505 }
7506
7507 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007508 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007509 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 final long identity = Binder.clearCallingIdentity();
7512 try {
7513 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7514 if (slots == null) {
7515 Rlog.i(LOG_TAG, "slots is null.");
7516 return null;
7517 }
7518
7519 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7520 for (int i = 0; i < slots.length; i++) {
7521 UiccSlot slot = slots[i];
7522 if (slot == null) {
7523 continue;
7524 }
7525
Jordan Liu7be7e652019-05-06 18:55:02 +00007526 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 UiccCard card = slot.getUiccCard();
7528 if (card != null) {
7529 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007530 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007531 cardId = slot.getEid();
7532 if (TextUtils.isEmpty(cardId)) {
7533 cardId = slot.getIccId();
7534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 }
7536
Jordan Liu857451f2019-05-09 16:35:35 -07007537 if (cardId != null) {
7538 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7539 // if cardId is an EID, it's all digits so this is fine
7540 cardId = IccUtils.stripTrailingFs(cardId);
7541 }
7542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 int cardState = 0;
7544 switch (slot.getCardState()) {
7545 case CARDSTATE_ABSENT:
7546 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7547 break;
7548 case CARDSTATE_PRESENT:
7549 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7550 break;
7551 case CARDSTATE_ERROR:
7552 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7553 break;
7554 case CARDSTATE_RESTRICTED:
7555 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7556 break;
7557 default:
7558 break;
7559
7560 }
7561
7562 infos[i] = new UiccSlotInfo(
7563 slot.isActive(),
7564 slot.isEuicc(),
7565 cardId,
7566 cardState,
7567 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007568 slot.isExtendedApduSupported(),
7569 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 }
7571 return infos;
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007574 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007575 }
7576
7577 @Override
7578 public boolean switchSlots(int[] physicalSlots) {
7579 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580
7581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
7586 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007587 }
Jack Yu4c988042018-02-27 15:30:01 -08007588
7589 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007590 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007591 final long identity = Binder.clearCallingIdentity();
7592 try {
7593 return UiccController.getInstance().getCardIdForDefaultEuicc();
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
7596 }
7597 }
7598
Pengquan Meng85728fb2018-03-12 16:31:21 -07007599 /**
goneil47ffb6e2018-04-06 15:40:58 -07007600 * A test API to reload the UICC profile.
7601 *
7602 * <p>Requires that the calling app has permission
7603 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7604 * @hide
7605 */
7606 @Override
7607 public void refreshUiccProfile(int subId) {
7608 enforceModifyPermission();
7609
7610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 Phone phone = getPhone(subId);
7613 if (phone == null) {
7614 return;
7615 }
7616 UiccCard uiccCard = phone.getUiccCard();
7617 if (uiccCard == null) {
7618 return;
7619 }
7620 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7621 if (uiccProfile == null) {
7622 return;
7623 }
7624 uiccProfile.refresh();
7625 } finally {
7626 Binder.restoreCallingIdentity(identity);
7627 }
7628 }
7629
7630 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007631 * Returns false if the mobile data is disabled by default, otherwise return true.
7632 */
7633 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007634 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007635 }
7636
7637 /**
7638 * Returns true if the data roaming is enabled by default, i.e the system property
7639 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7640 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7641 */
7642 private boolean getDefaultDataRoamingEnabled(int subId) {
7643 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007644 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007645 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007646 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7647 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7648 return isDataRoamingEnabled;
7649 }
7650
7651 /**
7652 * Returns the default network type for the given {@code subId}, if the default network type is
7653 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7654 */
7655 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007656 List<Integer> list = TelephonyProperties.default_network();
7657 int phoneId = mSubscriptionController.getPhoneId(subId);
7658 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7659 return list.get(phoneId);
7660 }
7661 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007662 }
fionaxua13278b2018-03-21 00:08:13 -07007663
7664 @Override
7665 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007666 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007667 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668
7669 final long identity = Binder.clearCallingIdentity();
7670 try {
7671 final Phone phone = getPhone(subId);
7672 if (phone == null) {
7673 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7674 return;
7675 }
chen xueaba88a2019-03-15 13:15:10 -07007676 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7677 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 } finally {
7679 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007680 }
fionaxua13278b2018-03-21 00:08:13 -07007681 }
7682
7683 @Override
7684 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007685 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686
7687 final long identity = Binder.clearCallingIdentity();
7688 try {
7689 final Phone phone = getPhone(subId);
7690 if (phone == null) {
7691 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7692 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7693 }
7694 return phone.getCarrierIdListVersion();
7695 } finally {
7696 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007697 }
fionaxua13278b2018-03-21 00:08:13 -07007698 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007699
7700 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007701 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7702 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007704 mApp, subId, callingPackage, callingFeatureId,
7705 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007706 return -1;
7707 }
7708
7709 final long identity = Binder.clearCallingIdentity();
7710 try {
7711 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7712 } finally {
7713 Binder.restoreCallingIdentity(identity);
7714 }
7715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007716
7717 @Override
7718 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007719 TelephonyPermissions
7720 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007721 mApp, subId, "getCdmaRoamingMode");
7722
7723 final long identity = Binder.clearCallingIdentity();
7724 try {
7725 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7726 } finally {
7727 Binder.restoreCallingIdentity(identity);
7728 }
7729 }
7730
7731 @Override
7732 public boolean setCdmaRoamingMode(int subId, int mode) {
7733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7734 mApp, subId, "setCdmaRoamingMode");
7735
7736 final long identity = Binder.clearCallingIdentity();
7737 try {
7738 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7739 } finally {
7740 Binder.restoreCallingIdentity(identity);
7741 }
7742 }
7743
7744 @Override
7745 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7747 mApp, subId, "setCdmaSubscriptionMode");
7748
7749 final long identity = Binder.clearCallingIdentity();
7750 try {
7751 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7752 } finally {
7753 Binder.restoreCallingIdentity(identity);
7754 }
7755 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007756
sqianc5eccab2018-10-19 18:46:41 -07007757 @Override
sqian8c685422019-02-22 15:55:18 -08007758 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007759 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007761 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7762 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007763 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7764 }
7765 final long identity = Binder.clearCallingIdentity();
7766 try {
sqian854d44b2018-12-12 16:48:18 -08007767 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7768 for (Phone phone: PhoneFactory.getPhones()) {
7769 if (phone.getEmergencyNumberTracker() != null
7770 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7771 emergencyNumberListInternal.put(
7772 phone.getSubId(),
7773 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7774 }
sqian11b7a0e2018-12-05 18:48:28 -08007775 }
sqian854d44b2018-12-12 16:48:18 -08007776 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007777 } finally {
7778 Binder.restoreCallingIdentity(identity);
7779 }
sqianc5eccab2018-10-19 18:46:41 -07007780 }
7781
7782 @Override
sqian8c685422019-02-22 15:55:18 -08007783 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007784 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007785 if (!exactMatch) {
7786 TelephonyPermissions
7787 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007788 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007789 }
7790 final long identity = Binder.clearCallingIdentity();
7791 try {
sqian854d44b2018-12-12 16:48:18 -08007792 for (Phone phone: PhoneFactory.getPhones()) {
7793 if (phone.getEmergencyNumberTracker() != null
7794 && phone.getEmergencyNumberTracker() != null) {
7795 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7796 number, exactMatch)) {
7797 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007798 }
7799 }
sqian11b7a0e2018-12-05 18:48:28 -08007800 }
7801 return false;
7802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
7805 }
7806
sqianf4ca7ed2019-01-15 18:32:07 -08007807 /**
7808 * Update emergency number list for test mode.
7809 */
7810 @Override
7811 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7812 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7813 "updateEmergencyNumberListTestMode");
7814
7815 final long identity = Binder.clearCallingIdentity();
7816 try {
7817 for (Phone phone: PhoneFactory.getPhones()) {
7818 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7819 if (tracker != null) {
7820 tracker.executeEmergencyNumberTestModeCommand(action, num);
7821 }
7822 }
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
7825 }
7826 }
7827
7828 /**
7829 * Get the full emergency number list for test mode.
7830 */
7831 @Override
7832 public List<String> getEmergencyNumberListTestMode() {
7833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7834 "getEmergencyNumberListTestMode");
7835
7836 final long identity = Binder.clearCallingIdentity();
7837 try {
7838 Set<String> emergencyNumbers = new HashSet<>();
7839 for (Phone phone: PhoneFactory.getPhones()) {
7840 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7841 if (tracker != null) {
7842 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7843 emergencyNumbers.add(num.getNumber());
7844 }
7845 }
7846 }
7847 return new ArrayList<>(emergencyNumbers);
7848 } finally {
7849 Binder.restoreCallingIdentity(identity);
7850 }
7851 }
7852
chen xud6b45bd2018-10-30 22:27:10 -07007853 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007854 public int getEmergencyNumberDbVersion(int subId) {
7855 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7856
7857 final long identity = Binder.clearCallingIdentity();
7858 try {
7859 final Phone phone = getPhone(subId);
7860 if (phone == null) {
7861 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7862 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7863 }
7864 return phone.getEmergencyNumberDbVersion();
7865 } finally {
7866 Binder.restoreCallingIdentity(identity);
7867 }
7868 }
7869
7870 @Override
7871 public void notifyOtaEmergencyNumberDbInstalled() {
7872 enforceModifyPermission();
7873
7874 final long identity = Binder.clearCallingIdentity();
7875 try {
7876 for (Phone phone: PhoneFactory.getPhones()) {
7877 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7878 if (tracker != null) {
7879 tracker.updateOtaEmergencyNumberDatabase();
7880 }
7881 }
7882 } finally {
7883 Binder.restoreCallingIdentity(identity);
7884 }
7885 }
7886
7887 @Override
7888 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7889 enforceActiveEmergencySessionPermission();
7890
7891 final long identity = Binder.clearCallingIdentity();
7892 try {
7893 for (Phone phone: PhoneFactory.getPhones()) {
7894 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7895 if (tracker != null) {
7896 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7897 }
7898 }
7899 } finally {
7900 Binder.restoreCallingIdentity(identity);
7901 }
7902 }
7903
7904 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007905 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7906 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7907 Phone phone = getPhone(subId);
7908 if (phone == null) {
7909 return null;
7910 }
7911 final long identity = Binder.clearCallingIdentity();
7912 try {
7913 UiccProfile profile = UiccController.getInstance()
7914 .getUiccProfileForPhone(phone.getPhoneId());
7915 if (profile != null) {
7916 return profile.getCertsFromCarrierPrivilegeAccessRules();
7917 }
7918 } finally {
7919 Binder.restoreCallingIdentity(identity);
7920 }
7921 return null;
7922 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007923
7924 /**
7925 * Enable or disable a modem stack.
7926 */
7927 @Override
7928 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7929 enforceModifyPermission();
7930
7931 final long identity = Binder.clearCallingIdentity();
7932 try {
7933 Phone phone = PhoneFactory.getPhone(slotIndex);
7934 if (phone == null) {
7935 return false;
7936 } else {
7937 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7938 }
7939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
7942 }
Michelecea4cf22018-12-21 15:00:11 -08007943
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007944 /**
7945 * Whether a modem stack is enabled or not.
7946 */
7947 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007948 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7949 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007950 Phone phone = PhoneFactory.getPhone(slotIndex);
7951 if (phone == null) return false;
7952
7953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007954 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7955 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007956 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7957 }
7958
7959 final long identity = Binder.clearCallingIdentity();
7960 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007961 try {
7962 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7963 } catch (NoSuchElementException ex) {
7964 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7965 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007966 } finally {
7967 Binder.restoreCallingIdentity(identity);
7968 }
7969 }
7970
Michelecea4cf22018-12-21 15:00:11 -08007971 @Override
Michele0ea7d782019-03-19 14:58:42 -07007972 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007973 enforceModifyPermission();
7974
7975 final long identity = Binder.clearCallingIdentity();
7976 try {
7977 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007978 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007979 .commit();
7980 } finally {
7981 Binder.restoreCallingIdentity(identity);
7982 }
7983 }
7984
7985 @Override
Michele0ea7d782019-03-19 14:58:42 -07007986 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007987 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007989 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7990 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007991 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007992 }
Michelecea4cf22018-12-21 15:00:11 -08007993
7994 final long identity = Binder.clearCallingIdentity();
7995 try {
Michele0ea7d782019-03-19 14:58:42 -07007996 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007997 } finally {
7998 Binder.restoreCallingIdentity(identity);
7999 }
8000 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008001
Michele0ea7d782019-03-19 14:58:42 -07008002 @TelephonyManager.IsMultiSimSupportedResult
8003 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008004 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8005 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8006 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008007 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8008 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008009 }
8010 // Check if the hardware supports multisim functionality. If usage of multisim is not
8011 // supported by the modem, indicate that it is restricted.
8012 PhoneCapability staticCapability =
8013 mPhoneConfigurationManager.getStaticPhoneCapability();
8014 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008015 loge("isMultiSimSupportedInternal: no static configuration available");
8016 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008017 }
Sarah Chin7caee492020-02-18 20:49:02 +00008018 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008019 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8020 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008021 }
8022 // Check if support of multiple SIMs is restricted by carrier
8023 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008024 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008025 }
8026
Michele0ea7d782019-03-19 14:58:42 -07008027 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008028 }
8029
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008030 /**
8031 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008032 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8033 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8034 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008035 * @param numOfSims number of active sims we want to switch to
8036 */
8037 @Override
8038 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008039 if (numOfSims == 1) {
8040 enforceModifyPermission();
8041 } else {
8042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8043 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8044 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008045 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008046
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008047 try {
Michele30b57b22019-03-01 12:01:14 -08008048 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008049 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008050 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8051 return;
8052 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008053 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8054 } finally {
8055 Binder.restoreCallingIdentity(identity);
8056 }
8057 }
8058
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008059 @Override
8060 public boolean isApplicationOnUicc(int subId, int appType) {
8061 enforceReadPrivilegedPermission("isApplicationOnUicc");
8062 Phone phone = getPhone(subId);
8063 if (phone == null) {
8064 return false;
8065 }
8066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 UiccCard uiccCard = phone.getUiccCard();
8069 if (uiccCard == null) {
8070 return false;
8071 }
8072 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8073 if (uiccProfile == null) {
8074 return false;
8075 }
8076 if (TelephonyManager.APPTYPE_SIM <= appType
8077 && appType <= TelephonyManager.APPTYPE_ISIM) {
8078 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8079 }
8080 return false;
8081 } finally {
8082 Binder.restoreCallingIdentity(identity);
8083 }
8084 }
8085
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008086 /**
chen xub4baa772019-04-03 10:23:41 -07008087 * Get whether making changes to modem configurations will trigger reboot.
8088 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008089 */
8090 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008091 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8092 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008094 mApp, subId, callingPackage, callingFeatureId,
8095 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008096 return false;
8097 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103 }
8104 }
8105
Nathan Harold29f5f052019-02-15 13:41:57 -08008106 private void updateModemStateMetrics() {
8107 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8108 // TODO: check the state for each modem if the api is ready.
8109 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8110 }
8111
Pengquan Meng3889a572019-01-23 11:16:29 -08008112 @Override
8113 public int[] getSlotsMapping() {
8114 enforceReadPrivilegedPermission("getSlotsMapping");
8115
8116 final long identity = Binder.clearCallingIdentity();
8117 try {
8118 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8119 // All logical slots should have a mapping to a physical slot.
8120 int[] logicalSlotsMapping = new int[phoneCount];
8121 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8122 for (int i = 0; i < slotInfos.length; i++) {
8123 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8124 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8125 }
8126 }
8127 return logicalSlotsMapping;
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
8131 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008132
8133 /**
8134 * Get the IRadio HAL Version
8135 */
8136 @Override
8137 public int getRadioHalVersion() {
8138 Phone phone = getDefaultPhone();
8139 if (phone == null) return -1;
8140 HalVersion hv = phone.getHalVersion();
8141 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8142 return hv.major * 100 + hv.minor;
8143 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008144
8145 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008146 * Get the current calling package name.
8147 * @return the current calling package name
8148 */
8149 @Override
8150 public String getCurrentPackageName() {
8151 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8152 }
8153
8154 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008155 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8156 * corresponding network requests on a subId.
8157 *
8158 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008159 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008160 * 2) APN is un-metered for this subscription, or
8161 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008162 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008163 *
8164 * @return whether data is allowed for a apn type.
8165 *
8166 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008167 */
8168 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008169 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008170 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8171 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008172
8173 // Now that all security checks passes, perform the operation as ourselves.
8174 final long identity = Binder.clearCallingIdentity();
8175 try {
8176 Phone phone = getPhone(subId);
8177 if (phone == null) return false;
8178
Jack Yu41407ee2019-05-13 16:54:09 -07008179 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008180 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8181 } finally {
8182 Binder.restoreCallingIdentity(identity);
8183 }
8184 }
8185
8186 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008187 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008188 enforceReadPrivilegedPermission("isApnMetered");
8189
8190 // Now that all security checks passes, perform the operation as ourselves.
8191 final long identity = Binder.clearCallingIdentity();
8192 try {
8193 Phone phone = getPhone(subId);
8194 if (phone == null) return true; // By default return true.
8195
Jack Yu41407ee2019-05-13 16:54:09 -07008196 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
8200 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008201
8202 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008203 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8204 int subscriptionId, IBooleanConsumer resultCallback) {
8205 enforceModifyPermission();
8206 long token = Binder.clearCallingIdentity();
8207 try {
8208 Phone phone = getPhone(subscriptionId);
8209 if (phone == null) {
8210 try {
8211 if (resultCallback != null) {
8212 resultCallback.accept(false);
8213 }
8214 } catch (RemoteException e) {
8215 // ignore
8216 }
8217 return;
8218 }
8219 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8220 Pair.create(specifiers, (x) -> {
8221 try {
8222 if (resultCallback != null) {
8223 resultCallback.accept(x);
8224 }
8225 } catch (RemoteException e) {
8226 // ignore
8227 }
8228 });
8229 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8230 } finally {
8231 Binder.restoreCallingIdentity(token);
8232 }
8233 }
8234
8235 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008236 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8237 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8238 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8239 if (iccRecords == null) {
8240 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8241 return false;
8242 }
8243 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8244 }
8245
8246 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008247 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008248 if (callingPackage == null) {
8249 callingPackage = getCurrentPackageName();
8250 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008251 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8252 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8253 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8254 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8255 }
8256 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8257 Intent intent = new Intent();
8258 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8259 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8260 // Bring up choose default SMS subscription dialog right now
8261 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8262 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8263 mApp.startActivity(intent);
8264 }
chen xud5ca2d52019-05-28 15:20:57 -07008265
8266 @Override
8267 public String getMmsUAProfUrl(int subId) {
8268 //TODO investigate if this API should require proper permission check in R b/133791609
8269 final long identity = Binder.clearCallingIdentity();
8270 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008271 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8272 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008273 } finally {
8274 Binder.restoreCallingIdentity(identity);
8275 }
8276 }
8277
8278 @Override
8279 public String getMmsUserAgent(int subId) {
8280 //TODO investigate if this API should require proper permission check in R b/133791609
8281 final long identity = Binder.clearCallingIdentity();
8282 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008283 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8284 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008285 } finally {
8286 Binder.restoreCallingIdentity(identity);
8287 }
8288 }
Jack Yub07d4972019-05-28 16:12:25 -07008289
8290 @Override
8291 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8292 enforceModifyPermission();
8293
8294 // Now that all security checks passes, perform the operation as ourselves.
8295 final long identity = Binder.clearCallingIdentity();
8296 try {
8297 Phone phone = getPhone(subId);
8298 if (phone == null) return false;
8299
8300 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
8304 }
8305
8306 @Override
8307 public boolean isDataAllowedInVoiceCall(int subId) {
8308 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8309
8310 // Now that all security checks passes, perform the operation as ourselves.
8311 final long identity = Binder.clearCallingIdentity();
8312 try {
8313 Phone phone = getPhone(subId);
8314 if (phone == null) return false;
8315
8316 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
8320 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008321
changbettyd5c246e2019-12-24 15:40:37 +08008322 @Override
8323 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8324 enforceModifyPermission();
8325
8326 // Now that all security checks passes, perform the operation as ourselves.
8327 final long identity = Binder.clearCallingIdentity();
8328 try {
8329 Phone phone = getPhone(subId);
8330 if (phone == null) return false;
8331
8332 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8333 } finally {
8334 Binder.restoreCallingIdentity(identity);
8335 }
8336 }
8337
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008338 /**
8339 * Updates whether conference event pacakge handling is enabled.
8340 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8341 * otherwise.
8342 */
8343 @Override
8344 public void setCepEnabled(boolean isCepEnabled) {
8345 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8346
8347 final long identity = Binder.clearCallingIdentity();
8348 try {
8349 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8350 for (Phone phone : PhoneFactory.getPhones()) {
8351 Phone defaultPhone = phone.getImsPhone();
8352 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8353 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8354 ImsPhoneCallTracker imsPhoneCallTracker =
8355 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8356 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8357 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8358 + imsPhone.getMsisdn());
8359 }
8360 }
8361 } finally {
8362 Binder.restoreCallingIdentity(identity);
8363 }
8364 }
allenwtsu46dcc572020-01-08 18:24:03 +08008365
8366 /**
8367 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8368 *
8369 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8370 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8371 * before being read.
8372 */
8373 @Override
8374 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8375 isCompressed) {
8376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8377 mApp, subId, "notifyRcsAutoConfigurationReceived");
8378 try {
8379 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8380 if (configBinder == null) {
8381 Rlog.e(LOG_TAG, "null result for getImsConfig");
8382 } else {
8383 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8384 }
8385 } catch (RemoteException e) {
8386 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8387 }
8388 }
zoey chene02881a2019-12-30 16:11:23 +08008389
8390 @Override
8391 public boolean isIccLockEnabled(int subId) {
8392 enforceReadPrivilegedPermission("isIccLockEnabled");
8393
8394 // Now that all security checks passes, perform the operation as ourselves.
8395 final long identity = Binder.clearCallingIdentity();
8396 try {
8397 Phone phone = getPhone(subId);
8398 if (phone != null && phone.getIccCard() != null) {
8399 return phone.getIccCard().getIccLockEnabled();
8400 } else {
8401 return false;
8402 }
8403 } finally {
8404 Binder.restoreCallingIdentity(identity);
8405 }
8406 }
8407
8408 /**
8409 * Set the ICC pin lock enabled or disabled.
8410 *
8411 * @return an integer representing the status of IccLock enabled or disabled in the following
8412 * three cases:
8413 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8414 * successfully.
8415 * - Positive number and zero for remaining password attempts.
8416 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8417 *
8418 */
8419 @Override
8420 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8421 enforceModifyPermission();
8422
8423 Phone phone = getPhone(subId);
8424 if (phone == null) {
8425 return 0;
8426 }
8427 // Now that all security checks passes, perform the operation as ourselves.
8428 final long identity = Binder.clearCallingIdentity();
8429 try {
8430 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8431 new Pair<Boolean, String>(enabled, password), phone, null);
8432 return attemptsRemaining;
8433
8434 } catch (Exception e) {
8435 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8436 } finally {
8437 Binder.restoreCallingIdentity(identity);
8438 }
8439 return 0;
8440 }
8441
8442 /**
8443 * Change the ICC password used in ICC pin lock.
8444 *
8445 * @return an integer representing the status of IccLock changed in the following three cases:
8446 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8447 * - Positive number and zero for remaining password attempts.
8448 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8449 *
8450 */
8451 @Override
8452 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8453 enforceModifyPermission();
8454
8455 Phone phone = getPhone(subId);
8456 if (phone == null) {
8457 return 0;
8458 }
8459 // Now that all security checks passes, perform the operation as ourselves.
8460 final long identity = Binder.clearCallingIdentity();
8461 try {
8462 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8463 new Pair<String, String>(oldPassword, newPassword), phone, null);
8464 return attemptsRemaining;
8465
8466 } catch (Exception e) {
8467 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8468 } finally {
8469 Binder.restoreCallingIdentity(identity);
8470 }
8471 return 0;
8472 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008473
8474 /**
8475 * Request for receiving user activity notification
8476 */
8477 @Override
8478 public void requestUserActivityNotification() {
8479 if (!mNotifyUserActivity.get()
8480 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8481 mNotifyUserActivity.set(true);
8482 }
8483 }
8484
8485 /**
8486 * Called when userActivity is signalled in the power manager.
8487 * This is safe to call from any thread, with any window manager locks held or not.
8488 */
8489 @Override
8490 public void userActivity() {
8491 // ***************************************
8492 // * Inherited from PhoneWindowManager *
8493 // ***************************************
8494 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8495 // WITH ITS LOCKS HELD.
8496 //
8497 // This code must be VERY careful about the locks
8498 // it acquires.
8499 // In fact, the current code acquires way too many,
8500 // and probably has lurking deadlocks.
8501
8502 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8503 throw new SecurityException("Only the OS may call notifyUserActivity()");
8504 }
8505
8506 if (mNotifyUserActivity.getAndSet(false)) {
8507 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8508 USER_ACTIVITY_NOTIFICATION_DELAY);
8509 }
8510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008511}