blob: d7a66ef830fe3e0489a708450bbaa218badbe9ec [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700118import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800124import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700126import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700127import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800128import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800131import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800133import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800134import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700135import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700136import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800137import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800139import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700140import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700141import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700142import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700144import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800145import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700146import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700147import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700148import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700149import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700150import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700152import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800154import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800155import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800156import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700157import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800158import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700159import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800160import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700161import com.android.internal.telephony.imsphone.ImsPhone;
162import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800163import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700164import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800166import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700169import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800170import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700171import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800172import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000173import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800174import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700175import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700176import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800177import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700178import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800180import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700181import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700182import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800183import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800184
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700185import java.io.FileDescriptor;
186import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800189import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800191import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100192import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800193import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700194import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800195import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800196import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800197import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
199/**
200 * Implementation of the ITelephony interface.
201 */
Santos Cordon117fee72014-05-16 17:56:12 -0700202public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203 private static final String LOG_TAG = "PhoneInterfaceManager";
204 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
205 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800206 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207
208 // Message codes used with mMainThreadHandler
209 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700210 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
211 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700212 private static final int CMD_OPEN_CHANNEL = 9;
213 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
214 private static final int CMD_CLOSE_CHANNEL = 11;
215 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800216 private static final int CMD_NV_READ_ITEM = 13;
217 private static final int EVENT_NV_READ_ITEM_DONE = 14;
218 private static final int CMD_NV_WRITE_ITEM = 15;
219 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
220 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
221 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700222 private static final int CMD_RESET_MODEM_CONFIG = 19;
223 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800224 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
225 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
226 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
227 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800228 private static final int CMD_SEND_ENVELOPE = 25;
229 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000230 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
231 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700232 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
233 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
234 private static final int CMD_EXCHANGE_SIM_IO = 31;
235 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800236 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
237 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700238 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
239 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700240 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
241 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700242 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
243 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
244 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
245 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700246 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
247 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
248 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
249 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700250 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800251 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
252 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000253 private static final int CMD_SWITCH_SLOTS = 50;
254 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700255 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
256 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
257 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
258 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
259 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
260 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
261 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
262 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700263 private static final int CMD_GET_ALL_CELL_INFO = 60;
264 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
265 private static final int CMD_GET_CELL_LOCATION = 62;
266 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700267 private static final int CMD_MODEM_REBOOT = 64;
268 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700269 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
270 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800271 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
272 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700273 private static final int CMD_GET_MODEM_STATUS = 70;
274 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700275 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
276 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700277 private static final int CMD_ERASE_MODEM_CONFIG = 74;
278 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800279 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
280 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
281 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
282 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800283 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
284 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800285 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800286 private static final int CMD_GET_CALL_FORWARDING = 83;
287 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
288 private static final int CMD_SET_CALL_FORWARDING = 85;
289 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
290 private static final int CMD_GET_CALL_WAITING = 87;
291 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
292 private static final int CMD_SET_CALL_WAITING = 89;
293 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800295 // Parameters of select command.
296 private static final int SELECT_COMMAND = 0xA4;
297 private static final int SELECT_P1 = 0x04;
298 private static final int SELECT_P2 = 0;
299 private static final int SELECT_P3 = 0x10;
300
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700301 /** The singleton instance. */
302 private static PhoneInterfaceManager sInstance;
303
Wink Saville3ab207e2014-11-20 13:07:20 -0800304 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800305 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800306 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700307 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800308 private AppOpsManager mAppOps;
309 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800310 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800311 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700312 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 /** User Activity */
315 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800316 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
317
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700318 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
319
Derek Tan97ebb422014-09-05 16:55:38 -0700320 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
321 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800322 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800323 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700324
Michelecea4cf22018-12-21 15:00:11 -0800325 // String to store multi SIM allowed
326 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
327
Derek Tan740e1672017-06-27 14:56:27 -0700328 // The AID of ISD-R.
329 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
330
yinxub1bed742017-04-17 11:45:04 -0700331 private NetworkScanRequestTracker mNetworkScanRequestTracker;
332
David Kelly5e06a7f2018-03-12 14:10:59 +0000333 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
334 private static final int MANUFACTURER_CODE_LENGTH = 8;
335
Derek Tan89e89d42014-07-08 17:00:10 -0700336 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700337 * Experiment flag to enable erase modem config on reset network, default value is false
338 */
339 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
340 "reset_network_erase_modem_config_enabled";
341
342 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700343 * A request object to use for transmitting data to an ICC.
344 */
345 private static final class IccAPDUArgument {
346 public int channel, cla, command, p1, p2, p3;
347 public String data;
348
349 public IccAPDUArgument(int channel, int cla, int command,
350 int p1, int p2, int p3, String data) {
351 this.channel = channel;
352 this.cla = cla;
353 this.command = command;
354 this.p1 = p1;
355 this.p2 = p2;
356 this.p3 = p3;
357 this.data = data;
358 }
359 }
360
361 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700362 * A request object to use for transmitting data to an ICC.
363 */
364 private static final class ManualNetworkSelectionArgument {
365 public OperatorInfo operatorInfo;
366 public boolean persistSelection;
367
368 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
369 this.operatorInfo = operatorInfo;
370 this.persistSelection = persistSelection;
371 }
372 }
373
374 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
376 * request after sending. The main thread will notify the request when it is complete.
377 */
378 private static final class MainThreadRequest {
379 /** The argument to use for the request */
380 public Object argument;
381 /** The result of the request that is run on the main thread */
382 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800383 // The subscriber id that this request applies to. Defaults to
384 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
385 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386
Nathan Harold92bed182018-10-12 18:16:49 -0700387 // In cases where subId is unavailable, the caller needs to specify the phone.
388 public Phone phone;
389
vagdeviaf9a5b92018-08-15 16:01:53 -0700390 public WorkSource workSource;
391
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 public MainThreadRequest(Object argument) {
393 this.argument = argument;
394 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800395
Nathan Harold92bed182018-10-12 18:16:49 -0700396 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
397 this.argument = argument;
398 if (phone != null) {
399 this.phone = phone;
400 }
401 this.workSource = workSource;
402 }
403
vagdeviaf9a5b92018-08-15 16:01:53 -0700404 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800405 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800406 if (subId != null) {
407 this.subId = subId;
408 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700409 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 }
412
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800413 private static final class IncomingThirdPartyCallArgs {
414 public final ComponentName component;
415 public final String callId;
416 public final String callerDisplayName;
417
418 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
419 String callerDisplayName) {
420 this.component = component;
421 this.callId = callId;
422 this.callerDisplayName = callerDisplayName;
423 }
424 }
425
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 /**
427 * A handler that processes messages on the main thread in the phone process. Since many
428 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
429 * inbound binder threads to the main thread in the phone process. The Binder thread
430 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
431 * on, which will be notified when the operation completes and will contain the result of the
432 * request.
433 *
434 * <p>If a MainThreadRequest object is provided in the msg.obj field,
435 * note that request.result must be set to something non-null for the calling thread to
436 * unblock.
437 */
438 private final class MainThreadHandler extends Handler {
439 @Override
440 public void handleMessage(Message msg) {
441 MainThreadRequest request;
442 Message onCompleted;
443 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800444 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800446 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447
448 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700449 case CMD_HANDLE_USSD_REQUEST: {
450 request = (MainThreadRequest) msg.obj;
451 final Phone phone = getPhoneFromRequest(request);
452 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
453 String ussdRequest = ussdObject.first;
454 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700455
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 if (!isUssdApiAllowed(request.subId)) {
457 // Carrier does not support use of this API, return failure.
458 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
459 UssdResponse response = new UssdResponse(ussdRequest, null);
460 Bundle returnData = new Bundle();
461 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
462 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700463
Pengquan Menga1bb6272018-09-06 09:59:22 -0700464 request.result = true;
465 notifyRequester(request);
466 return;
467 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700468
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 try {
470 request.result = phone != null
471 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
472 } catch (CallStateException cse) {
473 request.result = false;
474 }
475 // Wake up the requesting thread
476 notifyRequester(request);
477 break;
pkanwar32d516d2016-10-14 19:37:38 -0700478 }
479
Yorke Lee716f67e2015-06-17 15:39:16 -0700480 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700482 final Phone phone = getPhoneFromRequest(request);
483 request.result = phone != null ?
484 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
485 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800494 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700495 if (uiccCard == null) {
496 loge("iccTransmitApduLogicalChannel: No UICC");
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700498 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700499 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
501 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700502 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 iccArgument.channel, iccArgument.cla, iccArgument.command,
504 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700506 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700507 break;
508
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700510 ar = (AsyncResult) msg.obj;
511 request = (MainThreadRequest) ar.userObj;
512 if (ar.exception == null && ar.result != null) {
513 request.result = ar.result;
514 } else {
515 request.result = new IccIoResult(0x6F, 0, (byte[])null);
516 if (ar.result == null) {
517 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800518 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700519 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800520 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700521 } else {
522 loge("iccTransmitApduLogicalChannel: Unknown exception");
523 }
524 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 break;
527
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
529 request = (MainThreadRequest) msg.obj;
530 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800531 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 if (uiccCard == null) {
533 loge("iccTransmitApduBasicChannel: No UICC");
534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 } else {
537 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
538 request);
539 uiccCard.iccTransmitApduBasicChannel(
540 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
541 iccArgument.p3, iccArgument.data, onCompleted);
542 }
543 break;
544
545 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
546 ar = (AsyncResult) msg.obj;
547 request = (MainThreadRequest) ar.userObj;
548 if (ar.exception == null && ar.result != null) {
549 request.result = ar.result;
550 } else {
551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
552 if (ar.result == null) {
553 loge("iccTransmitApduBasicChannel: Empty response");
554 } else if (ar.exception instanceof CommandException) {
555 loge("iccTransmitApduBasicChannel: CommandException: " +
556 ar.exception);
557 } else {
558 loge("iccTransmitApduBasicChannel: Unknown exception");
559 }
560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 break;
563
564 case CMD_EXCHANGE_SIM_IO:
565 request = (MainThreadRequest) msg.obj;
566 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800567 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 if (uiccCard == null) {
569 loge("iccExchangeSimIO: No UICC");
570 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 } else {
573 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
574 request);
575 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
576 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
577 iccArgument.data, onCompleted);
578 }
579 break;
580
581 case EVENT_EXCHANGE_SIM_IO_DONE:
582 ar = (AsyncResult) msg.obj;
583 request = (MainThreadRequest) ar.userObj;
584 if (ar.exception == null && ar.result != null) {
585 request.result = ar.result;
586 } else {
587 request.result = new IccIoResult(0x6f, 0, (byte[])null);
588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 break;
591
Derek Tan4d5e5c12014-02-04 11:54:58 -0800592 case CMD_SEND_ENVELOPE:
593 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800594 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 if (uiccCard == null) {
596 loge("sendEnvelopeWithStatus: No UICC");
597 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 } else {
600 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
601 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
602 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800603 break;
604
605 case EVENT_SEND_ENVELOPE_DONE:
606 ar = (AsyncResult) msg.obj;
607 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700608 if (ar.exception == null && ar.result != null) {
609 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800610 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700611 request.result = new IccIoResult(0x6F, 0, (byte[])null);
612 if (ar.result == null) {
613 loge("sendEnvelopeWithStatus: Empty response");
614 } else if (ar.exception instanceof CommandException) {
615 loge("sendEnvelopeWithStatus: CommandException: " +
616 ar.exception);
617 } else {
618 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
619 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800620 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800622 break;
623
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 case CMD_OPEN_CHANNEL:
625 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800626 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800627 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 if (uiccCard == null) {
629 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800630 request.result = new IccOpenLogicalChannelResponse(-1,
631 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 } else {
634 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800635 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
636 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700637 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 break;
639
640 case EVENT_OPEN_CHANNEL_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 int[] result = (int[]) ar.result;
646 int channelId = result[0];
647 byte[] selectResponse = null;
648 if (result.length > 1) {
649 selectResponse = new byte[result.length - 1];
650 for (int i = 1; i < result.length; ++i) {
651 selectResponse[i - 1] = (byte) result[i];
652 }
653 }
654 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700655 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 if (ar.result == null) {
658 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 if (ar.exception != null) {
661 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
662 }
663
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700664 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700665 if (ar.exception instanceof CommandException) {
666 CommandException.Error error =
667 ((CommandException) (ar.exception)).getCommandError();
668 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700669 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700670 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700671 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 }
673 }
674 openChannelResp = new IccOpenLogicalChannelResponse(
675 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700677 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
681 case CMD_CLOSE_CHANNEL:
682 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800683 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 if (uiccCard == null) {
685 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900686 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700688 } else {
689 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
690 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
691 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 break;
693
694 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800695 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
696 break;
697
698 case CMD_NV_READ_ITEM:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800701 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
702 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800703 break;
704
705 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 ar = (AsyncResult) msg.obj;
707 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800708 if (ar.exception == null && ar.result != null) {
709 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800711 request.result = "";
712 if (ar.result == null) {
713 loge("nvReadItem: Empty response");
714 } else if (ar.exception instanceof CommandException) {
715 loge("nvReadItem: CommandException: " +
716 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800718 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 }
720 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700721 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 break;
723
Jake Hambye994d462014-02-03 13:10:13 -0800724 case CMD_NV_WRITE_ITEM:
725 request = (MainThreadRequest) msg.obj;
726 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
727 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800728 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700729 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800730 break;
731
732 case EVENT_NV_WRITE_ITEM_DONE:
733 handleNullReturnEvent(msg, "nvWriteItem");
734 break;
735
736 case CMD_NV_WRITE_CDMA_PRL:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800739 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800740 break;
741
742 case EVENT_NV_WRITE_CDMA_PRL_DONE:
743 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
744 break;
745
chen xu6dac5ab2018-10-26 17:39:23 -0700746 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800747 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700748 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800749 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800750 break;
751
chen xu6dac5ab2018-10-26 17:39:23 -0700752 case EVENT_RESET_MODEM_CONFIG_DONE:
753 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800754 break;
755
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 case CMD_GET_PREFERRED_NETWORK_TYPE:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700759 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800760 break;
761
762 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
763 ar = (AsyncResult) msg.obj;
764 request = (MainThreadRequest) ar.userObj;
765 if (ar.exception == null && ar.result != null) {
766 request.result = ar.result; // Integer
767 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530768 // request.result must be set to something non-null
769 // for the calling thread to unblock
770 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800771 if (ar.result == null) {
772 loge("getPreferredNetworkType: Empty response");
773 } else if (ar.exception instanceof CommandException) {
774 loge("getPreferredNetworkType: CommandException: " +
775 ar.exception);
776 } else {
777 loge("getPreferredNetworkType: Unknown exception");
778 }
779 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800781 break;
782
783 case CMD_SET_PREFERRED_NETWORK_TYPE:
784 request = (MainThreadRequest) msg.obj;
785 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
786 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700787 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800788 break;
789
790 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
791 handleNullReturnEvent(msg, "setPreferredNetworkType");
792 break;
793
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000794 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
795 request = (MainThreadRequest)msg.obj;
796 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800797 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000798 break;
799
800 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
801 ar = (AsyncResult)msg.obj;
802 request = (MainThreadRequest)ar.userObj;
803 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700804 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000805 break;
806
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800807 case CMD_SET_VOICEMAIL_NUMBER:
808 request = (MainThreadRequest) msg.obj;
809 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
810 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800811 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
812 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800813 break;
814
815 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
816 handleNullReturnEvent(msg, "setVoicemailNumber");
817 break;
818
Stuart Scott54788802015-03-30 13:18:01 -0700819 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
822 request);
823 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
824 break;
825
826 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
827 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
828 break;
829
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 case CMD_PERFORM_NETWORK_SCAN:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
833 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
834 break;
835
Hall Liu27d24262020-09-18 19:04:59 -0700836 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800837 request = (MainThreadRequest) msg.obj;
838 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700839 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
840 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
841 request.argument;
842 int callForwardingReason = args.first;
843 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800844 break;
Hall Liu27d24262020-09-18 19:04:59 -0700845 }
846 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700849 TelephonyManager.CallForwardingInfoCallback callback =
850 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
851 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800852 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700853 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800854 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
855 for (CallForwardInfo callForwardInfo : callForwardInfos) {
856 // Service Class is a bit mask per 3gpp 27.007. Search for
857 // any service for voice call.
858 if ((callForwardInfo.serviceClass
859 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700860 callForwardingInfo = new CallForwardingInfo(true,
861 callForwardInfo.reason,
862 callForwardInfo.number,
863 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800864 break;
865 }
866 }
867 // Didn't find a call forward info for voice call.
868 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700869 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
870 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800871 }
Hall Liu27d24262020-09-18 19:04:59 -0700872 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800873 } else {
874 if (ar.result == null) {
875 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
876 }
877 if (ar.exception != null) {
878 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
879 }
Hall Liu27d24262020-09-18 19:04:59 -0700880 int errorCode = CallForwardingInfo.ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800881 if (ar.exception instanceof CommandException) {
882 CommandException.Error error =
883 ((CommandException) (ar.exception)).getCommandError();
884 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu27d24262020-09-18 19:04:59 -0700885 errorCode = CallForwardingInfo.ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800886 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu27d24262020-09-18 19:04:59 -0700887 errorCode = CallForwardingInfo.ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800888 }
889 }
Hall Liu27d24262020-09-18 19:04:59 -0700890 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -0800891 }
Shuo Qian4a594052020-01-23 11:59:30 -0800892 break;
Hall Liu27d24262020-09-18 19:04:59 -0700893 }
Shuo Qian4a594052020-01-23 11:59:30 -0800894
Hall Liu27d24262020-09-18 19:04:59 -0700895 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800896 request = (MainThreadRequest) msg.obj;
897 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700898 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -0800899 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -0700900 ((Pair<CallForwardingInfo, Consumer<Integer>>)
901 request.argument).first;
902 request.phone.setCallForwardingOption(
903 callForwardingInfoToSet.isEnabled()
904 ? CommandsInterface.CF_ACTION_ENABLE
905 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -0800906 callForwardingInfoToSet.getReason(),
907 callForwardingInfoToSet.getNumber(),
908 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
909 break;
Hall Liu27d24262020-09-18 19:04:59 -0700910 }
Shuo Qian4a594052020-01-23 11:59:30 -0800911
Hall Liu27d24262020-09-18 19:04:59 -0700912 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700915 Consumer<Integer> callback =
916 ((Pair<CallForwardingInfo, Consumer<Integer>>)
917 request.argument).second;
918 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -0800919 loge("setCallForwarding exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -0700920 int errorCode = CallForwardingInfo.ERROR_UNKNOWN;
921 if (ar.exception instanceof CommandException) {
922 CommandException.Error error =
923 ((CommandException) (ar.exception)).getCommandError();
924 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
925 errorCode = CallForwardingInfo.ERROR_FDN_CHECK_FAILURE;
926 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
927 errorCode = CallForwardingInfo.ERROR_NOT_SUPPORTED;
928 }
929 }
930 callback.accept(errorCode);
931 } else {
932 callback.accept(CallForwardingInfo.SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -0800933 }
Shuo Qian4a594052020-01-23 11:59:30 -0800934 break;
Hall Liu27d24262020-09-18 19:04:59 -0700935 }
Shuo Qian4a594052020-01-23 11:59:30 -0800936
Hall Liu27d24262020-09-18 19:04:59 -0700937 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
940 getPhoneFromRequest(request).getCallWaiting(onCompleted);
941 break;
Hall Liu27d24262020-09-18 19:04:59 -0700942 }
Shuo Qian4a594052020-01-23 11:59:30 -0800943
Hall Liu27d24262020-09-18 19:04:59 -0700944 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800945 ar = (AsyncResult) msg.obj;
946 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700947 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -0800948 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
949 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800950 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800951 // Service Class is a bit mask per 3gpp 27.007.
952 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800953 if (callForwardResults.length > 1
954 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -0700955 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800956 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -0700957 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
958 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -0800959 } else {
Hall Liu27d24262020-09-18 19:04:59 -0700960 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -0800961 }
962 } else {
963 if (ar.result == null) {
964 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
965 }
966 if (ar.exception != null) {
967 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
968 }
969 if (ar.exception instanceof CommandException) {
970 CommandException.Error error =
971 ((CommandException) (ar.exception)).getCommandError();
972 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
973 callForwardingStatus =
974 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
975 }
976 }
977 }
Hall Liu27d24262020-09-18 19:04:59 -0700978 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -0800979 break;
Hall Liu27d24262020-09-18 19:04:59 -0700980 }
Shuo Qian4a594052020-01-23 11:59:30 -0800981
Hall Liu27d24262020-09-18 19:04:59 -0700982 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700985 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
986 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800987 break;
Hall Liu27d24262020-09-18 19:04:59 -0700988 }
Shuo Qian4a594052020-01-23 11:59:30 -0800989
Hall Liu27d24262020-09-18 19:04:59 -0700990 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700993 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
994 Consumer<Integer> callback =
995 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
996 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -0800997 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -0700998 if (ar.exception instanceof CommandException) {
999 CommandException.Error error =
1000 ((CommandException) (ar.exception)).getCommandError();
1001 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1002 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1003 } else {
1004 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1005 }
1006 } else {
1007 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1008 }
1009 } else {
1010 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1011 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001012 }
Shuo Qian4a594052020-01-23 11:59:30 -08001013 break;
Hall Liu27d24262020-09-18 19:04:59 -07001014 }
Shuo Qian4a594052020-01-23 11:59:30 -08001015
Shishir Agrawal302c8692015-06-19 13:49:39 -07001016 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 CellNetworkScanResult cellScanResult;
1020 if (ar.exception == null && ar.result != null) {
1021 cellScanResult = new CellNetworkScanResult(
1022 CellNetworkScanResult.STATUS_SUCCESS,
1023 (List<OperatorInfo>) ar.result);
1024 } else {
1025 if (ar.result == null) {
1026 loge("getCellNetworkScanResults: Empty response");
1027 }
1028 if (ar.exception != null) {
1029 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1030 }
1031 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1032 if (ar.exception instanceof CommandException) {
1033 CommandException.Error error =
1034 ((CommandException) (ar.exception)).getCommandError();
1035 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1036 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1037 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1038 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1039 }
1040 }
1041 cellScanResult = new CellNetworkScanResult(errorCode, null);
1042 }
1043 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001044 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001045 break;
1046
1047 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1048 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001049 ManualNetworkSelectionArgument selArg =
1050 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001051 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1052 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001053 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1054 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001055 break;
1056
1057 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
1060 if (ar.exception == null) {
1061 request.result = true;
1062 } else {
1063 request.result = false;
1064 loge("setNetworkSelectionModeManual " + ar.exception);
1065 }
1066 notifyRequester(request);
1067 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001068 break;
1069
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001070 case CMD_GET_MODEM_ACTIVITY_INFO:
1071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001073 if (defaultPhone != null) {
1074 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001075 } else {
1076 ResultReceiver result = (ResultReceiver) request.argument;
1077 Bundle bundle = new Bundle();
1078 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1079 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1080 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001081 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001082 break;
1083
1084 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1085 ar = (AsyncResult) msg.obj;
1086 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001087 ResultReceiver result = (ResultReceiver) request.argument;
1088
1089 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001090 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001091 // Update the last modem activity info and the result of the request.
1092 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1093 if (isModemActivityInfoValid(info)) {
1094 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1095 int[] txTimeMs = info.getTransmitTimeMillis();
1096 int[] lastModemTxTimeMs = mLastModemActivityInfo
1097 .getTransmitTimeMillis();
1098 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1099 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1100 }
1101 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1102 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1103 + mLastModemActivityInfo.getSleepTimeMillis());
1104 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1105 + mLastModemActivityInfo.getIdleTimeMillis());
1106 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1107 mLastModemActivityInfo.setReceiveTimeMillis(
1108 info.getReceiveTimeMillis()
1109 + mLastModemActivityInfo.getReceiveTimeMillis());
1110 }
1111 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1112 mLastModemActivityInfo.getSleepTimeMillis(),
1113 mLastModemActivityInfo.getIdleTimeMillis(),
1114 mLastModemActivityInfo.getTransmitTimeMillis(),
1115 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001116 } else {
1117 if (ar.result == null) {
1118 loge("queryModemActivityInfo: Empty response");
1119 } else if (ar.exception instanceof CommandException) {
1120 loge("queryModemActivityInfo: CommandException: " +
1121 ar.exception);
1122 } else {
1123 loge("queryModemActivityInfo: Unknown exception");
1124 }
1125 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001126 Bundle bundle = new Bundle();
1127 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1128 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001129 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001130 break;
1131
Meng Wang1a7c35a2016-05-05 20:56:15 -07001132 case CMD_SET_ALLOWED_CARRIERS:
1133 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001134 CarrierRestrictionRules argument =
1135 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001136 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001137 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001138 break;
1139
1140 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 if (ar.exception == null && ar.result != null) {
1144 request.result = ar.result;
1145 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001146 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1147 if (ar.exception instanceof CommandException) {
1148 loge("setAllowedCarriers: CommandException: " + ar.exception);
1149 CommandException.Error error =
1150 ((CommandException) (ar.exception)).getCommandError();
1151 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1152 request.result =
1153 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1154 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001155 } else {
1156 loge("setAllowedCarriers: Unknown exception");
1157 }
1158 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001159 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001160 break;
1161
1162 case CMD_GET_ALLOWED_CARRIERS:
1163 request = (MainThreadRequest) msg.obj;
1164 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001165 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001166 break;
1167
1168 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1169 ar = (AsyncResult) msg.obj;
1170 request = (MainThreadRequest) ar.userObj;
1171 if (ar.exception == null && ar.result != null) {
1172 request.result = ar.result;
1173 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001174 request.result = new IllegalStateException(
1175 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001176 if (ar.result == null) {
1177 loge("getAllowedCarriers: Empty response");
1178 } else if (ar.exception instanceof CommandException) {
1179 loge("getAllowedCarriers: CommandException: " +
1180 ar.exception);
1181 } else {
1182 loge("getAllowedCarriers: Unknown exception");
1183 }
1184 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001185 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001186 break;
1187
Nathan Haroldb3014052017-01-25 15:57:32 -08001188 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1189 ar = (AsyncResult) msg.obj;
1190 request = (MainThreadRequest) ar.userObj;
1191 if (ar.exception == null && ar.result != null) {
1192 request.result = ar.result;
1193 } else {
1194 request.result = new IllegalArgumentException(
1195 "Failed to retrieve Forbidden Plmns");
1196 if (ar.result == null) {
1197 loge("getForbiddenPlmns: Empty response");
1198 } else {
1199 loge("getForbiddenPlmns: Unknown exception");
1200 }
1201 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001202 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001203 break;
1204
1205 case CMD_GET_FORBIDDEN_PLMNS:
1206 request = (MainThreadRequest) msg.obj;
1207 uiccCard = getUiccCardFromRequest(request);
1208 if (uiccCard == null) {
1209 loge("getForbiddenPlmns() UiccCard is null");
1210 request.result = new IllegalArgumentException(
1211 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001212 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001213 break;
1214 }
1215 Integer appType = (Integer) request.argument;
1216 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1217 if (uiccApp == null) {
1218 loge("getForbiddenPlmns() no app with specified type -- "
1219 + appType);
1220 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001221 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001222 break;
1223 } else {
1224 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1225 + " specified type -- " + appType);
1226 }
1227 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1228 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1229 onCompleted);
1230 break;
1231
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001232 case CMD_SWITCH_SLOTS:
1233 request = (MainThreadRequest) msg.obj;
1234 int[] physicalSlots = (int[]) request.argument;
1235 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1236 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1237 break;
1238
1239 case EVENT_SWITCH_SLOTS_DONE:
1240 ar = (AsyncResult) msg.obj;
1241 request = (MainThreadRequest) ar.userObj;
1242 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001243 notifyRequester(request);
1244 break;
1245 case CMD_GET_NETWORK_SELECTION_MODE:
1246 request = (MainThreadRequest) msg.obj;
1247 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1248 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1249 break;
1250
1251 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1252 ar = (AsyncResult) msg.obj;
1253 request = (MainThreadRequest) ar.userObj;
1254 if (ar.exception != null) {
1255 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1256 } else {
1257 int mode = ((int[]) ar.result)[0];
1258 if (mode == 0) {
1259 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1260 } else {
1261 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1262 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001263 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001264 notifyRequester(request);
1265 break;
1266 case CMD_GET_CDMA_ROAMING_MODE:
1267 request = (MainThreadRequest) msg.obj;
1268 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1269 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1270 break;
1271 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1272 ar = (AsyncResult) msg.obj;
1273 request = (MainThreadRequest) ar.userObj;
1274 if (ar.exception != null) {
1275 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1276 } else {
1277 request.result = ((int[]) ar.result)[0];
1278 }
1279 notifyRequester(request);
1280 break;
1281 case CMD_SET_CDMA_ROAMING_MODE:
1282 request = (MainThreadRequest) msg.obj;
1283 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1284 int mode = (int) request.argument;
1285 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1286 break;
1287 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1288 ar = (AsyncResult) msg.obj;
1289 request = (MainThreadRequest) ar.userObj;
1290 request.result = ar.exception == null;
1291 notifyRequester(request);
1292 break;
1293 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1294 request = (MainThreadRequest) msg.obj;
1295 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1296 int subscriptionMode = (int) request.argument;
1297 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1298 break;
1299 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1300 ar = (AsyncResult) msg.obj;
1301 request = (MainThreadRequest) ar.userObj;
1302 request.result = ar.exception == null;
1303 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001304 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001305 case CMD_GET_ALL_CELL_INFO:
1306 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001307 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001308 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001309 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 case EVENT_GET_ALL_CELL_INFO_DONE:
1311 ar = (AsyncResult) msg.obj;
1312 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001313 // If a timeout occurs, the response will be null
1314 request.result = (ar.exception == null && ar.result != null)
1315 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001316 synchronized (request) {
1317 request.notifyAll();
1318 }
1319 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001320 case CMD_REQUEST_CELL_INFO_UPDATE:
1321 request = (MainThreadRequest) msg.obj;
1322 request.phone.requestCellInfoUpdate(request.workSource,
1323 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1324 break;
1325 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1326 ar = (AsyncResult) msg.obj;
1327 request = (MainThreadRequest) ar.userObj;
1328 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1329 try {
1330 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001331 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001332 cb.onError(
1333 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1334 ar.exception.getClass().getName(),
1335 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001336 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001337 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001338 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001339 } else {
1340 // use the result as returned
1341 cb.onCellInfo((List<CellInfo>) ar.result);
1342 }
1343 } catch (RemoteException re) {
1344 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1345 }
1346 break;
1347 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001348 request = (MainThreadRequest) msg.obj;
1349 WorkSource ws = (WorkSource) request.argument;
1350 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001351 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001352 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001353 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001354 ar = (AsyncResult) msg.obj;
1355 request = (MainThreadRequest) ar.userObj;
1356 if (ar.exception == null) {
1357 request.result = ar.result;
1358 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001360 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001361 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001362 }
1363
1364 synchronized (request) {
1365 request.notifyAll();
1366 }
1367 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001368 case CMD_MODEM_REBOOT:
1369 request = (MainThreadRequest) msg.obj;
1370 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001371 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001372 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001373 case EVENT_CMD_MODEM_REBOOT_DONE:
1374 handleNullReturnEvent(msg, "rebootModem");
1375 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001376 case CMD_REQUEST_ENABLE_MODEM:
1377 request = (MainThreadRequest) msg.obj;
1378 boolean enable = (boolean) request.argument;
1379 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001380 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001381 PhoneConfigurationManager.getInstance()
1382 .enablePhone(request.phone, enable, onCompleted);
1383 break;
1384 case EVENT_ENABLE_MODEM_DONE:
1385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001388 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001389 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001390 if ((boolean) request.result) {
1391 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1392 updateModemStateMetrics();
1393 } else {
1394 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1395 + ar.exception);
1396 }
1397 notifyRequester(request);
1398 break;
1399 case CMD_GET_MODEM_STATUS:
1400 request = (MainThreadRequest) msg.obj;
1401 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1402 PhoneConfigurationManager.getInstance()
1403 .getPhoneStatusFromModem(request.phone, onCompleted);
1404 break;
1405 case EVENT_GET_MODEM_STATUS_DONE:
1406 ar = (AsyncResult) msg.obj;
1407 request = (MainThreadRequest) ar.userObj;
1408 int id = request.phone.getPhoneId();
1409 if (ar.exception == null && ar.result != null) {
1410 request.result = ar.result;
1411 //update the cache as modem status has changed
1412 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1413 (boolean) request.result);
1414 } else {
1415 // Return true if modem status cannot be retrieved. For most cases,
1416 // modem status is on. And for older version modems, GET_MODEM_STATUS
1417 // and disable modem are not supported. Modem is always on.
1418 // TODO: this should be fixed in R to support a third
1419 // status UNKNOWN b/131631629
1420 request.result = true;
1421 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1422 + ar.exception);
1423 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001424 notifyRequester(request);
1425 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001426 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1427 request = (MainThreadRequest) msg.obj;
1428 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1429 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1430 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1431 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1432 break;
1433 }
1434 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1435 ar = (AsyncResult) msg.obj;
1436 request = (MainThreadRequest) ar.userObj;
1437 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1438 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1439 args.second.accept(ar.exception == null);
1440 notifyRequester(request);
1441 break;
1442 }
yincheng zhao2737e882019-09-06 17:06:54 -07001443 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1444 ar = (AsyncResult) msg.obj;
1445 request = (MainThreadRequest) ar.userObj;
1446 if (ar.exception == null && ar.result != null) {
1447 request.result = ar.result;
1448 } else {
1449 request.result = -1;
1450 loge("Failed to set Forbidden Plmns");
1451 if (ar.result == null) {
1452 loge("setForbidenPlmns: Empty response");
1453 } else if (ar.exception != null) {
1454 loge("setForbiddenPlmns: Exception: " + ar.exception);
1455 request.result = -1;
1456 } else {
1457 loge("setForbiddenPlmns: Unknown exception");
1458 }
1459 }
1460 notifyRequester(request);
1461 break;
1462 case CMD_SET_FORBIDDEN_PLMNS:
1463 request = (MainThreadRequest) msg.obj;
1464 uiccCard = getUiccCardFromRequest(request);
1465 if (uiccCard == null) {
1466 loge("setForbiddenPlmns: UiccCard is null");
1467 request.result = -1;
1468 notifyRequester(request);
1469 break;
1470 }
1471 Pair<Integer, List<String>> setFplmnsArgs =
1472 (Pair<Integer, List<String>>) request.argument;
1473 appType = setFplmnsArgs.first;
1474 List<String> fplmns = setFplmnsArgs.second;
1475 uiccApp = uiccCard.getApplicationByType(appType);
1476 if (uiccApp == null) {
1477 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1478 request.result = -1;
1479 loge("Failed to get UICC App");
1480 notifyRequester(request);
1481 } else {
1482 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1483 ((SIMRecords) uiccApp.getIccRecords())
1484 .setForbiddenPlmns(onCompleted, fplmns);
1485 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001486 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001487 case CMD_ERASE_MODEM_CONFIG:
1488 request = (MainThreadRequest) msg.obj;
1489 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1490 defaultPhone.eraseModemConfig(onCompleted);
1491 break;
1492 case EVENT_ERASE_MODEM_CONFIG_DONE:
1493 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001494 break;
zoey chene02881a2019-12-30 16:11:23 +08001495
1496 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1497 request = (MainThreadRequest) msg.obj;
1498 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1499 Pair<String, String> changed = (Pair<String, String>) request.argument;
1500 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1501 changed.first, changed.second, onCompleted);
1502 break;
1503 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1504 ar = (AsyncResult) msg.obj;
1505 request = (MainThreadRequest) ar.userObj;
1506 if (ar.exception == null) {
1507 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1508 } else {
1509 request.result = msg.arg1;
1510 }
1511 notifyRequester(request);
1512 break;
1513
1514 case CMD_SET_ICC_LOCK_ENABLED:
1515 request = (MainThreadRequest) msg.obj;
1516 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1517 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1518 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1519 enabled.first, enabled.second, onCompleted);
1520 break;
1521 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1522 ar = (AsyncResult) msg.obj;
1523 request = (MainThreadRequest) ar.userObj;
1524 if (ar.exception == null) {
1525 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1526 } else {
1527 request.result = msg.arg1;
1528 }
1529 notifyRequester(request);
1530 break;
1531
Peter Wangdafb9ac2020-01-15 14:13:38 -08001532 case MSG_NOTIFY_USER_ACTIVITY:
1533 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001534 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001535 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1536 getDefaultPhone().getContext().sendBroadcastAsUser(
1537 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1538 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001539 default:
1540 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1541 break;
1542 }
1543 }
Jake Hambye994d462014-02-03 13:10:13 -08001544
Pengquan Menga1bb6272018-09-06 09:59:22 -07001545 private void notifyRequester(MainThreadRequest request) {
1546 synchronized (request) {
1547 request.notifyAll();
1548 }
1549 }
1550
Jake Hambye994d462014-02-03 13:10:13 -08001551 private void handleNullReturnEvent(Message msg, String command) {
1552 AsyncResult ar = (AsyncResult) msg.obj;
1553 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1554 if (ar.exception == null) {
1555 request.result = true;
1556 } else {
1557 request.result = false;
1558 if (ar.exception instanceof CommandException) {
1559 loge(command + ": CommandException: " + ar.exception);
1560 } else {
1561 loge(command + ": Unknown exception");
1562 }
1563 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001564 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
1568 /**
1569 * Posts the specified command to be executed on the main thread,
1570 * waits for the request to complete, and returns the result.
1571 * @see #sendRequestAsync
1572 */
1573 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001574 return sendRequest(
1575 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001576 }
1577
1578 /**
1579 * Posts the specified command to be executed on the main thread,
1580 * waits for the request to complete, and returns the result.
1581 * @see #sendRequestAsync
1582 */
1583 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1584 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001585 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001586 }
1587
1588 /**
1589 * Posts the specified command to be executed on the main thread,
1590 * waits for the request to complete, and returns the result.
1591 * @see #sendRequestAsync
1592 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001593 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001594 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001595 }
1596
1597 /**
1598 * Posts the specified command to be executed on the main thread,
1599 * waits for the request to complete, and returns the result.
1600 * @see #sendRequestAsync
1601 */
Nathan Harold92bed182018-10-12 18:16:49 -07001602 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1603 return sendRequest(command, argument, subId, null, workSource);
1604 }
1605
1606 /**
1607 * Posts the specified command to be executed on the main thread,
1608 * waits for the request to complete, and returns the result.
1609 * @see #sendRequestAsync
1610 */
1611 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1612 return sendRequest(
1613 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1614 }
1615
1616 /**
1617 * Posts the specified command to be executed on the main thread,
1618 * waits for the request to complete, and returns the result.
1619 * @see #sendRequestAsync
1620 */
1621 private Object sendRequest(
1622 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1624 throw new RuntimeException("This method will deadlock if called from the main thread.");
1625 }
1626
Nathan Harold92bed182018-10-12 18:16:49 -07001627 MainThreadRequest request = null;
1628 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1629 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1630 } else if (phone != null) {
1631 request = new MainThreadRequest(argument, phone, workSource);
1632 } else {
1633 request = new MainThreadRequest(argument, subId, workSource);
1634 }
1635
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 Message msg = mMainThreadHandler.obtainMessage(command, request);
1637 msg.sendToTarget();
1638
1639 // Wait for the request to complete
1640 synchronized (request) {
1641 while (request.result == null) {
1642 try {
1643 request.wait();
1644 } catch (InterruptedException e) {
1645 // Do nothing, go back and wait until the request is complete
1646 }
1647 }
1648 }
1649 return request.result;
1650 }
1651
1652 /**
1653 * Asynchronous ("fire and forget") version of sendRequest():
1654 * Posts the specified command to be executed on the main thread, and
1655 * returns immediately.
1656 * @see #sendRequest
1657 */
1658 private void sendRequestAsync(int command) {
1659 mMainThreadHandler.sendEmptyMessage(command);
1660 }
1661
1662 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001663 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001664 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001665 */
1666 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001667 sendRequestAsync(command, argument, null, null);
1668 }
1669
1670 /**
1671 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1672 * @see {@link #sendRequest(int,Object)}
1673 */
1674 private void sendRequestAsync(
1675 int command, Object argument, Phone phone, WorkSource workSource) {
1676 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001677 Message msg = mMainThreadHandler.obtainMessage(command, request);
1678 msg.sendToTarget();
1679 }
1680
1681 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 * Initialize the singleton PhoneInterfaceManager instance.
1683 * This is only done once, at startup, from PhoneApp.onCreate().
1684 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001685 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 synchronized (PhoneInterfaceManager.class) {
1687 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001688 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 } else {
1690 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1691 }
1692 return sInstance;
1693 }
1694 }
1695
1696 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001697 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001700 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001701 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1703 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001704 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001705 mTelephonySharedPreferences =
1706 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001707 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001708 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001709 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001710
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 publish();
1712 }
1713
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001714 private Phone getDefaultPhone() {
1715 Phone thePhone = getPhone(getDefaultSubscription());
1716 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1717 }
1718
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 private void publish() {
1720 if (DBG) log("publish: " + this);
1721
Peter Wangc035ce42020-01-08 21:00:22 -08001722 TelephonyFrameworkInitializer
1723 .getTelephonyServiceManager()
1724 .getTelephonyServiceRegisterer()
1725 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
Stuart Scott584921c2015-01-15 17:10:34 -08001728 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001729 if (request.phone != null) {
1730 return request.phone;
1731 } else {
1732 return getPhoneFromSubId(request.subId);
1733 }
1734 }
1735
1736 private Phone getPhoneFromSubId(int subId) {
1737 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1738 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001739 }
1740
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001741 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1742 Phone phone = getPhoneFromRequest(request);
1743 return phone == null ? null :
1744 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1745 }
1746
Wink Saville36469e72014-06-11 15:17:00 -07001747 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001748 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001749 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751
Naina Nallurid63128d2019-09-17 14:10:30 -07001752 private void sendEraseModemConfig(Phone phone) {
1753 if (phone != null) {
1754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1755 mApp, phone.getSubId(), "eraseModemConfig");
1756 final long identity = Binder.clearCallingIdentity();
1757 try {
1758 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1759 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
1762 }
1763 }
1764 }
1765
Peter Wang44b186e2020-01-13 23:33:09 -08001766 private boolean isImsAvailableOnDevice() {
1767 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1768 if (pm == null) {
1769 // For some reason package manger is not available.. This will fail internally anyway,
1770 // so do not throw error and allow.
1771 return true;
1772 }
1773 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1774 }
1775
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001777 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001778 }
1779
Wink Savilleb564aae2014-10-23 10:18:09 -07001780 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 if (DBG) log("dial: " + number);
1782 // No permission check needed here: This is just a wrapper around the
1783 // ACTION_DIAL intent, which is available to any app since it puts up
1784 // the UI before it does anything.
1785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 final long identity = Binder.clearCallingIdentity();
1787 try {
1788 String url = createTelUrl(number);
1789 if (url == null) {
1790 return;
1791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001793 // PENDING: should we just silently fail if phone is offhook or ringing?
1794 PhoneConstants.State state = mCM.getState(subId);
1795 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1796 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1797 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1798 mApp.startActivity(intent);
1799 }
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 }
1803 }
1804
1805 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001806 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001807 }
1808
Wink Savilleb564aae2014-10-23 10:18:09 -07001809 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 if (DBG) log("call: " + number);
1811
1812 // This is just a wrapper around the ACTION_CALL intent, but we still
1813 // need to do a permission check since we're calling startActivity()
1814 // from the context of the phone app.
1815 enforceCallPermission();
1816
Jordan Liu1617b712019-07-10 15:06:26 -07001817 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 != AppOpsManager.MODE_ALLOWED) {
1819 return;
1820 }
1821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 String url = createTelUrl(number);
1825 if (url == null) {
1826 return;
1827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001829 boolean isValid = false;
1830 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1831 if (slist != null) {
1832 for (SubscriptionInfo subInfoRecord : slist) {
1833 if (subInfoRecord.getSubscriptionId() == subId) {
1834 isValid = true;
1835 break;
1836 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001837 }
Wink Saville08874612014-08-31 19:19:58 -07001838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001839 if (!isValid) {
1840 return;
1841 }
Wink Saville08874612014-08-31 19:19:58 -07001842
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001843 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1844 intent.putExtra(SUBSCRIPTION_KEY, subId);
1845 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1846 mApp.startActivity(intent);
1847 } finally {
1848 Binder.restoreCallingIdentity(identity);
1849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 }
1851
Wink Savilleb564aae2014-10-23 10:18:09 -07001852 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001853 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001854 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1855 }
1856
Wink Savilleb564aae2014-10-23 10:18:09 -07001857 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001858 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001859 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1860 }
1861
Wink Savilleb564aae2014-10-23 10:18:09 -07001862 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001864
1865 final long identity = Binder.clearCallingIdentity();
1866 try {
1867 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1868 checkSimPin.start();
1869 return checkSimPin.unlockSim(null, pin);
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
1872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
Wink Savilleb564aae2014-10-23 10:18:09 -07001875 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001877
1878 final long identity = Binder.clearCallingIdentity();
1879 try {
1880 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1881 checkSimPuk.start();
1882 return checkSimPuk.unlockSim(puk, pin);
1883 } finally {
1884 Binder.restoreCallingIdentity(identity);
1885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 }
1887
1888 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001889 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 * a synchronous one.
1891 */
1892 private static class UnlockSim extends Thread {
1893
1894 private final IccCard mSimCard;
1895
1896 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001897 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1898 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899
1900 // For replies from SimCard interface
1901 private Handler mHandler;
1902
1903 // For async handler to identify request type
1904 private static final int SUPPLY_PIN_COMPLETE = 100;
1905
1906 public UnlockSim(IccCard simCard) {
1907 mSimCard = simCard;
1908 }
1909
1910 @Override
1911 public void run() {
1912 Looper.prepare();
1913 synchronized (UnlockSim.this) {
1914 mHandler = new Handler() {
1915 @Override
1916 public void handleMessage(Message msg) {
1917 AsyncResult ar = (AsyncResult) msg.obj;
1918 switch (msg.what) {
1919 case SUPPLY_PIN_COMPLETE:
1920 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1921 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001922 mRetryCount = msg.arg1;
1923 if (ar.exception != null) {
1924 if (ar.exception instanceof CommandException &&
1925 ((CommandException)(ar.exception)).getCommandError()
1926 == CommandException.Error.PASSWORD_INCORRECT) {
1927 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001928 } //When UiccCardApp dispose,handle message and return exception
1929 else if (ar.exception instanceof CommandException &&
1930 ((CommandException) (ar.exception)).getCommandError()
1931 == CommandException.Error.ABORTED) {
1932 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001933 } else {
1934 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1935 }
1936 } else {
1937 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 mDone = true;
1940 UnlockSim.this.notifyAll();
1941 }
1942 break;
1943 }
1944 }
1945 };
1946 UnlockSim.this.notifyAll();
1947 }
1948 Looper.loop();
1949 }
1950
1951 /*
1952 * Use PIN or PUK to unlock SIM card
1953 *
1954 * If PUK is null, unlock SIM card with PIN
1955 *
1956 * If PUK is not null, unlock SIM card with PUK and set PIN code
1957 */
Wink Saville9de0f752013-10-22 19:04:03 -07001958 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959
1960 while (mHandler == null) {
1961 try {
1962 wait();
1963 } catch (InterruptedException e) {
1964 Thread.currentThread().interrupt();
1965 }
1966 }
1967 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1968
1969 if (puk == null) {
1970 mSimCard.supplyPin(pin, callback);
1971 } else {
1972 mSimCard.supplyPuk(puk, pin, callback);
1973 }
1974
1975 while (!mDone) {
1976 try {
1977 Log.d(LOG_TAG, "wait for done");
1978 wait();
1979 } catch (InterruptedException e) {
1980 // Restore the interrupted status
1981 Thread.currentThread().interrupt();
1982 }
1983 }
1984 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001985 int[] resultArray = new int[2];
1986 resultArray[0] = mResult;
1987 resultArray[1] = mRetryCount;
1988 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990 }
1991
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001992 /**
1993 * This method has been removed due to privacy and stability concerns.
1994 */
1995 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001997 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
1998 return;
Wink Saville36469e72014-06-11 15:17:00 -07001999 }
2000
Nathan Harold1f889d82020-06-04 17:05:26 -07002001 @Override
2002 public void updateServiceLocationWithPackageName(String callingPackage) {
2003 mApp.getSystemService(AppOpsManager.class)
2004 .checkPackage(Binder.getCallingUid(), callingPackage);
2005
2006 final int targetSdk = getTargetSdk(callingPackage);
2007 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2008 // Callers targeting S have no business invoking this method.
2009 return;
2010 }
2011
2012 LocationAccessPolicy.LocationPermissionResult locationResult =
2013 LocationAccessPolicy.checkLocationPermission(mApp,
2014 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2015 .setCallingPackage(callingPackage)
2016 .setCallingFeatureId(null)
2017 .setCallingPid(Binder.getCallingPid())
2018 .setCallingUid(Binder.getCallingUid())
2019 .setMethod("updateServiceLocation")
2020 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2021 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2022 .build());
2023 // Apps that lack location permission have no business calling this method;
2024 // however, because no permission was declared in the public API, denials must
2025 // all be "soft".
2026 switch (locationResult) {
2027 case DENIED_HARD: /* fall through */
2028 case DENIED_SOFT:
2029 return;
2030 }
2031
2032 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002033 final long identity = Binder.clearCallingIdentity();
2034 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002035 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002037 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 }
2039 } finally {
2040 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 }
2043
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002044 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002045 @Override
2046 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002047 return isRadioOnWithFeature(callingPackage, null);
2048 }
2049
2050
2051 @Override
2052 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2053 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2054 callingFeatureId);
2055 }
2056
2057 @Deprecated
2058 @Override
2059 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2060 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002061 }
2062
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002064 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2065 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002067 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002068 return false;
2069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002070
2071 final long identity = Binder.clearCallingIdentity();
2072 try {
2073 return isRadioOnForSubscriber(subId);
2074 } finally {
2075 Binder.restoreCallingIdentity(identity);
2076 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002077 }
2078
2079 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080 final long identity = Binder.clearCallingIdentity();
2081 try {
2082 final Phone phone = getPhone(subId);
2083 if (phone != null) {
2084 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2085 } else {
2086 return false;
2087 }
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 }
2092
2093 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002094 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 }
Wink Saville36469e72014-06-11 15:17:00 -07002096
Wink Savilleb564aae2014-10-23 10:18:09 -07002097 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099
2100 final long identity = Binder.clearCallingIdentity();
2101 try {
2102 final Phone phone = getPhone(subId);
2103 if (phone != null) {
2104 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2105 }
2106 } finally {
2107 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002108 }
Wink Saville36469e72014-06-11 15:17:00 -07002109 }
2110
2111 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002112 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002113 }
2114
Wink Savilleb564aae2014-10-23 10:18:09 -07002115 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002116 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002117
2118 final long identity = Binder.clearCallingIdentity();
2119 try {
2120 final Phone phone = getPhone(subId);
2121 if (phone == null) {
2122 return false;
2123 }
2124 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2125 toggleRadioOnOffForSubscriber(subId);
2126 }
2127 return true;
2128 } finally {
2129 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002130 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 }
Wink Saville36469e72014-06-11 15:17:00 -07002132
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002133 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002134 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002135 /*
2136 * If any of the Radios are available, it will need to be
2137 * shutdown. So return true if any Radio is available.
2138 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 final long identity = Binder.clearCallingIdentity();
2140 try {
2141 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2142 Phone phone = PhoneFactory.getPhone(i);
2143 if (phone != null && phone.isRadioAvailable()) return true;
2144 }
2145 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2146 return false;
2147 } finally {
2148 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002149 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002150 }
2151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002153 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002154 enforceModifyPermission();
2155
2156 final long identity = Binder.clearCallingIdentity();
2157 try {
2158 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2159 logv("Shutting down Phone " + i);
2160 shutdownRadioUsingPhoneId(i);
2161 }
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002164 }
2165 }
2166
2167 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002168 Phone phone = PhoneFactory.getPhone(phoneId);
2169 if (phone != null && phone.isRadioAvailable()) {
2170 phone.shutdownRadio();
2171 }
2172 }
2173
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002175 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176
2177 final long identity = Binder.clearCallingIdentity();
2178 try {
2179 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2180 if (defaultPhone != null) {
2181 defaultPhone.setRadioPower(turnOn);
2182 return true;
2183 } else {
2184 loge("There's no default phone.");
2185 return false;
2186 }
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002189 }
Wink Saville36469e72014-06-11 15:17:00 -07002190 }
2191
Wink Savilleb564aae2014-10-23 10:18:09 -07002192 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002194
2195 final long identity = Binder.clearCallingIdentity();
2196 try {
2197 final Phone phone = getPhone(subId);
2198 if (phone != null) {
2199 phone.setRadioPower(turnOn);
2200 return true;
2201 } else {
2202 return false;
2203 }
2204 } finally {
2205 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 }
2208
Wink Saville36469e72014-06-11 15:17:00 -07002209 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002210 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 public boolean enableDataConnectivity() {
2212 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002213
2214 final long identity = Binder.clearCallingIdentity();
2215 try {
2216 int subId = mSubscriptionController.getDefaultDataSubId();
2217 final Phone phone = getPhone(subId);
2218 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002219 phone.getDataEnabledSettings().setDataEnabled(
2220 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002221 return true;
2222 } else {
2223 return false;
2224 }
2225 } finally {
2226 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 }
2229
Wink Saville36469e72014-06-11 15:17:00 -07002230 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002231 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 public boolean disableDataConnectivity() {
2233 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002234
2235 final long identity = Binder.clearCallingIdentity();
2236 try {
2237 int subId = mSubscriptionController.getDefaultDataSubId();
2238 final Phone phone = getPhone(subId);
2239 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002240 phone.getDataEnabledSettings().setDataEnabled(
2241 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 return true;
2243 } else {
2244 return false;
2245 }
2246 } finally {
2247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 }
2250
Sanket Padawe356d7632015-06-22 14:03:32 -07002251 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002252 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253 final long identity = Binder.clearCallingIdentity();
2254 try {
2255 final Phone phone = getPhone(subId);
2256 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002257 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258 } else {
2259 return false;
2260 }
2261 } finally {
2262 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 }
2265
2266 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002267 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002268 }
2269
pkanwarae03a6b2016-11-06 20:37:09 -08002270 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271 enforceCallPermission();
2272
2273 final long identity = Binder.clearCallingIdentity();
2274 try {
2275 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2276 return;
2277 }
2278 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2279 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2280 } finally {
2281 Binder.restoreCallingIdentity(identity);
2282 }
pkanwar32d516d2016-10-14 19:37:38 -07002283 };
2284
Wink Savilleb564aae2014-10-23 10:18:09 -07002285 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287
2288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2291 return false;
2292 }
2293 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2294 } finally {
2295 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002300 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002301 }
2302
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002303 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002304 final long identity = Binder.clearCallingIdentity();
2305 try {
2306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2308 PhoneConstantConversions.convertCallState(phone.getState());
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
2311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
Sanket Padawe356d7632015-06-22 14:03:32 -07002314 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002315 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002316 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2317 }
2318
2319 @Override
2320 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002321 final long identity = Binder.clearCallingIdentity();
2322 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002323 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324 if (phone != null) {
2325 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2326 } else {
2327 return PhoneConstantConversions.convertDataState(
2328 PhoneConstants.DataState.DISCONNECTED);
2329 }
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334
Sanket Padawe356d7632015-06-22 14:03:32 -07002335 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002336 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002337 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2338 }
2339
2340 @Override
2341 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342 final long identity = Binder.clearCallingIdentity();
2343 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002344 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345 if (phone != null) {
2346 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2347 } else {
2348 return TelephonyManager.DATA_ACTIVITY_NONE;
2349 }
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
2355 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002356 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002357 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002358 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002359
2360 LocationAccessPolicy.LocationPermissionResult locationResult =
2361 LocationAccessPolicy.checkLocationPermission(mApp,
2362 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2363 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002364 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002365 .setCallingPid(Binder.getCallingPid())
2366 .setCallingUid(Binder.getCallingUid())
2367 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002368 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002369 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2370 .build());
2371 switch (locationResult) {
2372 case DENIED_HARD:
2373 throw new SecurityException("Not allowed to access cell location");
2374 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002375 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2376 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 }
2378
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002379 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002383 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002384 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002385 } finally {
2386 Binder.restoreCallingIdentity(identity);
2387 }
Svetoslav64fad262015-04-14 14:35:21 -07002388 }
2389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002391 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002392 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2393 // registered cell info, so return a NULL country instead.
2394 final long identity = Binder.clearCallingIdentity();
2395 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002396 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2397 // Get default phone in this case.
2398 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2399 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002400 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002401 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002402 if (phone == null) return "";
2403 ServiceStateTracker sst = phone.getServiceStateTracker();
2404 if (sst == null) return "";
2405 LocaleTracker lt = sst.getLocaleTracker();
2406 if (lt == null) return "";
2407 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2408 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2409 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002410 } finally {
2411 Binder.restoreCallingIdentity(identity);
2412 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002413 }
2414
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002415 /**
2416 * This method was removed due to potential issues caused by performing partial
2417 * updates of service state, and lack of a credible use case.
2418 *
2419 * This has the ability to break the telephony implementation by disabling notification of
2420 * changes in device connectivity. DO NOT USE THIS!
2421 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002422 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 public void enableLocationUpdates() {
2424 mApp.enforceCallingOrSelfPermission(
2425 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
2427
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002428 /**
2429 * This method was removed due to potential issues caused by performing partial
2430 * updates of service state, and lack of a credible use case.
2431 *
2432 * This has the ability to break the telephony implementation by disabling notification of
2433 * changes in device connectivity. DO NOT USE THIS!
2434 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 @Override
2436 public void disableLocationUpdates() {
2437 mApp.enforceCallingOrSelfPermission(
2438 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 }
2440
Nathan Harold31d7ff32018-10-15 20:20:30 -07002441 /**
2442 * Returns the target SDK version number for a given package name.
2443 *
Nathan Haroldec184742019-07-10 17:04:16 -07002444 * This call MUST be invoked before clearing the calling UID.
2445 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002446 * @return target SDK if the package is found or INT_MAX.
2447 */
2448 private int getTargetSdk(String packageName) {
2449 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002450 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002451 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002452 if (ai != null) return ai.targetSdkVersion;
2453 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002454 loge("Failed to get package info for pkg="
2455 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002456 }
2457 return Integer.MAX_VALUE;
2458 }
2459
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 @Override
2461 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002462 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2463 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002464 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002465 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2466 throw new SecurityException(
2467 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2468 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002469
Jordan Liu1617b712019-07-10 15:06:26 -07002470 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2472 return null;
2473 }
Svetoslav64fad262015-04-14 14:35:21 -07002474
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002475 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002477 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002478 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479
Nathan Haroldf180aac2018-06-01 18:43:55 -07002480 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2481 for (CellInfo ci : info) {
2482 if (ci instanceof CellInfoGsm) {
2483 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2484 } else if (ci instanceof CellInfoWcdma) {
2485 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002488 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002491 private List<CellInfo> getCachedCellInfo() {
2492 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2493 for (Phone phone : PhoneFactory.getPhones()) {
2494 List<CellInfo> info = phone.getAllCellInfo();
2495 if (info != null) cellInfos.addAll(info);
2496 }
2497 return cellInfos;
2498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499
2500 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002501 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002502 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002503 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002504
2505 LocationAccessPolicy.LocationPermissionResult locationResult =
2506 LocationAccessPolicy.checkLocationPermission(mApp,
2507 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2508 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002509 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002510 .setCallingPid(Binder.getCallingPid())
2511 .setCallingUid(Binder.getCallingUid())
2512 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002513 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002514 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2515 .build());
2516 switch (locationResult) {
2517 case DENIED_HARD:
2518 throw new SecurityException("Not allowed to access cell info");
2519 case DENIED_SOFT:
2520 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 }
2522
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002523 final int targetSdk = getTargetSdk(callingPackage);
2524 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2525 return getCachedCellInfo();
2526 }
2527
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002528 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002529 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2533 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002534 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002535 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536 if (info != null) cellInfos.addAll(info);
2537 }
2538 return cellInfos;
2539 } finally {
2540 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 }
2542 }
2543
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002544 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002545 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2546 String callingFeatureId) {
2547 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2548 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002549 }
2550
2551 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002552 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2553 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002554 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002555 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002556 }
2557
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002558 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2559 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002560 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002561 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002562
2563 LocationAccessPolicy.LocationPermissionResult locationResult =
2564 LocationAccessPolicy.checkLocationPermission(mApp,
2565 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2566 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002567 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002568 .setCallingPid(Binder.getCallingPid())
2569 .setCallingUid(Binder.getCallingUid())
2570 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002571 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2572 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002573 .build());
2574 switch (locationResult) {
2575 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002576 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2577 // Safetynet logging for b/154934934
2578 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2579 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002580 throw new SecurityException("Not allowed to access cell info");
2581 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002582 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2583 // Safetynet logging for b/154934934
2584 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2585 }
Nathan Harold5320c422019-05-09 10:26:08 -07002586 try {
2587 cb.onCellInfo(new ArrayList<CellInfo>());
2588 } catch (RemoteException re) {
2589 // Drop without consequences
2590 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002591 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002592 }
2593
Nathan Harolda939a962019-05-09 10:13:47 -07002594
2595 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002596 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2597
2598 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2599 }
2600
2601 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002603 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002604 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605
2606 final long identity = Binder.clearCallingIdentity();
2607 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002608 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 } finally {
2610 Binder.restoreCallingIdentity(identity);
2611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613
Shishir Agrawala9f32182016-04-12 12:00:16 -07002614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002615 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002616 Phone phone = PhoneFactory.getPhone(slotIndex);
2617 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002618 return null;
2619 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002620 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002621 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002622 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002623 return null;
2624 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625
2626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 return phone.getImei();
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
2631 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002632 }
2633
2634 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002635 public String getTypeAllocationCodeForSlot(int slotIndex) {
2636 Phone phone = PhoneFactory.getPhone(slotIndex);
2637 String tac = null;
2638 if (phone != null) {
2639 String imei = phone.getImei();
2640 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2641 }
2642 return tac;
2643 }
2644
2645 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002646 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002647 Phone phone = PhoneFactory.getPhone(slotIndex);
2648 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002649 return null;
2650 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002651
Jeff Davidson913390f2018-02-23 17:11:49 -08002652 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002653 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002654 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002655 return null;
2656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657
2658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 return phone.getMeid();
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
Jack Yu2af8d712017-03-15 17:14:14 -07002664 }
2665
2666 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002667 public String getManufacturerCodeForSlot(int slotIndex) {
2668 Phone phone = PhoneFactory.getPhone(slotIndex);
2669 String manufacturerCode = null;
2670 if (phone != null) {
2671 String meid = phone.getMeid();
2672 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2673 }
2674 return manufacturerCode;
2675 }
2676
2677 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002678 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2679 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002680 Phone phone = PhoneFactory.getPhone(slotIndex);
2681 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002682 return null;
2683 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002684 int subId = phone.getSubId();
2685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002686 mApp, subId, callingPackage, callingFeatureId,
2687 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002688 return null;
2689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690
2691 final long identity = Binder.clearCallingIdentity();
2692 try {
2693 return phone.getDeviceSvn();
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
2696 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002697 }
2698
fionaxu43304da2017-11-27 22:51:16 -08002699 @Override
2700 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 final Phone phone = getPhone(subId);
2704 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
2707 }
fionaxu43304da2017-11-27 22:51:16 -08002708 }
2709
2710 @Override
2711 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 final long identity = Binder.clearCallingIdentity();
2713 try {
2714 final Phone phone = getPhone(subId);
2715 return phone == null ? null : phone.getCarrierName();
2716 } finally {
2717 Binder.restoreCallingIdentity(identity);
2718 }
fionaxu43304da2017-11-27 22:51:16 -08002719 }
2720
calvinpanffe225e2018-11-01 19:43:06 +08002721 @Override
chen xu0026ca62019-03-06 15:28:50 -08002722 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 final Phone phone = getPhone(subId);
2726 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002727 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002728 } finally {
2729 Binder.restoreCallingIdentity(identity);
2730 }
2731 }
2732
2733 @Override
chen xu0026ca62019-03-06 15:28:50 -08002734 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002738 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002739 } finally {
2740 Binder.restoreCallingIdentity(identity);
2741 }
2742 }
2743
chen xu651eec72018-11-11 19:03:44 -08002744 @Override
chen xu864e11c2018-12-06 22:10:03 -08002745 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2746 if (!isSubscriptionMccMnc) {
2747 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2748 }
chen xu651eec72018-11-11 19:03:44 -08002749 final Phone phone = PhoneFactory.getPhone(slotIndex);
2750 if (phone == null) {
2751 return TelephonyManager.UNKNOWN_CARRIER_ID;
2752 }
2753 final long identity = Binder.clearCallingIdentity();
2754 try {
2755 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
2758 }
2759 }
2760
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 //
2762 // Internal helper methods.
2763 //
2764
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002765 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2767 *
2768 * @throws SecurityException if the caller does not have the required permission
2769 */
2770 private void enforceModifyPermission() {
2771 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2772 }
2773
Shuo Qiancd19c462020-01-16 20:51:11 -08002774 /**
2775 * Make sure the caller is system.
2776 *
2777 * @throws SecurityException if the caller is not system.
2778 */
2779 private void enforceSystemCaller() {
2780 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2781 throw new SecurityException("Caller must be system");
2782 }
2783 }
2784
Shuo Qian3b6ee772019-11-13 17:43:31 -08002785 private void enforceActiveEmergencySessionPermission() {
2786 mApp.enforceCallingOrSelfPermission(
2787 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2788 }
2789
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 /**
2791 * Make sure the caller has the CALL_PHONE permission.
2792 *
2793 * @throws SecurityException if the caller does not have the required permission
2794 */
2795 private void enforceCallPermission() {
2796 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2797 }
2798
paulhu5a773602019-08-23 19:17:33 +08002799 private void enforceSettingsPermission() {
2800 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002801 }
2802
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002803 private String createTelUrl(String number) {
2804 if (TextUtils.isEmpty(number)) {
2805 return null;
2806 }
2807
Jake Hambye994d462014-02-03 13:10:13 -08002808 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 }
2810
Ihab Awadf9e92732013-12-05 18:02:52 -08002811 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2813 }
2814
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002815 private static void logv(String msg) {
2816 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2817 }
2818
Ihab Awadf9e92732013-12-05 18:02:52 -08002819 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2821 }
2822
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002823 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002825 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002826 }
2827
Sanket Padawe356d7632015-06-22 14:03:32 -07002828 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002829 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 final Phone phone = PhoneFactory.getPhone(slotIndex);
2833 if (phone == null) {
2834 return PhoneConstants.PHONE_TYPE_NONE;
2835 } else {
2836 return phone.getPhoneType();
2837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 }
2842
2843 /**
2844 * Returns the CDMA ERI icon index to display
2845 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002846 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002847 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2848 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2849 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002850 }
2851
Sanket Padawe356d7632015-06-22 14:03:32 -07002852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002853 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2854 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002856 mApp, subId, callingPackage, callingFeatureId,
2857 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002858 return -1;
2859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 final Phone phone = getPhone(subId);
2864 if (phone != null) {
2865 return phone.getCdmaEriIconIndex();
2866 } else {
2867 return -1;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 }
2873
2874 /**
2875 * Returns the CDMA ERI icon mode,
2876 * 0 - ON
2877 * 1 - FLASHING
2878 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002879 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002880 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2881 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2882 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002883 }
2884
Sanket Padawe356d7632015-06-22 14:03:32 -07002885 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002886 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2887 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002889 mApp, subId, callingPackage, callingFeatureId,
2890 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002891 return -1;
2892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893
2894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 final Phone phone = getPhone(subId);
2897 if (phone != null) {
2898 return phone.getCdmaEriIconMode();
2899 } else {
2900 return -1;
2901 }
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002905 }
2906
2907 /**
2908 * Returns the CDMA ERI text,
2909 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002910 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002911 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2912 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2913 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002914 }
2915
Sanket Padawe356d7632015-06-22 14:03:32 -07002916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002917 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2918 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002920 mApp, subId, callingPackage, callingFeatureId,
2921 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002922 return null;
2923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924
2925 final long identity = Binder.clearCallingIdentity();
2926 try {
2927 final Phone phone = getPhone(subId);
2928 if (phone != null) {
2929 return phone.getCdmaEriText();
2930 } else {
2931 return null;
2932 }
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002936 }
2937
2938 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002939 * Returns the CDMA MDN.
2940 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002941 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002942 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2944 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945
2946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002949 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950 return phone.getLine1Number();
2951 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002952 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002953 return null;
2954 }
2955 } finally {
2956 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002957 }
2958 }
2959
2960 /**
2961 * Returns the CDMA MIN.
2962 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002963 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002964 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2966 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967
2968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 final Phone phone = getPhone(subId);
2971 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2972 return phone.getCdmaMin();
2973 } else {
2974 return null;
2975 }
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002978 }
2979 }
2980
Hall Liud892bec2018-11-30 14:51:45 -08002981 @Override
2982 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2983 INumberVerificationCallback callback, String callingPackage) {
2984 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2985 != PERMISSION_GRANTED) {
2986 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2987 }
2988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2989
2990 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2991 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2992 throw new SecurityException("Calling package must be configured in the device config");
2993 }
2994
2995 if (range == null) {
2996 throw new NullPointerException("Range must be non-null");
2997 }
2998
2999 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003000 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003001
3002 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3003 }
3004
Junda Liuca05d5d2014-08-14 22:36:34 -07003005 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 * Returns true if CDMA provisioning needs to run.
3007 */
3008 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009 final long identity = Binder.clearCallingIdentity();
3010 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003011 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012 } finally {
3013 Binder.restoreCallingIdentity(identity);
3014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 }
3016
3017 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003018 * Sets the voice mail number of a given subId.
3019 */
3020 @Override
3021 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003022 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3023 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3028 new Pair<String, String>(alphaTag, number), new Integer(subId));
3029 return success;
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003033 }
3034
Ta-wei Yen87c49842016-05-13 21:19:52 -07003035 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003036 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003038 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3039 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003040 if (!TextUtils.equals(callingPackage, systemDialer)) {
3041 throw new SecurityException("caller must be system dialer");
3042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3047 if (phoneAccountHandle == null) {
3048 return null;
3049 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003050 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051 } finally {
3052 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003053 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003054 }
3055
3056 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003057 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3058 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003059 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003061 mApp, subId, callingPackage, callingFeatureId,
3062 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003063 return null;
3064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003066 final long identity = Binder.clearCallingIdentity();
3067 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003068 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003072 }
3073
3074 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003075 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3076 VisualVoicemailSmsFilterSettings settings) {
3077 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078
3079 final long identity = Binder.clearCallingIdentity();
3080 try {
3081 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003082 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003086 }
3087
3088 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003089 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3090 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003091
3092 final long identity = Binder.clearCallingIdentity();
3093 try {
3094 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003095 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003099 }
3100
3101 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003102 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3103 String callingPackage, int subId) {
3104 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105
3106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003109 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003113 }
3114
3115 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003116 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118
3119 final long identity = Binder.clearCallingIdentity();
3120 try {
3121 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003122 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 } finally {
3124 Binder.restoreCallingIdentity(identity);
3125 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003126 }
3127
3128 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003129 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3130 String callingAttributionTag, int subId, String number, int port, String text,
3131 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003132 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003133 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003134 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003135 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003136 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3137 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003138 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003139
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003140 /**
fionaxu0152e512016-11-14 13:36:14 -08003141 * Sets the voice activation state of a given subId.
3142 */
3143 @Override
3144 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3146 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147
3148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 final Phone phone = getPhone(subId);
3151 if (phone != null) {
3152 phone.setVoiceActivationState(activationState);
3153 } else {
3154 loge("setVoiceActivationState fails with invalid subId: " + subId);
3155 }
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003158 }
3159 }
3160
3161 /**
3162 * Sets the data activation state of a given subId.
3163 */
3164 @Override
3165 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3167 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168
3169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 final Phone phone = getPhone(subId);
3172 if (phone != null) {
3173 phone.setDataActivationState(activationState);
3174 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003175 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176 }
3177 } finally {
3178 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003179 }
3180 }
3181
3182 /**
3183 * Returns the voice activation state of a given subId.
3184 */
3185 @Override
3186 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003187 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188
fionaxu0152e512016-11-14 13:36:14 -08003189 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 if (phone != null) {
3193 return phone.getVoiceActivationState();
3194 } else {
3195 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3196 }
3197 } finally {
3198 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003199 }
3200 }
3201
3202 /**
3203 * Returns the data activation state of a given subId.
3204 */
3205 @Override
3206 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003207 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208
fionaxu0152e512016-11-14 13:36:14 -08003209 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 if (phone != null) {
3213 return phone.getDataActivationState();
3214 } else {
3215 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3216 }
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003219 }
3220 }
3221
3222 /**
Wink Saville36469e72014-06-11 15:17:00 -07003223 * Returns the unread count of voicemails for a subId
3224 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003225 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003226 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3227 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003229 mApp, subId, callingPackage, callingFeatureId,
3230 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003231 return 0;
3232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 final Phone phone = getPhone(subId);
3236 if (phone != null) {
3237 return phone.getVoiceMessageCount();
3238 } else {
3239 return 0;
3240 }
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003244 }
3245
3246 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003247 * returns true, if the device is in a state where both voice and data
3248 * are supported simultaneously. This can change based on location or network condition.
3249 */
3250 @Override
3251 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 final Phone phone = getPhone(subId);
3255 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003259 }
3260
3261 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003262 * Send the dialer code if called from the current default dialer or the caller has
3263 * carrier privilege.
3264 * @param inputCode The dialer code to send
3265 */
3266 @Override
3267 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003268 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003270 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3271 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003272 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003273 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003274 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276
3277 final long identity = Binder.clearCallingIdentity();
3278 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003279 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
fionaxu235cc5e2017-03-06 22:25:57 -08003283 }
3284
Pengquan Menga1bb6272018-09-06 09:59:22 -07003285 @Override
3286 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003287 TelephonyPermissions
3288 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3289 mApp, subId, "getNetworkSelectionMode");
3290 final long identity = Binder.clearCallingIdentity();
3291 try {
3292 if (!isActiveSubscription(subId)) {
3293 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3294 }
3295 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003298 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003299 }
3300
Brad Ebinger35c841c2018-10-01 10:40:55 -07003301 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003302 public boolean isInEmergencySmsMode() {
3303 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 for (Phone phone : PhoneFactory.getPhones()) {
3307 if (phone.isInEmergencySmsMode()) {
3308 return true;
3309 }
3310 }
3311 } finally {
3312 Binder.restoreCallingIdentity(identity);
3313 }
3314 return false;
3315 }
3316
shilu366312e2019-12-17 09:28:10 -08003317 /**
3318 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3319 * @param subId The subscription to use to check the configuration.
3320 * @param c The callback that will be used to send the result.
3321 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003322 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003323 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3324 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003325 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3326 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003327
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003328 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3329 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3330 "IMS not available on device.");
3331 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 final long token = Binder.clearCallingIdentity();
3333 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003334 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003335 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003336 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003337 } catch (ImsException e) {
3338 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003339 } finally {
3340 Binder.restoreCallingIdentity(token);
3341 }
3342 }
3343
shilu366312e2019-12-17 09:28:10 -08003344 /**
3345 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3346 * @param subId The subscription to use to check the configuration.
3347 * @param c The callback that will be used to send the result.
3348 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003350 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003351 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3352 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003353 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3354 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3355 }
Meng Wangafbc5852019-09-19 17:37:13 -07003356 final long token = Binder.clearCallingIdentity();
3357 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003358 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003359 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3360 .removeRegistrationCallbackForSubscription(c, subId);
3361 } catch (ImsException e) {
3362 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3363 + "is inactive, ignoring unregister.");
3364 // If the subscription is no longer active, just return, since the callback
3365 // will already have been removed internally.
3366 } finally {
3367 Binder.restoreCallingIdentity(token);
3368 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 }
3370
Brad Ebingera34a6c22019-10-22 17:36:18 -07003371 /**
3372 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3373 */
3374 @Override
3375 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3376 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3377 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3378 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3379 "IMS not available on device.");
3380 }
3381 final long token = Binder.clearCallingIdentity();
3382 try {
3383 Phone phone = getPhone(subId);
3384 if (phone == null) {
3385 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3386 + subId + "'");
3387 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3388 }
3389 phone.getImsRegistrationState(regState -> {
3390 try {
3391 consumer.accept((regState == null)
3392 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3393 } catch (RemoteException e) {
3394 // Ignore if the remote process is no longer available to call back.
3395 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3396 }
3397 });
3398 } finally {
3399 Binder.restoreCallingIdentity(token);
3400 }
3401 }
3402
3403 /**
3404 * Get the transport type for the IMS service registration state.
3405 */
3406 @Override
3407 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003408 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3409 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003410 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3411 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3412 "IMS not available on device.");
3413 }
3414 final long token = Binder.clearCallingIdentity();
3415 try {
3416 Phone phone = getPhone(subId);
3417 if (phone == null) {
3418 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3419 + subId + "'");
3420 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3421 }
3422 phone.getImsRegistrationTech(regTech -> {
3423 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3424 int regTechConverted = (regTech == null)
3425 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3426 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3427 regTechConverted);
3428 try {
3429 consumer.accept(regTechConverted);
3430 } catch (RemoteException e) {
3431 // Ignore if the remote process is no longer available to call back.
3432 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3433 }
3434 });
3435 } finally {
3436 Binder.restoreCallingIdentity(token);
3437 }
3438 }
3439
shilu366312e2019-12-17 09:28:10 -08003440 /**
3441 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3442 * @param subId The subscription to use to check the configuration.
3443 * @param c The callback that will be used to send the result.
3444 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003445 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003446 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3447 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003448 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3449 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003450 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3451 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3452 "IMS not available on device.");
3453 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003454 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3455 final long token = Binder.clearCallingIdentity();
3456 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003457 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003458 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003459 } catch (ImsException e) {
3460 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 } finally {
3462 Binder.restoreCallingIdentity(token);
3463 }
3464 }
3465
shilu366312e2019-12-17 09:28:10 -08003466 /**
3467 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3468 * @param subId The subscription to use to check the configuration.
3469 * @param c The callback that will be used to send the result.
3470 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003471 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003472 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003473 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3474 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003475 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3476 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3477 }
Meng Wangafbc5852019-09-19 17:37:13 -07003478
3479 final long token = Binder.clearCallingIdentity();
3480 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003481 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003482 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003483 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003484 } catch (ImsException e) {
3485 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3486 + "is inactive, ignoring unregister.");
3487 // If the subscription is no longer active, just return, since the callback
3488 // will already have been removed internally.
3489 } finally {
3490 Binder.restoreCallingIdentity(token);
3491 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003492 }
3493
3494 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003495 public boolean isCapable(int subId, int capability, int regTech) {
3496 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003497 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3498 final long token = Binder.clearCallingIdentity();
3499 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003500 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003501 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003502 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003503 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3504 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003505 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003506 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3507 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003508 } finally {
3509 Binder.restoreCallingIdentity(token);
3510 }
3511 }
3512
3513 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003514 public boolean isAvailable(int subId, int capability, int regTech) {
3515 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003516 final long token = Binder.clearCallingIdentity();
3517 try {
3518 Phone phone = getPhone(subId);
3519 if (phone == null) return false;
3520 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003521 } catch (com.android.ims.ImsException e) {
3522 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3523 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 } finally {
3525 Binder.restoreCallingIdentity(token);
3526 }
3527 }
3528
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003529 /**
3530 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3531 * subscription.
3532 * @param subId The subscription to use to check the configuration.
3533 * @param callback The callback that will be used to send the result.
3534 * @param capability The MmTelFeature capability that will be used to send the result.
3535 * @param transportType The transport type of the MmTelFeature capability.
3536 */
3537 @Override
3538 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3539 int transportType) {
3540 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3541 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3542 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3543 "IMS not available on device.");
3544 }
3545 final long token = Binder.clearCallingIdentity();
3546 try {
3547 int slotId = getSlotIndex(subId);
3548 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3549 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3550 + subId + "'");
3551 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3552 }
3553 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3554 transportType, aBoolean -> {
3555 try {
3556 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3557 } catch (RemoteException e) {
3558 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3559 + "running. Ignore");
3560 }
3561 });
3562 } finally {
3563 Binder.restoreCallingIdentity(token);
3564 }
3565 }
3566
shilu366312e2019-12-17 09:28:10 -08003567 /**
3568 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3569 * @param subId The subscription to use to check the configuration.
3570 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003571 @Override
3572 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003573 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3574 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003575
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3577 final long token = Binder.clearCallingIdentity();
3578 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003579 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003580 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003581 } catch (ImsException e) {
3582 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 } finally {
3584 Binder.restoreCallingIdentity(token);
3585 }
3586 }
3587
3588 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003589 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003591 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003597 } catch (ImsException e) {
3598 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003599 } finally {
3600 Binder.restoreCallingIdentity(identity);
3601 }
3602 }
3603
shilu366312e2019-12-17 09:28:10 -08003604 /**
3605 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3606 * @param subId The subscription to use to check the configuration.
3607 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003609 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003610 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3611 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003615 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3616 } catch (ImsException e) {
3617 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 } finally {
3619 Binder.restoreCallingIdentity(identity);
3620 }
3621 }
3622
3623 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003624 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003626 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003630 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003631 } catch (ImsException e) {
3632 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003633 } finally {
3634 Binder.restoreCallingIdentity(identity);
3635 }
3636 }
3637
shilu366312e2019-12-17 09:28:10 -08003638 /**
3639 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3640 * @param subId The subscription to use to check the configuration.
3641 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 @Override
3643 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003644 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3645 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003649 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003650 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003651 } catch (ImsException e) {
3652 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
3656 }
3657
3658 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003659 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003661 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003665 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003666 } catch (ImsException e) {
3667 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
3671 }
3672
shilu366312e2019-12-17 09:28:10 -08003673 /**
3674 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3675 * @param subId The subscription to use to check the configuration.
3676 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 @Override
3678 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003679 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3680 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003684 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003685 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003686 } catch (ImsException e) {
3687 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 }
3692
3693 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003694 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003696 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003700 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003702 } catch (ImsException e) {
3703 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
3707 }
3708
3709 @Override
3710 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3712 "setVoWiFiNonPersistent");
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003716 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003717 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003718 } catch (ImsException e) {
3719 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
shilu366312e2019-12-17 09:28:10 -08003725 /**
3726 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3727 * @param subId The subscription to use to check the configuration.
3728 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 @Override
3730 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003731 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3732 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003736 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003738 } catch (ImsException e) {
3739 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
3743 }
3744
3745 @Override
3746 public void setVoWiFiModeSetting(int subId, int mode) {
3747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3748 "setVoWiFiModeSetting");
3749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003754 } catch (ImsException e) {
3755 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 } finally {
3757 Binder.restoreCallingIdentity(identity);
3758 }
3759 }
3760
3761 @Override
3762 public int getVoWiFiRoamingModeSetting(int subId) {
3763 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3764 final long identity = Binder.clearCallingIdentity();
3765 try {
3766 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003767 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003768 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003769 } catch (ImsException e) {
3770 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003771 } finally {
3772 Binder.restoreCallingIdentity(identity);
3773 }
3774 }
3775
3776 @Override
3777 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3779 "setVoWiFiRoamingModeSetting");
3780 final long identity = Binder.clearCallingIdentity();
3781 try {
3782 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003783 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003784 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003785 } catch (ImsException e) {
3786 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
3790 }
3791
3792 @Override
3793 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3795 "setRttCapabilityEnabled");
3796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003799 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3800 } catch (ImsException e) {
3801 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
3805 }
3806
shilu366312e2019-12-17 09:28:10 -08003807 /**
3808 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3809 * @param subId The subscription to use to check the configuration.
3810 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003811 @Override
3812 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003813 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3814 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 final long identity = Binder.clearCallingIdentity();
3816 try {
3817 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003818 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003820 } catch (ImsException e) {
3821 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 } finally {
3823 Binder.restoreCallingIdentity(identity);
3824 }
3825 }
3826
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003827 @Override
3828 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3829 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3830 final long identity = Binder.clearCallingIdentity();
3831 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003832 if (!isImsAvailableOnDevice()) {
3833 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3834 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003835 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003837 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003838 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003839 } catch (ImsException e) {
3840 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003841 } finally {
3842 Binder.restoreCallingIdentity(identity);
3843 }
3844 }
3845
3846 @Override
3847 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3848 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3849 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003850 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3851 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3852 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003853 try {
3854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003855 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003856 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003857 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003858 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3859 + "is inactive, ignoring unregister.");
3860 // If the subscription is no longer active, just return, since the callback will already
3861 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003862 } finally {
3863 Binder.restoreCallingIdentity(identity);
3864 }
3865 }
3866
allenwtsu99c623b2020-01-03 18:24:23 +08003867
3868 private void checkModifyPhoneStatePermission(int subId, String message) {
3869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3870 message);
3871 }
3872
3873 private boolean isImsProvisioningRequired(int subId, int capability,
3874 boolean isMmtelCapability) {
3875 Phone phone = getPhone(subId);
3876 if (phone == null) {
3877 loge("phone instance null for subid " + subId);
3878 return false;
3879 }
3880 if (isMmtelCapability) {
3881 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3882 return false;
3883 }
3884 } else {
3885 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3886 return false;
3887 }
3888 }
3889 return true;
3890 }
3891
3892 @Override
3893 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3894 boolean isProvisioned) {
3895 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3896
3897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3900 if (!isImsProvisioningRequired(subId, capability, false)) {
3901 return;
3902 }
3903
3904 // this capability requires provisioning, route to the correct API.
3905 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3906 switch (capability) {
3907 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3908 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3909 ims.setEabProvisioned(isProvisioned);
3910 break;
3911 default: {
3912 throw new IllegalArgumentException("Tried to set provisioning for "
3913 + "rcs capability '" + capability + "', which does not require "
3914 + "provisioning.");
3915 }
3916 }
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
3920
3921 }
3922
3923
3924 @Override
3925 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3926 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3930 if (!isImsProvisioningRequired(subId, capability, false)) {
3931 return true;
3932 }
3933
3934 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3935 switch (capability) {
3936 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3937 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3938 return ims.isEabProvisionedOnDevice();
3939
3940 default: {
3941 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3942 + "capability '" + capability + "', which does not require "
3943 + "provisioning.");
3944 }
3945 }
3946
3947 } finally {
3948 Binder.restoreCallingIdentity(identity);
3949 }
3950 }
3951
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003952 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003953 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3954 boolean isProvisioned) {
3955 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3956 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3957 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3958 }
allenwtsu99c623b2020-01-03 18:24:23 +08003959 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003960 final long identity = Binder.clearCallingIdentity();
3961 try {
3962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003963 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003964 return;
3965 }
3966
3967 // this capability requires provisioning, route to the correct API.
3968 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3969 switch (capability) {
3970 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3971 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3972 ims.setVolteProvisioned(isProvisioned);
3973 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3974 ims.setWfcProvisioned(isProvisioned);
3975 }
3976 break;
3977 }
3978 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3979 // There is currently no difference in VT provisioning type.
3980 ims.setVtProvisioned(isProvisioned);
3981 break;
3982 }
3983 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3984 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3985 // change the capability of the feature instead if needed.
3986 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3987 == isProvisioned) {
3988 // No change in provisioning.
3989 return;
3990 }
3991 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3992 try {
3993 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003994 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003995 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3996 + ", Exception" + e.getMessage());
3997 }
3998 break;
3999 }
4000 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004001 throw new IllegalArgumentException("Tried to set provisioning for "
4002 + "MmTel capability '" + capability + "', which does not require "
4003 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004004 }
4005 }
4006
4007 } finally {
4008 Binder.restoreCallingIdentity(identity);
4009 }
4010 }
4011
4012 @Override
4013 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4014 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4015 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4016 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4017 }
4018 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004022 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004023 return true;
4024 }
4025
4026 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4027 switch (capability) {
4028 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4029 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4030 return ims.isVolteProvisionedOnDevice();
4031 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4032 return ims.isWfcProvisionedOnDevice();
4033 }
4034 // This should never happen, since we are checking tech above to make sure it
4035 // is either LTE or IWLAN.
4036 throw new IllegalArgumentException("Invalid radio technology for voice "
4037 + "capability.");
4038 }
4039 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4040 // There is currently no difference in VT provisioning type.
4041 return ims.isVtProvisionedOnDevice();
4042 }
4043 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4044 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4045 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4046 }
4047 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004048 throw new IllegalArgumentException(
4049 "Tried to get provisioning for MmTel capability '" + capability
4050 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004051 }
4052 }
4053
4054 } finally {
4055 Binder.restoreCallingIdentity(identity);
4056 }
4057 }
4058
4059 @Override
4060 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4061 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4062 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4063 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4064 }
4065 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4066 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4067 return (provisionedBits & capability) > 0;
4068 }
4069
4070 @Override
4071 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4072 boolean isProvisioned) {
4073 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4074 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4075 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4076 }
4077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4078 "setProvisioningStatusForCapability");
4079 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4080 // If the current provisioning status for capability already matches isProvisioned,
4081 // do nothing.
4082 if (((provisionedBits & capability) > 0) == isProvisioned) {
4083 return;
4084 }
4085 if (isProvisioned) {
4086 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4087 } else {
4088 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4089 }
4090 }
4091
4092 /**
4093 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4094 * technology. The bitfield should mirror the bitfield defined by
4095 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4096 */
4097 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4098 String key = getMmTelProvisioningKey(subId, tech);
4099 // Default is no capabilities are provisioned.
4100 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4101 }
4102
4103 /**
4104 * Sets the MmTel capability provisioning bitfield (defined by
4105 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4106 * technology specified.
4107 *
4108 * Note: This is a synchronous command and should not be called on UI thread.
4109 */
4110 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4111 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4112 String key = getMmTelProvisioningKey(subId, tech);
4113 editor.putInt(key, newField);
4114 editor.commit();
4115 }
4116
4117 private static String getMmTelProvisioningKey(int subId, int tech) {
4118 // resulting key is provision_ims_mmtel_{subId}_{tech}
4119 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4120 }
4121
4122 /**
4123 * Query CarrierConfig to see if the specified capability requires provisioning for the
4124 * carrier associated with the subscription id.
4125 */
4126 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4127 int capability) {
4128 CarrierConfigManager configManager = new CarrierConfigManager(context);
4129 PersistableBundle c = configManager.getConfigForSubId(subId);
4130 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004131 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004132 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4133 false);
4134 boolean requireVoiceVtProvisioning = c.getBoolean(
4135 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4136
4137 // First check to make sure that the capability requires provisioning.
4138 switch (capability) {
4139 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4140 // intentional fallthrough
4141 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4142 if (requireVoiceVtProvisioning) {
4143 // Voice and Video requires provisioning
4144 return true;
4145 }
4146 break;
4147 }
4148 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4149 if (requireUtProvisioning) {
4150 // UT requires provisioning
4151 return true;
4152 }
4153 break;
4154 }
4155 }
4156 return false;
4157 }
4158
allenwtsu99c623b2020-01-03 18:24:23 +08004159 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4160 int capability) {
4161 CarrierConfigManager configManager = new CarrierConfigManager(context);
4162 PersistableBundle c = configManager.getConfigForSubId(subId);
4163
4164 boolean requireRcsProvisioning = c.getBoolean(
4165 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4166
4167 // First check to make sure that the capability requires provisioning.
4168 switch (capability) {
4169 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4170 // intentional fallthrough
4171 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4172 if (requireRcsProvisioning) {
4173 // OPTION or PRESENCE requires provisioning
4174 return true;
4175 }
4176 break;
4177 }
4178 }
4179 return false;
4180 }
4181
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004182 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004183 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004184 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4185 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4186 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004187 enforceReadPrivilegedPermission("getImsProvisioningInt");
4188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004191 int slotId = getSlotIndex(subId);
4192 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4193 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4194 + subId + "' for key:" + key);
4195 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4196 }
4197 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004198 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004199 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4200 + subId + "' for key:" + key);
4201 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004202 } finally {
4203 Binder.restoreCallingIdentity(identity);
4204 }
4205 }
4206
4207 @Override
4208 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004209 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4210 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4211 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004212 enforceReadPrivilegedPermission("getImsProvisioningString");
4213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004216 int slotId = getSlotIndex(subId);
4217 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4218 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4219 + subId + "' for key:" + key);
4220 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4221 }
4222 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004224 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4225 + subId + "' for key:" + key);
4226 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
4230 }
4231
4232 @Override
4233 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004234 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4235 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4236 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4238 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004239 final long identity = Binder.clearCallingIdentity();
4240 try {
4241 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004242 int slotId = getSlotIndex(subId);
4243 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4244 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4245 + subId + "' for key:" + key);
4246 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4247 }
4248 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004249 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004250 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4251 + "' for key:" + key);
4252 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
4256 }
4257
4258 @Override
4259 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004260 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4261 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4262 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4264 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004265 final long identity = Binder.clearCallingIdentity();
4266 try {
4267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004268 int slotId = getSlotIndex(subId);
4269 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4270 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4271 + subId + "' for key:" + key);
4272 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4273 }
4274 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004275 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004276 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4277 + "' for key:" + key);
4278 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
4282 }
4283
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004284 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 int slotId = SubscriptionManager.getSlotIndex(subId);
4286 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004287 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4288 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 }
4290 return slotId;
4291 }
4292
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004293 private int getSlotIndex(int subId) {
4294 int slotId = SubscriptionManager.getSlotIndex(subId);
4295 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4296 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4297 }
4298 return slotId;
4299 }
4300
Wink Saville36469e72014-06-11 15:17:00 -07004301 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004302 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004303 */
4304 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004305 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4306 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004307 final int targetSdk = getTargetSdk(callingPackage);
4308 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004309 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004310 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004311 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004312 mApp, subId, callingPackage, callingFeatureId,
4313 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004314 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4315 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 final long identity = Binder.clearCallingIdentity();
4318 try {
4319 final Phone phone = getPhone(subId);
4320 if (phone != null) {
4321 return phone.getServiceState().getDataNetworkType();
4322 } else {
4323 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4324 }
4325 } finally {
4326 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004328 }
4329
4330 /**
4331 * Returns the data network type
4332 */
4333 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004334 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4335 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4336 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004337 }
4338
4339 /**
4340 * Returns the data network type for a subId
4341 */
4342 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004343 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4344 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004346 mApp, subId, callingPackage, callingFeatureId,
4347 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004348 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4349 }
4350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351 final long identity = Binder.clearCallingIdentity();
4352 try {
4353 final Phone phone = getPhone(subId);
4354 if (phone != null) {
4355 return phone.getServiceState().getDataNetworkType();
4356 } else {
4357 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4358 }
4359 } finally {
4360 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004362 }
4363
4364 /**
Wink Saville36469e72014-06-11 15:17:00 -07004365 * Returns the Voice network type for a subId
4366 */
4367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004368 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4369 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004371 mApp, subId, callingPackage, callingFeatureId,
4372 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004373 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4374 }
4375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 final Phone phone = getPhone(subId);
4379 if (phone != null) {
4380 return phone.getServiceState().getVoiceNetworkType();
4381 } else {
4382 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4383 }
4384 } finally {
4385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004387 }
4388
4389 /**
4390 * @return true if a ICC card is present
4391 */
4392 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004393 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004394 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4395 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004396 }
4397
4398 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004399 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004400 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004401 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004402 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 final long identity = Binder.clearCallingIdentity();
4404 try {
4405 final Phone phone = PhoneFactory.getPhone(slotIndex);
4406 if (phone != null) {
4407 return phone.getIccCard().hasIccCard();
4408 } else {
4409 return false;
4410 }
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004414 }
4415
4416 /**
4417 * Return if the current radio is LTE on CDMA. This
4418 * is a tri-state return value as for a period of time
4419 * the mode may be unknown.
4420 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004421 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004422 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004423 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004424 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004425 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004426 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4427 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4428 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004429 }
4430
Sanket Padawe356d7632015-06-22 14:03:32 -07004431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004432 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4433 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004434 try {
4435 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4436 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004437 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4438 }
4439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 final long identity = Binder.clearCallingIdentity();
4441 try {
4442 final Phone phone = getPhone(subId);
4443 if (phone == null) {
4444 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4445 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004446 return TelephonyProperties.lte_on_cdma_device()
4447 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 }
4449 } finally {
4450 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004451 }
Wink Saville36469e72014-06-11 15:17:00 -07004452 }
4453
Wink Saville36469e72014-06-11 15:17:00 -07004454 /**
4455 * {@hide}
4456 * Returns Default subId, 0 in the case of single standby.
4457 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004458 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004459 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004460 }
4461
Shishir Agrawala9f32182016-04-12 12:00:16 -07004462 private int getSlotForDefaultSubscription() {
4463 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4464 }
4465
Wink Savilleb564aae2014-10-23 10:18:09 -07004466 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004467 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004468 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004469
Pengquan Menge92a50d2018-09-21 15:54:48 -07004470 private boolean isActiveSubscription(int subId) {
4471 return mSubscriptionController.isActiveSubId(subId);
4472 }
4473
Ihab Awadf2177b72013-11-25 13:33:23 -08004474 /**
4475 * @see android.telephony.TelephonyManager.WifiCallingChoices
4476 */
4477 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 final long identity = Binder.clearCallingIdentity();
4479 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004480 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4482 getWhenToMakeWifiCallsDefaultPreference());
4483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004486 }
4487
4488 /**
4489 * @see android.telephony.TelephonyManager.WifiCallingChoices
4490 */
4491 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 final long identity = Binder.clearCallingIdentity();
4493 try {
4494 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004495 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004500 }
4501
Sailesh Nepald1e68152013-12-12 19:08:02 -08004502 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004503 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004504 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004505 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004506
Jordan Liu4c733742019-02-28 12:03:40 -08004507 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4508 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4509 if (phoneId == -1) {
4510 throw new IllegalArgumentException("Given slot index: " + slotIndex
4511 + " does not correspond to an active phone");
4512 }
4513 return PhoneFactory.getPhone(phoneId);
4514 }
4515
Shishir Agrawal566b7612013-10-28 14:41:00 -07004516 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004517 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4518 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4520 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004522 if (DBG) {
4523 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4524 }
4525 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4526 p2);
4527 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004528
Jordan Liu4c733742019-02-28 12:03:40 -08004529
4530 @Override
4531 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4532 int slotIndex, String callingPackage, String aid, int p2) {
4533 enforceModifyPermission();
4534 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4535 if (DBG) {
4536 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4537 }
4538 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4539 callingPackage, aid, p2);
4540 }
4541
4542 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4543 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544 final long identity = Binder.clearCallingIdentity();
4545 try {
4546 if (TextUtils.equals(ISDR_AID, aid)) {
4547 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004548 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4549 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550 if (bestComponent == null
4551 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4552 loge("The calling package is not allowed to access ISD-R.");
4553 throw new SecurityException(
4554 "The calling package is not allowed to access ISD-R.");
4555 }
Derek Tan740e1672017-06-27 14:56:27 -07004556 }
Derek Tan740e1672017-06-27 14:56:27 -07004557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004558 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004559 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4560 null /* workSource */);
4561 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004562 return response;
4563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004566 }
4567
4568 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004569 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4571 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004572 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4573 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4574 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004575
Jordan Liu4c733742019-02-28 12:03:40 -08004576 @Override
4577 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4578 enforceModifyPermission();
4579 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4580 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4581 channel);
4582 }
4583
4584 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 final long identity = Binder.clearCallingIdentity();
4586 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004587 if (channel < 0) {
4588 return false;
4589 }
Jordan Liu4c733742019-02-28 12:03:40 -08004590 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4591 null /* workSource */);
4592 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593 return success;
4594 } finally {
4595 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004596 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004597 }
4598
4599 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004600 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004601 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4603 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004604 if (DBG) {
4605 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4606 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4607 + p3 + " data=" + data);
4608 }
4609 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4610 command, p1, p2, p3, data);
4611 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004612
Jordan Liu4c733742019-02-28 12:03:40 -08004613 @Override
4614 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4615 int command, int p1, int p2, int p3, String data) {
4616 enforceModifyPermission();
4617 if (DBG) {
4618 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4619 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4620 + p3 + " data=" + data);
4621 }
4622 return iccTransmitApduLogicalChannelWithPermission(
4623 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4624 data);
4625 }
4626
4627 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4628 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 final long identity = Binder.clearCallingIdentity();
4630 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004631 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 return "";
4633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004636 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4637 null /* workSource */);
4638 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 // Append the returned status code to the end of the response payload.
4641 String s = Integer.toHexString(
4642 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4643 if (response.payload != null) {
4644 s = IccUtils.bytesToHexString(response.payload) + s;
4645 }
4646 return s;
4647 } finally {
4648 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004649 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004650 }
Jake Hambye994d462014-02-03 13:10:13 -08004651
Evan Charltonc66da362014-05-16 14:06:40 -07004652 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004653 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4654 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4656 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004658 if (DBG) {
4659 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4660 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4661 }
4662 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4663 cla, command, p1, p2, p3, data);
4664 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004665
Jordan Liu4c733742019-02-28 12:03:40 -08004666 @Override
4667 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4668 int command, int p1, int p2, int p3, String data) {
4669 enforceModifyPermission();
4670 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4671 if (DBG) {
4672 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4673 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4674 + " data=" + data);
4675 }
4676
4677 return iccTransmitApduBasicChannelWithPermission(
4678 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4679 p2, p3, data);
4680 }
4681
4682 // open APDU basic channel assuming the caller has sufficient permissions
4683 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4684 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 final long identity = Binder.clearCallingIdentity();
4686 try {
4687 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4688 && TextUtils.equals(ISDR_AID, data)) {
4689 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004690 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4691 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692 if (bestComponent == null
4693 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4694 loge("The calling package is not allowed to select ISD-R.");
4695 throw new SecurityException(
4696 "The calling package is not allowed to select ISD-R.");
4697 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004698 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004701 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4702 null /* workSource */);
4703 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 // Append the returned status code to the end of the response payload.
4706 String s = Integer.toHexString(
4707 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4708 if (response.payload != null) {
4709 s = IccUtils.bytesToHexString(response.payload) + s;
4710 }
4711 return s;
4712 } finally {
4713 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004714 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004715 }
4716
4717 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004718 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004719 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4721 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723 final long identity = Binder.clearCallingIdentity();
4724 try {
4725 if (DBG) {
4726 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4727 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4728 }
4729
4730 IccIoResult response =
4731 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4732 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4733 subId);
4734
4735 if (DBG) {
4736 log("Exchange SIM_IO [R]" + response);
4737 }
4738
4739 byte[] result = null;
4740 int length = 2;
4741 if (response.payload != null) {
4742 length = 2 + response.payload.length;
4743 result = new byte[length];
4744 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4745 } else {
4746 result = new byte[length];
4747 }
4748
4749 result[length - 1] = (byte) response.sw2;
4750 result[length - 2] = (byte) response.sw1;
4751 return result;
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004754 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004755 }
4756
Nathan Haroldb3014052017-01-25 15:57:32 -08004757 /**
4758 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4759 * on a particular subscription
4760 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004761 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4762 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004764 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004765 return null;
4766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767
4768 final long identity = Binder.clearCallingIdentity();
4769 try {
4770 if (appType != TelephonyManager.APPTYPE_USIM
4771 && appType != TelephonyManager.APPTYPE_SIM) {
4772 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4773 return null;
4774 }
4775 Object response = sendRequest(
4776 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4777 if (response instanceof String[]) {
4778 return (String[]) response;
4779 }
yincheng zhao2737e882019-09-06 17:06:54 -07004780 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004782 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 } finally {
4784 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004785 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004786 }
4787
yincheng zhao2737e882019-09-06 17:06:54 -07004788 /**
4789 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4790 * subscription.
4791 *
4792 * @param subId the id of the subscription.
4793 * @param appType the uicc app type, must be USIM or SIM.
4794 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4795 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004796 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004797 * @return number of fplmns that is successfully written to the SIM.
4798 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004799 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4800 String callingFeatureId) {
4801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4802 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004803 if (DBG) logv("no permissions for setForbiddenplmns");
4804 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4805 }
4806 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4807 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4808 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4809 }
4810 if (fplmns == null) {
4811 throw new IllegalArgumentException("Fplmn List provided is null");
4812 }
4813 for (String fplmn : fplmns) {
4814 if (!CellIdentity.isValidPlmn(fplmn)) {
4815 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4816 }
4817 }
4818 final long identity = Binder.clearCallingIdentity();
4819 try {
4820 Object response = sendRequest(
4821 CMD_SET_FORBIDDEN_PLMNS,
4822 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4823 subId);
4824 return (int) response;
4825 } finally {
4826 Binder.restoreCallingIdentity(identity);
4827 }
4828 }
4829
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004830 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004831 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4833 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004835 final long identity = Binder.clearCallingIdentity();
4836 try {
4837 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4838 if (response.payload == null) {
4839 return "";
4840 }
Evan Charltonc66da362014-05-16 14:06:40 -07004841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 // Append the returned status code to the end of the response payload.
4843 String s = Integer.toHexString(
4844 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4845 s = IccUtils.bytesToHexString(response.payload) + s;
4846 return s;
4847 } finally {
4848 Binder.restoreCallingIdentity(identity);
4849 }
Evan Charltonc66da362014-05-16 14:06:40 -07004850 }
4851
Jake Hambye994d462014-02-03 13:10:13 -08004852 /**
4853 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4854 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4855 *
4856 * @param itemID the ID of the item to read
4857 * @return the NV item as a String, or null on error.
4858 */
4859 @Override
4860 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004861 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4863 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864
4865 final long identity = Binder.clearCallingIdentity();
4866 try {
4867 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004868 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4870 return value;
4871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
Jake Hambye994d462014-02-03 13:10:13 -08004874 }
4875
4876 /**
4877 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4878 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4879 *
4880 * @param itemID the ID of the item to read
4881 * @param itemValue the value to write, as a String
4882 * @return true on success; false on any failure
4883 */
4884 @Override
4885 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4888 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4893 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004894 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4896 return success;
4897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
Jake Hambye994d462014-02-03 13:10:13 -08004900 }
4901
4902 /**
4903 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4904 * Used for device configuration by some CDMA operators.
4905 *
4906 * @param preferredRoamingList byte array containing the new PRL
4907 * @return true on success; false on any failure
4908 */
4909 @Override
4910 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4912 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004913
4914 final long identity = Binder.clearCallingIdentity();
4915 try {
4916 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4917 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4918 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4919 return success;
4920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
Jake Hambye994d462014-02-03 13:10:13 -08004923 }
4924
4925 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004926 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004927 * Used for device configuration by some CDMA operators.
4928 *
chen xu6dac5ab2018-10-26 17:39:23 -07004929 * @param slotIndex - device slot.
4930 *
Jake Hambye994d462014-02-03 13:10:13 -08004931 * @return true on success; false on any failure
4932 */
4933 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004934 public boolean resetModemConfig(int slotIndex) {
4935 Phone phone = PhoneFactory.getPhone(slotIndex);
4936 if (phone != null) {
4937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4938 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939
chen xu6dac5ab2018-10-26 17:39:23 -07004940 final long identity = Binder.clearCallingIdentity();
4941 try {
4942 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4943 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4944 return success;
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 }
chen xu6dac5ab2018-10-26 17:39:23 -07004949 return false;
4950 }
4951
4952 /**
4953 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4954 *
4955 * @param slotIndex - device slot.
4956 *
4957 * @return true on success; false on any failure
4958 */
4959 @Override
4960 public boolean rebootModem(int slotIndex) {
4961 Phone phone = PhoneFactory.getPhone(slotIndex);
4962 if (phone != null) {
4963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4964 mApp, phone.getSubId(), "rebootModem");
4965
4966 final long identity = Binder.clearCallingIdentity();
4967 try {
4968 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4969 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4970 return success;
4971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
4974 }
4975 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004976 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004977
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004978 public String[] getPcscfAddress(String apnType, String callingPackage,
4979 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004980 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4982 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004983 return new String[0];
4984 }
4985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 final long identity = Binder.clearCallingIdentity();
4987 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004988 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
Wink Saville36469e72014-06-11 15:17:00 -07004992 }
4993
Brad Ebinger51f743a2017-01-23 13:50:20 -08004994 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004995 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4996 * {@link #disableIms(int)}.
4997 * @param slotIndex device slot.
4998 */
4999 public void resetIms(int slotIndex) {
5000 enforceModifyPermission();
5001
5002 final long identity = Binder.clearCallingIdentity();
5003 try {
5004 if (mImsResolver == null) {
5005 // may happen if the does not support IMS.
5006 return;
5007 }
5008 mImsResolver.disableIms(slotIndex);
5009 mImsResolver.enableIms(slotIndex);
5010 } finally {
5011 Binder.restoreCallingIdentity(identity);
5012 }
5013 }
5014
5015 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005016 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5017 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005018 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005019 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021
5022 final long identity = Binder.clearCallingIdentity();
5023 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005024 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005025 // may happen if the device does not support IMS.
5026 return;
5027 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005028 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029 } finally {
5030 Binder.restoreCallingIdentity(identity);
5031 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005032 }
5033
5034 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005035 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5036 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005037 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005038 public void disableIms(int slotId) {
5039 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040
5041 final long identity = Binder.clearCallingIdentity();
5042 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005043 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005044 // may happen if the device does not support IMS.
5045 return;
5046 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005047 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 } finally {
5049 Binder.restoreCallingIdentity(identity);
5050 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005051 }
5052
5053 /**
5054 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
5055 * feature or {@link null} if the service is not available. If the feature is available, the
5056 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
5057 */
5058 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08005059 IImsServiceFeatureCallback callback) {
5060 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061
5062 final long identity = Binder.clearCallingIdentity();
5063 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005064 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005065 // may happen if the device does not support IMS.
5066 return null;
5067 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005068 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005072 }
5073
5074 /**
5075 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5076 * feature during emergency calling or {@link null} if the service is not available. If the
5077 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5078 * listener for feature updates.
5079 */
5080 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5081 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082
5083 final long identity = Binder.clearCallingIdentity();
5084 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005085 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005086 // may happen if the device does not support IMS.
5087 return null;
5088 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005089 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005093 }
5094
Brad Ebinger5f64b052017-12-14 14:26:15 -08005095 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005096 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5097 */
5098 public void unregisterImsFeatureCallback(int slotId, int featureType,
5099 IImsServiceFeatureCallback callback) {
5100 enforceModifyPermission();
5101
5102 final long identity = Binder.clearCallingIdentity();
5103 try {
5104 if (mImsResolver == null) return;
5105 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5106 } finally {
5107 Binder.restoreCallingIdentity(identity);
5108 }
5109 }
5110
5111 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005112 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005113 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005114 */
5115 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5116 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117
5118 final long identity = Binder.clearCallingIdentity();
5119 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005120 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005121 // may happen if the device does not support IMS.
5122 return null;
5123 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005124 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005128 }
5129
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005130 /**
5131 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005132 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005133 */
5134 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136
5137 final long identity = Binder.clearCallingIdentity();
5138 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005139 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005140 // may happen if the device does not support IMS.
5141 return null;
5142 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005143 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005147 }
5148
Brad Ebinger884c07b2018-02-15 16:17:40 -08005149 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005150 * Sets the ImsService Package Name that Telephony will bind to.
5151 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005152 * @param slotIndex the slot ID that the ImsService should bind for.
5153 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005154 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005155 * @param featureTypes An integer array of feature types associated with a packageName.
5156 * @param packageName The name of the package that the current configuration will be replaced
5157 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005158 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005159 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005160 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5161 int[] featureTypes, String packageName) {
5162 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5163 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5165 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005166 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 final long identity = Binder.clearCallingIdentity();
5169 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005170 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005171 // may happen if the device does not support IMS.
5172 return false;
5173 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005174 Map<Integer, String> featureConfig = new HashMap<>();
5175 for (int featureType : featureTypes) {
5176 featureConfig.put(featureType, packageName);
5177 }
5178 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5179 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 } finally {
5181 Binder.restoreCallingIdentity(identity);
5182 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005183 }
5184
5185 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005186 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005187 *
5188 * @param slotId The slot that the ImsService is associated with.
5189 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5190 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005191 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005192 * @return the package name of the ImsService configuration.
5193 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005194 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5195 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005196 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005197 TelephonyPermissions
5198 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5199 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5200 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202 final long identity = Binder.clearCallingIdentity();
5203 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005204 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005205 // may happen if the device does not support IMS.
5206 return "";
5207 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005208 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005209 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5210 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 } finally {
5212 Binder.restoreCallingIdentity(identity);
5213 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005214 }
5215
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005216 /**
5217 * Get the MmTelFeature state associated with the requested subscription id.
5218 * @param subId The subscription that the MmTelFeature is associated with.
5219 * @param callback A callback with an integer containing the
5220 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5221 */
5222 @Override
5223 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5224 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5225 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5226 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5227 "IMS not available on device.");
5228 }
5229 final long token = Binder.clearCallingIdentity();
5230 try {
5231 int slotId = getSlotIndex(subId);
5232 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5233 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5234 + subId + "'");
5235 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5236 }
5237 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5238 try {
5239 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5240 } catch (RemoteException e) {
5241 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5242 + "Ignore");
5243 }
5244 });
5245 } finally {
5246 Binder.restoreCallingIdentity(token);
5247 }
5248 }
5249
Wink Saville36469e72014-06-11 15:17:00 -07005250 public void setImsRegistrationState(boolean registered) {
5251 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252
5253 final long identity = Binder.clearCallingIdentity();
5254 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005255 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 } finally {
5257 Binder.restoreCallingIdentity(identity);
5258 }
Wink Saville36469e72014-06-11 15:17:00 -07005259 }
5260
5261 /**
Stuart Scott54788802015-03-30 13:18:01 -07005262 * Set the network selection mode to automatic.
5263 *
5264 */
5265 @Override
5266 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5268 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
shilufc958392020-01-20 11:36:01 -08005272 if (!isActiveSubscription(subId)) {
5273 return;
5274 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5276 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
Stuart Scott54788802015-03-30 13:18:01 -07005280 }
5281
Pengquan Mengea84e042018-09-20 14:57:26 -07005282 /**
5283 * Ask the radio to connect to the input network and change selection mode to manual.
5284 *
5285 * @param subId the id of the subscription.
5286 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5287 * the operator to attach to.
5288 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5289 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5290 * normal network selection next time.
5291 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005292 */
5293 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005294 public boolean setNetworkSelectionModeManual(
5295 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5297 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005298
5299 if (!isActiveSubscription(subId)) {
5300 return false;
5301 }
5302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303 final long identity = Binder.clearCallingIdentity();
5304 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005305 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005307 if (DBG) {
5308 log("setNetworkSelectionModeManual: subId: " + subId
5309 + " operator: " + operatorInfo);
5310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5312 } finally {
5313 Binder.restoreCallingIdentity(identity);
5314 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005315 }
shilu84f6e8b2019-12-19 13:58:01 -08005316 /**
5317 * Get the manual network selection
5318 *
5319 * @param subId the id of the subscription.
5320 *
5321 * @return the previously saved user selected PLMN
5322 */
5323 @Override
5324 public String getManualNetworkSelectionPlmn(int subId) {
5325 TelephonyPermissions
5326 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5327 mApp, subId, "getManualNetworkSelectionPlmn");
5328
5329 final long identity = Binder.clearCallingIdentity();
5330 try {
5331 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005332 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005333 }
5334
5335 final Phone phone = getPhone(subId);
5336 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005337 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005338 }
5339 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5340 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5341 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5342 } finally {
5343 Binder.restoreCallingIdentity(identity);
5344 }
5345 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005346
5347 /**
5348 * Scans for available networks.
5349 */
5350 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005351 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5352 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5354 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005355 LocationAccessPolicy.LocationPermissionResult locationResult =
5356 LocationAccessPolicy.checkLocationPermission(mApp,
5357 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5358 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005359 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005360 .setCallingPid(Binder.getCallingPid())
5361 .setCallingUid(Binder.getCallingUid())
5362 .setMethod("getCellNetworkScanResults")
5363 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005364 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5365 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005366 .build());
5367 switch (locationResult) {
5368 case DENIED_HARD:
5369 throw new SecurityException("Not allowed to access scan results -- location");
5370 case DENIED_SOFT:
5371 return null;
5372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373
Pengquan Menga1bb6272018-09-06 09:59:22 -07005374 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 try {
5376 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005377 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 } finally {
5380 Binder.restoreCallingIdentity(identity);
5381 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005382 }
5383
5384 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005385 * Get the call forwarding info, given the call forwarding reason.
5386 */
5387 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005388 public void getCallForwarding(int subId, int callForwardingReason,
5389 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005390 enforceReadPrivilegedPermission("getCallForwarding");
5391 long identity = Binder.clearCallingIdentity();
5392 try {
5393 if (DBG) {
5394 log("getCallForwarding: subId " + subId
5395 + " callForwardingReason" + callForwardingReason);
5396 }
Hall Liu27d24262020-09-18 19:04:59 -07005397
5398 Phone phone = getPhone(subId);
5399 if (phone == null) {
5400 try {
5401 callback.onError(CallForwardingInfo.ERROR_UNKNOWN);
5402 } catch (RemoteException e) {
5403 // ignore
5404 }
5405 return;
5406 }
5407
5408 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5409 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5410 @Override
5411 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5412 try {
5413 callback.onCallForwardingInfoAvailable(info);
5414 } catch (RemoteException e) {
5415 // ignore
5416 }
5417 }
5418
5419 @Override
5420 public void onError(int error) {
5421 try {
5422 callback.onError(error);
5423 } catch (RemoteException e) {
5424 // ignore
5425 }
5426 }
5427 });
5428 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
5431 }
5432 }
5433
5434 /**
5435 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5436 * reason, the number to forward, and the timeout before the forwarding is attempted.
5437 */
5438 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005439 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5440 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005441 enforceModifyPermission();
5442 long identity = Binder.clearCallingIdentity();
5443 try {
5444 if (DBG) {
5445 log("setCallForwarding: subId " + subId
5446 + " callForwardingInfo" + callForwardingInfo);
5447 }
Hall Liu27d24262020-09-18 19:04:59 -07005448
5449 Phone phone = getPhone(subId);
5450 if (phone == null) {
5451 try {
5452 callback.accept(CallForwardingInfo.ERROR_UNKNOWN);
5453 } catch (RemoteException e) {
5454 // ignore
5455 }
5456 return;
5457 }
5458
5459 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5460 FunctionalUtils.ignoreRemoteException(callback::accept));
5461
5462 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005463 } finally {
5464 Binder.restoreCallingIdentity(identity);
5465 }
5466 }
5467
5468 /**
Hall Liu27d24262020-09-18 19:04:59 -07005469 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005470 */
5471 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005472 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005473 enforceReadPrivilegedPermission("getCallForwarding");
5474 long identity = Binder.clearCallingIdentity();
5475 try {
Hall Liu27d24262020-09-18 19:04:59 -07005476
5477 Phone phone = getPhone(subId);
5478 if (phone == null) {
5479 try {
5480 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5481 } catch (RemoteException e) {
5482 // ignore
5483 }
5484 return;
5485 }
5486
5487 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5488
Shuo Qian4a594052020-01-23 11:59:30 -08005489 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005490 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
5494 }
5495
5496 /**
Hall Liu27d24262020-09-18 19:04:59 -07005497 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005498 */
5499 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005500 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005501 enforceModifyPermission();
5502 long identity = Binder.clearCallingIdentity();
5503 try {
Hall Liu27d24262020-09-18 19:04:59 -07005504 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5505
5506 Phone phone = getPhone(subId);
5507 if (phone == null) {
5508 try {
5509 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5510 } catch (RemoteException e) {
5511 // ignore
5512 }
5513 return;
5514 }
5515
5516 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5517 FunctionalUtils.ignoreRemoteException(callback::accept));
5518
5519 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005520 } finally {
5521 Binder.restoreCallingIdentity(identity);
5522 }
5523 }
5524
5525 /**
yinxub1bed742017-04-17 11:45:04 -07005526 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005527 *
yinxub1bed742017-04-17 11:45:04 -07005528 * @param subId id of the subscription
5529 * @param request contains the radio access networks with bands/channels to scan
5530 * @param messenger callback messenger for scan results or errors
5531 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005532 * @return the id of the requested scan which can be used to stop the scan.
5533 */
5534 @Override
5535 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005536 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5538 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005539 LocationAccessPolicy.LocationPermissionResult locationResult =
5540 LocationAccessPolicy.checkLocationPermission(mApp,
5541 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5542 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005543 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005544 .setCallingPid(Binder.getCallingPid())
5545 .setCallingUid(Binder.getCallingUid())
5546 .setMethod("requestNetworkScan")
5547 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005548 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5549 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005550 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005551 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005552 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005553 if (e != null) {
5554 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5555 throw e;
5556 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005557 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005558 return TelephonyScanManager.INVALID_SCAN_ID;
5559 }
5560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 }
Hall Liu912dfd32019-04-25 14:02:26 -07005562 int callingUid = Binder.getCallingUid();
5563 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005564 final long identity = Binder.clearCallingIdentity();
5565 try {
5566 return mNetworkScanRequestTracker.startNetworkScan(
5567 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005568 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
yinxu504e1392017-04-12 16:03:22 -07005572 }
5573
Hall Liub2ac8ef2019-02-28 15:56:23 -08005574 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005575 NetworkScanRequest request, int subId) {
5576 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5577 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5578 boolean hasNetworkScanPermission =
5579 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5580 == PERMISSION_GRANTED;
5581
5582 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5583 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5584 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005585 }
5586
5587 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5588 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005589 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5590 return new SecurityException("Specific channels must not be"
5591 + " scanned without location access.");
5592 }
5593 }
5594 }
5595
Hall Liub2ac8ef2019-02-28 15:56:23 -08005596 return null;
5597 }
5598
yinxu504e1392017-04-12 16:03:22 -07005599 /**
5600 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005601 *
5602 * @param subId id of the subscription
5603 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005604 */
5605 @Override
5606 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5608 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609
Hall Liu912dfd32019-04-25 14:02:26 -07005610 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 final long identity = Binder.clearCallingIdentity();
5612 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005613 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
yinxu504e1392017-04-12 16:03:22 -07005617 }
5618
5619 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005620 * Get the calculated preferred network type.
5621 * Used for debugging incorrect network type.
5622 *
5623 * @return the preferred network type, defined in RILConstants.java.
5624 */
5625 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005626 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005627 final Phone defaultPhone = getDefaultPhone();
5628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005629 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005630 return RILConstants.PREFERRED_NETWORK_MODE;
5631 }
5632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005636 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 } finally {
5638 Binder.restoreCallingIdentity(identity);
5639 }
Junda Liu84d15a22014-07-02 11:21:04 -07005640 }
5641
5642 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005643 * Get the preferred network type.
5644 * Used for device configuration by some CDMA operators.
5645 *
5646 * @return the preferred network type, defined in RILConstants.java.
5647 */
5648 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005649 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005650 TelephonyPermissions
5651 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5652 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653
5654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 if (DBG) log("getPreferredNetworkType");
5657 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5658 int networkType = (result != null ? result[0] : -1);
5659 if (DBG) log("getPreferredNetworkType: " + networkType);
5660 return networkType;
5661 } finally {
5662 Binder.restoreCallingIdentity(identity);
5663 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005664 }
5665
5666 /**
5667 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005668 *
5669 * @param networkType the preferred network type, defined in RILConstants.java.
5670 * @return true on success; false on any failure.
5671 */
5672 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005673 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5675 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676
5677 final long identity = Binder.clearCallingIdentity();
5678 try {
calvinpan8ed33732020-03-12 14:17:55 +08005679 Boolean success = (Boolean) sendRequest(
5680 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005681
5682 if (success) {
5683 Settings.Global.putInt(mApp.getContentResolver(),
5684 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5685 }
calvinpan8ed33732020-03-12 14:17:55 +08005686 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5687 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 } finally {
5689 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005690 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005691 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005692
5693 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005694 * Get the allowed network types that store in the telephony provider.
5695 *
5696 * @param subId the id of the subscription.
5697 * @return allowedNetworkTypes the allowed network types.
5698 */
5699 @Override
5700 public long getAllowedNetworkTypes(int subId) {
5701 TelephonyPermissions
5702 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5703 mApp, subId, "getAllowedNetworkTypes");
5704
5705 final long identity = Binder.clearCallingIdentity();
5706 try {
5707 return SubscriptionManager.getLongSubscriptionProperty(
5708 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
5712 }
5713
5714 /**
5715 * Set the allowed network types.
5716 *
5717 * @param subId the id of the subscription.
5718 * @param allowedNetworkTypes the allowed network types.
5719 * @return true on success; false on any failure.
5720 */
5721 @Override
5722 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5724 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005725
calvinpan8ed33732020-03-12 14:17:55 +08005726 SubscriptionManager.setSubscriptionProperty(subId,
5727 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5728 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005729
calvinpan8ed33732020-03-12 14:17:55 +08005730 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5731 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5732 RILConstants.PREFERRED_NETWORK_MODE);
5733 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005734 }
5735
5736 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005737 * Get the allowed network types for certain reason.
5738 *
5739 * @param subId the id of the subscription.
5740 * @param reason the reason the allowed network type change is taking place
5741 * @return the allowed network types.
5742 */
5743 @Override
5744 public long getAllowedNetworkTypesForReason(int subId,
5745 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5746 TelephonyPermissions
5747 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5748 mApp, subId, "getAllowedNetworkTypesForReason");
5749 final long identity = Binder.clearCallingIdentity();
5750 try {
5751 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
5755 }
5756
5757 /**
5758 * Get the effective allowed network types on the device.
5759 * This API will return an intersection of allowed network types for all reasons,
5760 * including the configuration done through setAllowedNetworkTypes
5761 *
5762 * @param subId the id of the subscription.
5763 * @return the allowed network types
5764 */
5765 @Override
5766 public long getEffectiveAllowedNetworkTypes(int subId) {
5767 TelephonyPermissions
5768 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5769 mApp, subId, "getEffectiveAllowedNetworkTypes");
5770 final long identity = Binder.clearCallingIdentity();
5771 try {
5772 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5773 } finally {
5774 Binder.restoreCallingIdentity(identity);
5775 }
5776 }
5777
5778 /**
5779 * Set the allowed network types of the device and
5780 * provide the reason triggering the allowed network change.
5781 *
5782 * @param subId the id of the subscription.
5783 * @param reason the reason the allowed network type change is taking place
5784 * @param allowedNetworkTypes the allowed network types.
5785 * @return true on success; false on any failure.
5786 */
5787 @Override
5788 public boolean setAllowedNetworkTypesForReason(int subId,
5789 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5791 mApp, subId, "setAllowedNetworkTypesForReason");
5792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5795 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5796 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5797 RILConstants.PREFERRED_NETWORK_MODE);
5798 return setPreferredNetworkType(subId, preferredNetworkMode);
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
5801 }
5802 }
5803
5804 /**
Miaoa84611c2019-03-15 09:21:10 +08005805 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005806 *
Miaoa84611c2019-03-15 09:21:10 +08005807 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005808 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005809 * @hide
5810 */
5811 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005812 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005815 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 try {
Miaoa84611c2019-03-15 09:21:10 +08005817 if (phone != null) {
5818 return phone.hasMatchedTetherApnSetting();
5819 } else {
5820 return false;
5821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 } finally {
5823 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005824 }
Junda Liu475951f2014-11-07 16:45:03 -08005825 }
5826
5827 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005828 * Enable or disable always reporting signal strength changes from radio.
5829 *
5830 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5831 */
5832 @Override
5833 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5834 enforceModifyPermission();
5835 enforceSystemCaller();
5836
5837 final long identity = Binder.clearCallingIdentity();
5838 final Phone phone = getPhone(subId);
5839 try {
5840 if (phone != null) {
5841 if (DBG) {
5842 log("setAlwaysReportSignalStrength: subId=" + subId
5843 + " isEnable=" + isEnable);
5844 }
5845 phone.setAlwaysReportSignalStrength(isEnable);
5846 } else {
5847 loge("setAlwaysReportSignalStrength: no phone found for subId="
5848 + subId);
5849 }
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
5852 }
5853 }
5854
5855 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005856 * Get the user enabled state of Mobile Data.
5857 *
5858 * TODO: remove and use isUserDataEnabled.
5859 * This can't be removed now because some vendor codes
5860 * calls through ITelephony directly while they should
5861 * use TelephonyManager.
5862 *
5863 * @return true on enabled
5864 */
5865 @Override
5866 public boolean getDataEnabled(int subId) {
5867 return isUserDataEnabled(subId);
5868 }
5869
5870 /**
5871 * Get whether mobile data is enabled per user setting.
5872 *
5873 * There are other factors deciding whether mobile data is actually enabled, but they are
5874 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005875 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005876 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005877 *
5878 * @return {@code true} if data is enabled else {@code false}
5879 */
5880 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005881 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005882 try {
5883 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5884 null);
5885 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5887 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889
5890 final long identity = Binder.clearCallingIdentity();
5891 try {
5892 int phoneId = mSubscriptionController.getPhoneId(subId);
5893 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5894 Phone phone = PhoneFactory.getPhone(phoneId);
5895 if (phone != null) {
5896 boolean retVal = phone.isUserDataEnabled();
5897 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5898 return retVal;
5899 } else {
5900 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5901 return false;
5902 }
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005905 }
5906 }
5907
5908 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005909 * Checks if the device is capable of mobile data by considering whether whether the
5910 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5911 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005912 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005913 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005914 */
5915 @Override
5916 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005917 try {
5918 try {
5919 mApp.enforceCallingOrSelfPermission(
5920 android.Manifest.permission.ACCESS_NETWORK_STATE,
5921 null);
5922 } catch (Exception e) {
5923 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
5924 "isDataEnabled");
5925 }
5926 } catch (Exception e) {
5927 enforceReadPrivilegedPermission("isDataEnabled");
5928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
5932 int phoneId = mSubscriptionController.getPhoneId(subId);
5933 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5934 Phone phone = PhoneFactory.getPhone(phoneId);
5935 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005936 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5938 return retVal;
5939 } else {
5940 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5941 return false;
5942 }
5943 } finally {
5944 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005945 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005946 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005947
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005948 /**
5949 * Check if data is enabled for a specific reason
5950 * @param subId Subscription index
5951 * @param reason the reason the data enable change is taking place
5952 * @return {@code true} if the overall data is enabled; {@code false} if not.
5953 */
5954 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005955 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005956 @TelephonyManager.DataEnabledReason int reason) {
5957 try {
5958 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5959 null);
5960 } catch (Exception e) {
5961 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005962 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005963 }
5964
5965
5966 final long identity = Binder.clearCallingIdentity();
5967 try {
5968 int phoneId = mSubscriptionController.getPhoneId(subId);
5969 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005970 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005971 + " reason=" + reason);
5972 }
5973 Phone phone = PhoneFactory.getPhone(phoneId);
5974 if (phone != null) {
5975 boolean retVal;
5976 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
5977 retVal = phone.isUserDataEnabled();
5978 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005979 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005980 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005981 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005982 return retVal;
5983 } else {
5984 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005985 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005986 + subId + " retVal=false");
5987 }
5988 return false;
5989 }
5990 } finally {
5991 Binder.restoreCallingIdentity(identity);
5992 }
5993 }
5994
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005995 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005996 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07005997 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5998 // Skip the check if it's one of these special uids
5999 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6000 }
6001
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006002 //load access rules from carrier configs, and check those as well: b/139133814
6003 SubscriptionController subController = SubscriptionController.getInstance();
6004 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6005 || subController == null) return privilegeFromSim;
6006
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006007 PackageManager pkgMgr = phone.getContext().getPackageManager();
6008 String[] packages = pkgMgr.getPackagesForUid(uid);
6009
6010 final long identity = Binder.clearCallingIdentity();
6011 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006012 int subId = phone.getSubId();
6013 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6014 // A test override is in place for the privileges for this subId, so don't try to
6015 // read the subscription privileges.
6016 return privilegeFromSim;
6017 }
6018 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006019 SubscriptionManager subManager = (SubscriptionManager)
6020 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6021 for (String pkg : packages) {
6022 if (subManager.canManageSubscription(subInfo, pkg)) {
6023 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6024 }
6025 }
6026 return privilegeFromSim;
6027 } finally {
6028 Binder.restoreCallingIdentity(identity);
6029 }
6030 }
6031
6032 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6033 String pkgName) {
6034 //load access rules from carrier configs, and check those as well: b/139133814
6035 SubscriptionController subController = SubscriptionController.getInstance();
6036 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6037 || subController == null) return privilegeFromSim;
6038
6039 final long identity = Binder.clearCallingIdentity();
6040 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006041 int subId = phone.getSubId();
6042 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6043 // A test override is in place for the privileges for this subId, so don't try to
6044 // read the subscription privileges.
6045 return privilegeFromSim;
6046 }
6047 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006048 SubscriptionManager subManager = (SubscriptionManager)
6049 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6050 return subManager.canManageSubscription(subInfo, pkgName)
6051 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6052 } finally {
6053 Binder.restoreCallingIdentity(identity);
6054 }
6055 }
6056
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006057 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006058 public int getCarrierPrivilegeStatus(int subId) {
6059 final Phone phone = getPhone(subId);
6060 if (phone == null) {
6061 loge("getCarrierPrivilegeStatus: Invalid subId");
6062 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6063 }
6064 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006065 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006066 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006067 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6068 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006069
6070 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6071 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006072 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006073 }
Junda Liu29340342014-07-10 15:23:27 -07006074
6075 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006076 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006077 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006078 final Phone phone = getPhone(subId);
6079 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006080 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006081 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6082 }
6083 UiccProfile profile =
6084 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6085 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006086 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006087 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6088 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006089 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006090 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006091 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006092 }
6093
6094 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006095 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6096 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006097 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006098 }
6099
6100 int phoneId = SubscriptionManager.getPhoneId(subId);
6101 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006102 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006103 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006104 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6105 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006106 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6107 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6108 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006109 }
6110
6111 @Override
6112 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006113 if (TextUtils.isEmpty(pkgName))
6114 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006115 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6116 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6117 UiccCard card = UiccController.getInstance().getUiccCard(i);
6118 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006119 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006120 continue;
6121 }
6122
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006123 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6124 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6125 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006126 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6127 break;
6128 }
6129 }
6130
6131 return result;
Junda Liu29340342014-07-10 15:23:27 -07006132 }
Derek Tan89e89d42014-07-08 17:00:10 -07006133
6134 @Override
Junda Liue64de782015-04-16 17:19:16 -07006135 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6136 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6137 loge("phoneId " + phoneId + " is not valid.");
6138 return null;
6139 }
6140 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006141 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006142 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006143 return null ;
6144 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006145 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006146 }
6147
Amith Yamasani6e118872016-02-19 12:53:51 -08006148 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006149 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006150 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006151 List<String> privilegedPackages = new ArrayList<>();
6152 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006153 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6154 // has UICC in that slot.
6155 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006156 if (card.hasCarrierPrivilegeRules()) {
6157 if (packages == null) {
6158 // Only check packages in user 0 for now
6159 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006160 PackageManager.MATCH_DISABLED_COMPONENTS
6161 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006162 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006163 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006164 }
6165 for (int p = packages.size() - 1; p >= 0; p--) {
6166 PackageInfo pkgInfo = packages.get(p);
6167 if (pkgInfo != null && pkgInfo.packageName != null
6168 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006169 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006170 privilegedPackages.add(pkgInfo.packageName);
6171 }
6172 }
6173 }
6174 }
6175 return privilegedPackages;
6176 }
6177
chen xuf7e9fe82019-05-09 19:31:02 -07006178 @Override
6179 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006180 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6181
6182 final long identity = Binder.clearCallingIdentity();
6183
chen xuf7e9fe82019-05-09 19:31:02 -07006184 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006185 try {
6186 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6187 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6188 }
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006191 }
6192 return privilegedPackages;
6193 }
6194
Wink Savilleb564aae2014-10-23 10:18:09 -07006195 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006196 final Phone phone = getPhone(subId);
6197 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006198 if (card == null) {
6199 loge("getIccId: No UICC");
6200 return null;
6201 }
6202 String iccId = card.getIccId();
6203 if (TextUtils.isEmpty(iccId)) {
6204 loge("getIccId: ICC ID is null or empty.");
6205 return null;
6206 }
6207 return iccId;
6208 }
6209
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006210 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006211 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6212 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006213 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006214 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 final long identity = Binder.clearCallingIdentity();
6217 try {
6218 final String iccId = getIccId(subId);
6219 final Phone phone = getPhone(subId);
6220 if (phone == null) {
6221 return false;
6222 }
6223 final String subscriberId = phone.getSubscriberId();
6224
6225 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006226 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 + subscriberId + " to " + number);
6228 }
6229
6230 if (TextUtils.isEmpty(iccId)) {
6231 return false;
6232 }
6233
6234 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6235
6236 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6237 if (alphaTag == null) {
6238 editor.remove(alphaTagPrefKey);
6239 } else {
6240 editor.putString(alphaTagPrefKey, alphaTag);
6241 }
6242
6243 // Record both the line number and IMSI for this ICCID, since we need to
6244 // track all merged IMSIs based on line number
6245 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6246 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6247 if (number == null) {
6248 editor.remove(numberPrefKey);
6249 editor.remove(subscriberPrefKey);
6250 } else {
6251 editor.putString(numberPrefKey, number);
6252 editor.putString(subscriberPrefKey, subscriberId);
6253 }
6254
6255 editor.commit();
6256 return true;
6257 } finally {
6258 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006259 }
Derek Tan7226c842014-07-02 17:42:23 -07006260 }
6261
6262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006263 public String getLine1NumberForDisplay(int subId, String callingPackage,
6264 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006265 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006267 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006268 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006269 return null;
6270 }
Derek Tan97ebb422014-09-05 16:55:38 -07006271
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 final long identity = Binder.clearCallingIdentity();
6273 try {
6274 String iccId = getIccId(subId);
6275 if (iccId != null) {
6276 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6277 if (DBG_MERGE) {
6278 log("getLine1NumberForDisplay returning "
6279 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6280 }
6281 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6284 return null;
6285 } finally {
6286 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006287 }
Derek Tan7226c842014-07-02 17:42:23 -07006288 }
6289
6290 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006291 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6292 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006294 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006295 return null;
6296 }
Derek Tan97ebb422014-09-05 16:55:38 -07006297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 final long identity = Binder.clearCallingIdentity();
6299 try {
6300 String iccId = getIccId(subId);
6301 if (iccId != null) {
6302 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6303 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6304 }
6305 return null;
6306 } finally {
6307 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006308 }
Derek Tan7226c842014-07-02 17:42:23 -07006309 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006310
6311 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006312 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6313 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006314 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6315 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006317 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006318 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006319 return null;
6320 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006321
Jordan Liub49b04b2019-05-06 14:45:15 -07006322 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6323 // the process, where TelephonyManager was instantiated.
6324 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006325 final long identity = Binder.clearCallingIdentity();
6326 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006327 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 final TelephonyManager tele = TelephonyManager.from(context);
6329 final SubscriptionManager sub = SubscriptionManager.from(context);
6330
6331 // Figure out what subscribers are currently active
6332 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333
Jordan Liub49b04b2019-05-06 14:45:15 -07006334 // Only consider subs which match the current subId
6335 // This logic can be simplified. See b/131189269 for progress.
6336 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006337 activeSubscriberIds.add(tele.getSubscriberId(subId));
6338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339
6340 // First pass, find a number override for an active subscriber
6341 String mergeNumber = null;
6342 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6343 for (String key : prefs.keySet()) {
6344 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6345 final String subscriberId = (String) prefs.get(key);
6346 if (activeSubscriberIds.contains(subscriberId)) {
6347 final String iccId = key.substring(
6348 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6349 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6350 mergeNumber = (String) prefs.get(numberKey);
6351 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006352 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 + " for active subscriber " + subscriberId);
6354 }
6355 if (!TextUtils.isEmpty(mergeNumber)) {
6356 break;
6357 }
6358 }
6359 }
6360 }
6361
6362 // Shortcut when no active merged subscribers
6363 if (TextUtils.isEmpty(mergeNumber)) {
6364 return null;
6365 }
6366
6367 // Second pass, find all subscribers under that line override
6368 final ArraySet<String> result = new ArraySet<>();
6369 for (String key : prefs.keySet()) {
6370 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6371 final String number = (String) prefs.get(key);
6372 if (mergeNumber.equals(number)) {
6373 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6374 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6375 final String subscriberId = (String) prefs.get(subscriberKey);
6376 if (!TextUtils.isEmpty(subscriberId)) {
6377 result.add(subscriberId);
6378 }
6379 }
6380 }
6381 }
6382
6383 final String[] resultArray = result.toArray(new String[result.size()]);
6384 Arrays.sort(resultArray);
6385 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006386 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6388 }
6389 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006390 } finally {
6391 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006392 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006393 }
6394
6395 @Override
zoey chen38003472019-12-13 17:16:31 +08006396 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6397 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006398
6399 final long identity = Binder.clearCallingIdentity();
6400 try {
6401 final TelephonyManager telephonyManager = mApp.getSystemService(
6402 TelephonyManager.class);
6403 String subscriberId = telephonyManager.getSubscriberId(subId);
6404 if (subscriberId == null) {
6405 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006406 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006407 + subId);
6408 }
6409 return null;
6410 }
6411
6412 final SubscriptionInfo info = SubscriptionController.getInstance()
6413 .getSubscriptionInfo(subId);
6414 final ParcelUuid groupUuid = info.getGroupUuid();
6415 // If it doesn't belong to any group, return just subscriberId of itself.
6416 if (groupUuid == null) {
6417 return new String[]{subscriberId};
6418 }
6419
6420 // Get all subscriberIds from the group.
6421 final List<String> mergedSubscriberIds = new ArrayList<>();
6422 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006423 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006424 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006425 for (SubscriptionInfo subInfo : groupInfos) {
6426 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6427 if (subscriberId != null) {
6428 mergedSubscriberIds.add(subscriberId);
6429 }
6430 }
6431
6432 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435
6436 }
6437 }
6438
6439 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006440 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006441 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006442 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443
6444 final long identity = Binder.clearCallingIdentity();
6445 try {
6446 final Phone phone = getPhone(subId);
6447 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006451 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006452
6453 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006454 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006455 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6456 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006457 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6458 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459
6460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 final Phone phone = getPhone(subId);
6463 if (phone == null) {
6464 return false;
6465 }
6466 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6467 cdmaNonRoamingList);
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006470 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006471 }
6472
6473 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006474 @Deprecated
6475 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6476 enforceModifyPermission();
6477
6478 int returnValue = 0;
6479 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006480 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006481 if(result.exception == null) {
6482 if (result.result != null) {
6483 byte[] responseData = (byte[])(result.result);
6484 if(responseData.length > oemResp.length) {
6485 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6486 responseData.length + "bytes. Buffer Size is " +
6487 oemResp.length + "bytes.");
6488 }
6489 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6490 returnValue = responseData.length;
6491 }
6492 } else {
6493 CommandException ex = (CommandException) result.exception;
6494 returnValue = ex.getCommandError().ordinal();
6495 if(returnValue > 0) returnValue *= -1;
6496 }
6497 } catch (RuntimeException e) {
6498 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6499 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6500 if(returnValue > 0) returnValue *= -1;
6501 }
6502
6503 return returnValue;
6504 }
6505
6506 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006507 public void setRadioCapability(RadioAccessFamily[] rafs) {
6508 try {
6509 ProxyController.getInstance().setRadioCapability(rafs);
6510 } catch (RuntimeException e) {
6511 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6512 }
6513 }
6514
6515 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006516 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006517 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006518 try {
6519 TelephonyPermissions
6520 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6521 mApp, phone.getSubId(), "getRadioAccessFamily");
6522 } catch (SecurityException e) {
6523 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6524 throw e;
6525 }
chen xub97461a2018-10-26 14:17:57 -07006526 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006527 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006528 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 final long identity = Binder.clearCallingIdentity();
6531 try {
chen xub97461a2018-10-26 14:17:57 -07006532 TelephonyPermissions
6533 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6534 mApp, phone.getSubId(), "getRadioAccessFamily");
6535 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 } finally {
6537 Binder.restoreCallingIdentity(identity);
6538 }
chen xub97461a2018-10-26 14:17:57 -07006539 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006540 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006541
6542 @Override
6543 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006544 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006545 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546
6547 final long identity = Binder.clearCallingIdentity();
6548 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006549 ImsManager.getInstance(defaultPhone.getContext(),
6550 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006554 }
6555
6556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006557 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006558 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6560 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006561 return false;
6562 }
Svet Ganovb320e182015-04-16 12:30:10 -07006563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 // Check the user preference and the system-level IMS setting. Even if the user has
6567 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6568 // In the long run, we may instead need to check if there exists a connection service
6569 // which can support video calling.
6570 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006571 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 return imsManager.isVtEnabledByPlatform()
6573 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6574 && imsManager.isVtEnabledByUser();
6575 } finally {
6576 Binder.restoreCallingIdentity(identity);
6577 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006578 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006579
Andrew Leea1239f22015-03-02 17:44:07 -08006580 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006581 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6582 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006584 mApp, subId, callingPackage, callingFeatureId,
6585 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 return false;
6587 }
6588
6589 final long identity = Binder.clearCallingIdentity();
6590 try {
6591 CarrierConfigManager configManager =
6592 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006593 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6595 } finally {
6596 Binder.restoreCallingIdentity(identity);
6597 }
Andrew Leea1239f22015-03-02 17:44:07 -08006598 }
6599
6600 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006601 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006603 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 return false;
6605 }
6606
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 CarrierConfigManager configManager =
6610 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006611 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6613 } finally {
6614 Binder.restoreCallingIdentity(identity);
6615 }
Andrew Leea1239f22015-03-02 17:44:07 -08006616 }
6617
Andrew Lee9431b832015-03-09 18:46:45 -07006618 @Override
6619 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006620 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006621 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006622 }
6623
6624 @Override
6625 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626 final long identity = Binder.clearCallingIdentity();
6627 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006628 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 } finally {
6630 Binder.restoreCallingIdentity(identity);
6631 }
Andrew Lee9431b832015-03-09 18:46:45 -07006632 }
6633
Hall Liuf6668912018-10-31 17:05:23 -07006634 /**
6635 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6636 * support for the feature and device firmware support.
6637 *
6638 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6639 */
6640 @Override
6641 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006642 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006643 final Phone phone = getPhone(subscriptionId);
6644 if (phone == null) {
6645 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6646 return false;
6647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006649 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6651 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006652 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 return isCarrierSupported && isDeviceSupported;
6654 } finally {
6655 Binder.restoreCallingIdentity(identity);
6656 }
Hall Liu98187582018-01-22 19:15:32 -08006657 }
6658
Hall Liuf6668912018-10-31 17:05:23 -07006659 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006660 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6661 * RTT setting, will return true if the device and carrier both support RTT.
6662 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006663 */
6664 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 final long identity = Binder.clearCallingIdentity();
6666 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006667 boolean isRttSupported = isRttSupported(subscriptionId);
6668 boolean isUserRttSettingOn = Settings.Secure.getInt(
6669 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6670 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6671 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6672 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006676 }
6677
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006678 @Deprecated
6679 @Override
6680 public String getDeviceId(String callingPackage) {
6681 return getDeviceIdWithFeature(callingPackage, null);
6682 }
6683
Sanket Padawe7310cc72015-01-14 09:53:20 -08006684 /**
6685 * Returns the unique device ID of phone, for example, the IMEI for
6686 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6687 *
6688 * <p>Requires Permission:
6689 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6690 */
6691 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006692 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006693 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006694 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006695 return null;
6696 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006697 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006698 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006699 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006700 return null;
6701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702
6703 final long identity = Binder.clearCallingIdentity();
6704 try {
6705 return phone.getDeviceId();
6706 } finally {
6707 Binder.restoreCallingIdentity(identity);
6708 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006709 }
6710
Ping Sunc67b7c22016-03-02 19:16:45 +08006711 /**
6712 * {@hide}
6713 * Returns the IMS Registration Status on a particular subid
6714 *
6715 * @param subId
6716 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006717 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006718 Phone phone = getPhone(subId);
6719 if (phone != null) {
6720 return phone.isImsRegistered();
6721 } else {
6722 return false;
6723 }
6724 }
6725
Santos Cordon7a1885b2015-02-03 11:15:19 -08006726 @Override
6727 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 final long identity = Binder.clearCallingIdentity();
6729 try {
6730 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6731 } finally {
6732 Binder.restoreCallingIdentity(identity);
6733 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006734 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006735
Tyler Gunnf70ed162019-04-03 15:28:53 -07006736 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006737 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006738 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006740 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006741 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6742 }
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
6745 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6746 } finally {
6747 Binder.restoreCallingIdentity(identity);
6748 }
6749 }
6750
6751 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006752 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006753 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6754 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006755 final long identity = Binder.clearCallingIdentity();
6756 try {
6757 Phone phone = getPhone(subscriptionId);
6758 if (phone == null) {
6759 return null;
6760 }
6761 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6762 } finally {
6763 Binder.restoreCallingIdentity(identity);
6764 }
6765 }
6766
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006767 /**
6768 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006769 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006770 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771 final long identity = Binder.clearCallingIdentity();
6772 try {
6773 Phone phone = getPhone(subId);
6774 if (phone != null) {
6775 return phone.isWifiCallingEnabled();
6776 } else {
6777 return false;
6778 }
6779 } finally {
6780 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006781 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006782 }
6783
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006784 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006785 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006786 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006787 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 final long identity = Binder.clearCallingIdentity();
6789 try {
6790 Phone phone = getPhone(subId);
6791 if (phone != null) {
6792 return phone.isVideoEnabled();
6793 } else {
6794 return false;
6795 }
6796 } finally {
6797 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006798 }
6799 }
6800
6801 /**
6802 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6803 * defined in {@link ImsRegistrationImplBase}.
6804 */
6805 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 Phone phone = getPhone(subId);
6809 if (phone != null) {
6810 return phone.getImsRegistrationTech();
6811 } else {
6812 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6813 }
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006816 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006817 }
6818
Stuart Scott8eef64f2015-04-08 15:13:54 -07006819 @Override
6820 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006821 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006822 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6823 return;
6824 }
6825
Svet Ganovcc087f82015-05-12 20:35:54 -07006826 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006827
Svet Ganovcc087f82015-05-12 20:35:54 -07006828 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006829 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6830 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006831 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006832 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006833 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006834 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006835 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6836 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006837 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006838 // There has been issues when Sms raw table somehow stores orphan
6839 // fragments. They lead to garbled message when new fragments come
6840 // in and combined with those stale ones. In case this happens again,
6841 // user can reset all network settings which will clean up this table.
6842 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006843 // Clean up IMS settings as well here.
6844 int slotId = getSlotIndex(subId);
6845 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6846 ImsManager.getInstance(mApp, slotId).factoryReset();
6847 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006848
6849 // Erase modem config if erase modem on network setting is enabled.
6850 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6851 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6852 if (configValue != null && Boolean.parseBoolean(configValue)) {
6853 sendEraseModemConfig(getDefaultPhone());
6854 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006855 } finally {
6856 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006857 }
6858 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006859
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006860 private void cleanUpSmsRawTable(Context context) {
6861 ContentResolver resolver = context.getContentResolver();
6862 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6863 resolver.delete(uri, null, null);
6864 }
6865
Narayan Kamath1c496c22015-04-16 14:40:19 +01006866 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006867 public String getSimLocaleForSubscriber(int subId) {
6868 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6869 final Phone phone = getPhone(subId);
6870 if (phone == null) {
6871 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006872 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006873 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 final long identity = Binder.clearCallingIdentity();
6875 try {
chen xu5d3637b2019-01-21 23:31:38 -08006876 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006877 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006878 if (info == null) {
6879 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6880 return null;
6881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882 // Try and fetch the locale from the carrier properties or from the SIM language
6883 // preferences (EF-PL and EF-LI)...
6884 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006886 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6887 if (localeFromDefaultSim != null) {
6888 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6889 if (DBG) log("Using locale from subId: " + subId + " locale: "
6890 + localeFromDefaultSim);
6891 return localeFromDefaultSim.toLanguageTag();
6892 } else {
6893 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 }
6895 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897 // The SIM language preferences only store a language (e.g. fr = French), not an
6898 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6899 // the SIM and carrier preferences does not include a country we add the country
6900 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006901 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006903 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 return mccLocale.toLanguageTag();
6905 }
6906
6907 if (DBG) log("No locale found - returning null");
6908 return null;
6909 } finally {
6910 Binder.restoreCallingIdentity(identity);
6911 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006912 }
6913
6914 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006915 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006916 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006917 }
6918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 /**
6920 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6921 */
6922 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006923 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006924 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006925 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006926
Chenjie Yu1ba97252018-01-11 18:16:20 -08006927 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006928 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006929
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006930 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006931 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6932 * representing the state of the modem.
6933 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006934 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6935 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006936 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006937 */
6938 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006939 public void requestModemActivityInfo(ResultReceiver result) {
6940 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006941 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942
6943 final long identity = Binder.clearCallingIdentity();
6944 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006945 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946 } finally {
6947 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006948 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006949 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006950
Siddharth Rayb8114062018-06-17 15:02:38 -07006951 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6952 // less than total activity duration.
6953 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6954 if (info == null) {
6955 return false;
6956 }
6957 int activityDurationMs =
6958 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6959 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006960 int[] txTimeMs = info.getTransmitTimeMillis();
6961 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6962 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006963 }
6964 return (info.isValid()
6965 && (info.getSleepTimeMillis() <= activityDurationMs)
6966 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006967 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006968 && (totalTxTimeMs <= activityDurationMs));
6969 }
6970
Jack Yu85bd38a2015-11-09 11:34:32 -08006971 /**
6972 * {@hide}
6973 * Returns the service state information on specified subscription.
6974 */
6975 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006976 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6977 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006979 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006980 return null;
6981 }
6982
Hall Liuf19c44f2018-11-27 14:38:17 -08006983 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6984 LocationAccessPolicy.checkLocationPermission(mApp,
6985 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6986 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006987 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006988 .setCallingPid(Binder.getCallingPid())
6989 .setCallingUid(Binder.getCallingUid())
6990 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006991 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006992 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006993 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6994 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006995 .build());
6996
6997 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6998 LocationAccessPolicy.checkLocationPermission(mApp,
6999 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7000 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007001 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007002 .setCallingPid(Binder.getCallingPid())
7003 .setCallingUid(Binder.getCallingUid())
7004 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007005 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007006 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007007 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7008 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007009 .build());
7010 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7011 boolean hasFinePermission =
7012 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7013 boolean hasCoarsePermission =
7014 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016 final long identity = Binder.clearCallingIdentity();
7017 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007018 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7019 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7020 Rlog.d(LOG_TAG,
7021 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7022 return null;
7023 }
7024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 final Phone phone = getPhone(subId);
7026 if (phone == null) {
7027 return null;
7028 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007029
Hall Liuf19c44f2018-11-27 14:38:17 -08007030 ServiceState ss = phone.getServiceState();
7031
7032 // Scrub out the location info in ServiceState depending on what level of access
7033 // the caller has.
7034 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007035 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7036 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037 } finally {
7038 Binder.restoreCallingIdentity(identity);
7039 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007040 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007041
7042 /**
7043 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7044 *
7045 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7046 * voicemail ringtone.
7047 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7048 * PhoneAccount.
7049 */
7050 @Override
7051 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 final long identity = Binder.clearCallingIdentity();
7053 try {
7054 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7055 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007056 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
7062 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007063 }
7064
7065 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007066 * Sets the per-account voicemail ringtone.
7067 *
7068 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7069 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7070 *
7071 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7072 * voicemail ringtone.
7073 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7074 * PhoneAccount.
7075 */
7076 @Override
7077 public void setVoicemailRingtoneUri(String callingPackage,
7078 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007079 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007081 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7082 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7084 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7085 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087
7088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7091 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007092 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 }
7094 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007097 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007098 }
7099
7100 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007101 * Returns whether vibration is set for voicemail notification in Phone settings.
7102 *
7103 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7104 * voicemail vibration setting.
7105 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7106 */
7107 @Override
7108 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007109 final long identity = Binder.clearCallingIdentity();
7110 try {
7111 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7112 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007113 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7117 } finally {
7118 Binder.restoreCallingIdentity(identity);
7119 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007120 }
7121
Youhan Wange64578a2016-05-02 15:32:42 -07007122 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007123 * Sets the per-account voicemail vibration.
7124 *
7125 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7126 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7127 *
7128 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7129 * voicemail vibration setting.
7130 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7131 * specific PhoneAccount.
7132 */
7133 @Override
7134 public void setVoicemailVibrationEnabled(String callingPackage,
7135 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007136 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007138 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7139 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7141 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7142 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007143 }
7144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 final long identity = Binder.clearCallingIdentity();
7146 try {
7147 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7148 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007149 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150 }
7151 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007154 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007155 }
7156
7157 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007158 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7159 *
7160 * @throws SecurityException if the caller does not have the required permission
7161 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007162 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007163 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007164 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007165 }
7166
7167 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007168 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7169 * permission.
7170 *
7171 * @throws SecurityException if the caller does not have the required permission
7172 */
7173 private void enforceSendSmsPermission() {
7174 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7175 }
7176
7177 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007178 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007179 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007180 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007181 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007182 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 final long identity = Binder.clearCallingIdentity();
7184 try {
7185 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007186 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 if (componentName == null) {
7188 throw new SecurityException(
7189 "Caller not current active visual voicemail package[null]");
7190 }
7191 String vvmPackage = componentName.getPackageName();
7192 if (!callingPackage.equals(vvmPackage)) {
7193 throw new SecurityException("Caller not current active visual voicemail package["
7194 + vvmPackage + "]");
7195 }
7196 } finally {
7197 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007198 }
7199 }
7200
7201 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007202 * Return the application ID for the app type.
7203 *
7204 * @param subId the subscription ID that this request applies to.
7205 * @param appType the uicc app type.
7206 * @return Application ID for specificied app type, or null if no uicc.
7207 */
7208 @Override
7209 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007210 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007211 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212
7213 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007214 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215 if (phone == null) {
7216 return null;
7217 }
7218 String aid = null;
7219 try {
7220 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7221 .getApplicationByType(appType).getAid();
7222 } catch (Exception e) {
7223 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7224 }
7225 return aid;
7226 } finally {
7227 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007228 }
Youhan Wange64578a2016-05-02 15:32:42 -07007229 }
7230
Youhan Wang4001d252016-05-11 10:29:41 -07007231 /**
7232 * Return the Electronic Serial Number.
7233 *
7234 * @param subId the subscription ID that this request applies to.
7235 * @return ESN or null if error.
7236 */
7237 @Override
7238 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007239 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007240 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241
7242 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007243 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244 if (phone == null) {
7245 return null;
7246 }
7247 String esn = null;
7248 try {
7249 esn = phone.getEsn();
7250 } catch (Exception e) {
7251 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7252 }
7253 return esn;
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007256 }
Youhan Wang4001d252016-05-11 10:29:41 -07007257 }
7258
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007259 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007260 * Return the Preferred Roaming List Version.
7261 *
7262 * @param subId the subscription ID that this request applies to.
7263 * @return PRLVersion or null if error.
7264 */
7265 @Override
7266 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007267 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007268 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269
7270 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007271 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 if (phone == null) {
7273 return null;
7274 }
7275 String cdmaPrlVersion = null;
7276 try {
7277 cdmaPrlVersion = phone.getCdmaPrlVersion();
7278 } catch (Exception e) {
7279 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7280 }
7281 return cdmaPrlVersion;
7282 } finally {
7283 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007284 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007285 }
7286
7287 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007288 * Get snapshot of Telephony histograms
7289 * @return List of Telephony histograms
7290 * @hide
7291 */
7292 @Override
7293 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7295 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007296
7297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 return RIL.getTelephonyRILTimingHistograms();
7300 } finally {
7301 Binder.restoreCallingIdentity(identity);
7302 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007303 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007304
7305 /**
7306 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007307 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7308 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007309 * Require system privileges. In the future we may add this to carrier APIs.
7310 *
Michele Berionne482f8202018-11-27 18:57:59 -08007311 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007312 */
7313 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007314 @TelephonyManager.SetCarrierRestrictionResult
7315 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007316 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007317 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007318
Michele Berionne482f8202018-11-27 18:57:59 -08007319 if (carrierRestrictionRules == null) {
7320 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007321 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 final long identity = Binder.clearCallingIdentity();
7324 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007325 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007326 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 } finally {
7328 Binder.restoreCallingIdentity(identity);
7329 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007330 }
7331
7332 /**
7333 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007334 * Get the allowed carrier list and the excluded carrier list, including the priority between
7335 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007336 * Require system privileges. In the future we may add this to carrier APIs.
7337 *
Michele Berionne482f8202018-11-27 18:57:59 -08007338 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007339 */
7340 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007341 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007342 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007347 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7348 if (response instanceof CarrierRestrictionRules) {
7349 return (CarrierRestrictionRules) response;
7350 }
7351 // Response is an Exception of some kind,
7352 // which is signalled to the user as a NULL retval
7353 return null;
7354 } catch (Exception e) {
7355 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7356 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 } finally {
7358 Binder.restoreCallingIdentity(identity);
7359 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007360 }
7361
fionaxu59545b42016-05-25 15:53:37 -07007362 /**
fionaxu59545b42016-05-25 15:53:37 -07007363 * Action set from carrier signalling broadcast receivers to enable/disable radio
7364 * @param subId the subscription ID that this action applies to.
7365 * @param enabled control enable or disable radio.
7366 * {@hide}
7367 */
7368 @Override
7369 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7370 enforceModifyPermission();
7371 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372
7373 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007374 if (phone == null) {
7375 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7376 return;
7377 }
7378 try {
7379 phone.carrierActionSetRadioEnabled(enabled);
7380 } catch (Exception e) {
7381 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 } finally {
7383 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007384 }
7385 }
7386
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007387 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007388 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7389 * network status based on which carrier apps could apply actions accordingly,
7390 * enable/disable default url handler for example.
7391 *
7392 * @param subId the subscription ID that this action applies to.
7393 * @param report control start/stop reporting the default network status.
7394 * {@hide}
7395 */
7396 @Override
7397 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7398 enforceModifyPermission();
7399 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400
7401 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007402 if (phone == null) {
7403 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7404 return;
7405 }
7406 try {
7407 phone.carrierActionReportDefaultNetworkStatus(report);
7408 } catch (Exception e) {
7409 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 } finally {
7411 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007412 }
7413 }
7414
7415 /**
fionaxud9622282017-07-17 17:51:30 -07007416 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7417 * @param subId the subscription ID that this action applies to.
7418 * {@hide}
7419 */
7420 @Override
7421 public void carrierActionResetAll(int subId) {
7422 enforceModifyPermission();
7423 final Phone phone = getPhone(subId);
7424 if (phone == null) {
7425 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7426 return;
7427 }
7428 try {
7429 phone.carrierActionResetAll();
7430 } catch (Exception e) {
7431 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7432 }
7433 }
7434
7435 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007436 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7437 * bug report is being generated.
7438 */
7439 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007440 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007441 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7442 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007443 writer.println("Permission Denial: can't dump Phone from pid="
7444 + Binder.getCallingPid()
7445 + ", uid=" + Binder.getCallingUid()
7446 + "without permission "
7447 + android.Manifest.permission.DUMP);
7448 return;
7449 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007450 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007451 }
Jack Yueb89b242016-06-22 13:27:47 -07007452
Brad Ebingerdac2f002018-04-03 15:17:52 -07007453 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007454 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7455 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7456 @NonNull String[] args) {
7457 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7458 this, in.getFileDescriptor(), out.getFileDescriptor(),
7459 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007460 }
7461
Jack Yueb89b242016-06-22 13:27:47 -07007462 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007463 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007464 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007465 * @param reason the reason the data enable change is taking place
7466 * @param enabled True if enabling the data, otherwise disabling.
7467 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007468 */
7469 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007470 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007471 boolean enabled) {
7472 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7473 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7474 try {
7475 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007476 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007477 } catch (SecurityException se) {
7478 enforceModifyPermission();
7479 }
7480 } else {
7481 enforceModifyPermission();
7482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483
7484 final long identity = Binder.clearCallingIdentity();
7485 try {
7486 Phone phone = getPhone(subId);
7487 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007488 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7489 phone.carrierActionSetMeteredApnsEnabled(enabled);
7490 } else {
7491 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 }
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007496 }
7497 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007498
7499 /**
7500 * Get Client request stats
7501 * @return List of Client Request Stats
7502 * @hide
7503 */
7504 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007505 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7506 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007508 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007509 return null;
7510 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007511 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 final long identity = Binder.clearCallingIdentity();
7514 try {
7515 if (phone != null) {
7516 return phone.getClientRequestStats();
7517 }
7518
7519 return null;
7520 } finally {
7521 Binder.restoreCallingIdentity(identity);
7522 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007523 }
7524
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007525 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007526 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007527 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007528 }
Jack Yueb4124c2017-02-16 15:32:43 -08007529
7530 /**
Grace Chen70990072017-03-24 17:21:30 -07007531 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007532 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007533 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007534 * @param state State of SIM (power down, power up, pass through)
7535 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7536 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7537 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007538 *
7539 **/
7540 @Override
Grace Chen70990072017-03-24 17:21:30 -07007541 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007542 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007543 Phone phone = PhoneFactory.getPhone(slotIndex);
7544
vagdeviaf9a5b92018-08-15 16:01:53 -07007545 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 final long identity = Binder.clearCallingIdentity();
7548 try {
7549 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007550 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 }
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007554 }
7555 }
Shuo Qiandd210312017-04-12 22:11:33 +00007556
Tyler Gunn65d45c22017-06-05 11:22:26 -07007557 private boolean isUssdApiAllowed(int subId) {
7558 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007559 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007560 if (configManager == null) {
7561 return false;
7562 }
7563 PersistableBundle pb = configManager.getConfigForSubId(subId);
7564 if (pb == null) {
7565 return false;
7566 }
7567 return pb.getBoolean(
7568 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7569 }
7570
Shuo Qiandd210312017-04-12 22:11:33 +00007571 /**
7572 * Check if phone is in emergency callback mode
7573 * @return true if phone is in emergency callback mode
7574 * @param subId sub id
7575 */
goneil9c5f4872017-12-05 14:07:56 -08007576 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007577 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007578 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007579 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580
7581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 if (phone != null) {
7584 return phone.isInEcm();
7585 } else {
7586 return false;
7587 }
7588 } finally {
7589 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007590 }
7591 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007592
7593 /**
7594 * Get the current signal strength information for the given subscription.
7595 * Because this information is not updated when the device is in a low power state
7596 * it should not be relied-upon to be current.
7597 * @param subId Subscription index
7598 * @return the most recent cached signal strength info from the modem
7599 */
7600 @Override
7601 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 final long identity = Binder.clearCallingIdentity();
7603 try {
7604 Phone p = getPhone(subId);
7605 if (p == null) {
7606 return null;
7607 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 return p.getSignalStrength();
7610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007613 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007614
Pengquan Meng77b7f132018-08-22 14:49:57 -07007615 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007616 * Get the current modem radio state for the given slot.
7617 * @param slotIndex slot index.
7618 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007619 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007620 * @return the current radio power state from the modem
7621 */
7622 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007623 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007624 Phone phone = PhoneFactory.getPhone(slotIndex);
7625 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7627 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007628 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7629 }
7630
7631 final long identity = Binder.clearCallingIdentity();
7632 try {
7633 return phone.getRadioPowerState();
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
7636 }
7637 }
7638 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7639 }
7640
7641 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007642 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7643 *
7644 * <p>Requires one of the following permissions:
7645 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7646 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7647 * privileges.
7648 *
7649 * @param subId subscription id
7650 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7651 * {@code false}.
7652 */
7653 @Override
7654 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007655 try {
7656 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7657 null);
7658 } catch (Exception e) {
7659 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7660 mApp, subId, "isDataRoamingEnabled");
7661 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007662
Pengquan Menga1bb6272018-09-06 09:59:22 -07007663 boolean isEnabled = false;
7664 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007665 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007666 Phone phone = getPhone(subId);
7667 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007668 } finally {
7669 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007670 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007671 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007672 }
7673
7674
7675 /**
7676 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7677 *
7678 * <p> Requires permission:
7679 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7680 * privileges.
7681 *
7682 * @param subId subscription id
7683 * @param isEnabled {@code true} means enable, {@code false} means disable.
7684 */
7685 @Override
7686 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7688 mApp, subId, "setDataRoamingEnabled");
7689
Pengquan Menga1bb6272018-09-06 09:59:22 -07007690 final long identity = Binder.clearCallingIdentity();
7691 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007692 Phone phone = getPhone(subId);
7693 if (phone != null) {
7694 phone.setDataRoamingEnabled(isEnabled);
7695 }
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007698 }
7699 }
7700
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007701 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007702 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007703 TelephonyPermissions
7704 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007705 mApp, subId, "isManualNetworkSelectionAllowed");
7706
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007707 boolean isAllowed = true;
7708 final long identity = Binder.clearCallingIdentity();
7709 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007710 Phone phone = getPhone(subId);
7711 if (phone != null) {
7712 isAllowed = phone.isCspPlmnEnabled();
7713 }
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
7716 }
7717 return isAllowed;
7718 }
7719
7720 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007721 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007722 // Verify that tha callingPackage belongs to the calling UID
7723 mApp.getSystemService(AppOpsManager.class)
7724 .checkPackage(Binder.getCallingUid(), callingPackage);
7725
Jordan Liu1e142fc2019-04-22 15:10:43 -07007726 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007727 try {
7728 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007729 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007730 } catch (SecurityException e) {
7731 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7732 // has carrier privileges on an active UICC
7733 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7734 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007735 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007736 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007737 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007738
7739 final long identity = Binder.clearCallingIdentity();
7740 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007741 UiccController uiccController = UiccController.getInstance();
7742 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007743 if (hasReadPermission) {
7744 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007745 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007746
7747 // Remove private info if the caller doesn't have access
7748 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7749 for (UiccCardInfo cardInfo : cardInfos) {
7750 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7751 // is available
7752 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7753 if (card == null || card.getUiccProfile() == null) {
7754 // assume no access if the card or profile is unavailable
7755 filteredInfos.add(cardInfo.getUnprivileged());
7756 continue;
7757 }
7758 UiccProfile profile = card.getUiccProfile();
7759 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7760 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7761 filteredInfos.add(cardInfo);
7762 } else {
7763 filteredInfos.add(cardInfo.getUnprivileged());
7764 }
7765 }
7766 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007767 } finally {
7768 Binder.restoreCallingIdentity(identity);
7769 }
7770 }
7771
7772 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007773 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007774 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 final long identity = Binder.clearCallingIdentity();
7777 try {
7778 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7779 if (slots == null) {
7780 Rlog.i(LOG_TAG, "slots is null.");
7781 return null;
7782 }
7783
7784 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7785 for (int i = 0; i < slots.length; i++) {
7786 UiccSlot slot = slots[i];
7787 if (slot == null) {
7788 continue;
7789 }
7790
Jordan Liu7be7e652019-05-06 18:55:02 +00007791 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 UiccCard card = slot.getUiccCard();
7793 if (card != null) {
7794 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007795 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007796 cardId = slot.getEid();
7797 if (TextUtils.isEmpty(cardId)) {
7798 cardId = slot.getIccId();
7799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 }
7801
Jordan Liu857451f2019-05-09 16:35:35 -07007802 if (cardId != null) {
7803 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7804 // if cardId is an EID, it's all digits so this is fine
7805 cardId = IccUtils.stripTrailingFs(cardId);
7806 }
7807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 int cardState = 0;
7809 switch (slot.getCardState()) {
7810 case CARDSTATE_ABSENT:
7811 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7812 break;
7813 case CARDSTATE_PRESENT:
7814 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7815 break;
7816 case CARDSTATE_ERROR:
7817 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7818 break;
7819 case CARDSTATE_RESTRICTED:
7820 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7821 break;
7822 default:
7823 break;
7824
7825 }
7826
7827 infos[i] = new UiccSlotInfo(
7828 slot.isActive(),
7829 slot.isEuicc(),
7830 cardId,
7831 cardState,
7832 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007833 slot.isExtendedApduSupported(),
7834 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835 }
7836 return infos;
7837 } finally {
7838 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007839 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007840 }
7841
7842 @Override
7843 public boolean switchSlots(int[] physicalSlots) {
7844 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845
7846 final long identity = Binder.clearCallingIdentity();
7847 try {
7848 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7849 } finally {
7850 Binder.restoreCallingIdentity(identity);
7851 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007852 }
Jack Yu4c988042018-02-27 15:30:01 -08007853
7854 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007855 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007856 final long identity = Binder.clearCallingIdentity();
7857 try {
7858 return UiccController.getInstance().getCardIdForDefaultEuicc();
7859 } finally {
7860 Binder.restoreCallingIdentity(identity);
7861 }
7862 }
7863
Pengquan Meng85728fb2018-03-12 16:31:21 -07007864 /**
goneil47ffb6e2018-04-06 15:40:58 -07007865 * A test API to reload the UICC profile.
7866 *
7867 * <p>Requires that the calling app has permission
7868 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7869 * @hide
7870 */
7871 @Override
7872 public void refreshUiccProfile(int subId) {
7873 enforceModifyPermission();
7874
7875 final long identity = Binder.clearCallingIdentity();
7876 try {
7877 Phone phone = getPhone(subId);
7878 if (phone == null) {
7879 return;
7880 }
7881 UiccCard uiccCard = phone.getUiccCard();
7882 if (uiccCard == null) {
7883 return;
7884 }
7885 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7886 if (uiccProfile == null) {
7887 return;
7888 }
7889 uiccProfile.refresh();
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
7892 }
7893 }
7894
7895 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007896 * Returns false if the mobile data is disabled by default, otherwise return true.
7897 */
7898 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007899 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007900 }
7901
7902 /**
7903 * Returns true if the data roaming is enabled by default, i.e the system property
7904 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7905 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7906 */
7907 private boolean getDefaultDataRoamingEnabled(int subId) {
7908 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007909 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07007910 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007911 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7912 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7913 return isDataRoamingEnabled;
7914 }
7915
7916 /**
7917 * Returns the default network type for the given {@code subId}, if the default network type is
7918 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7919 */
7920 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007921 List<Integer> list = TelephonyProperties.default_network();
7922 int phoneId = mSubscriptionController.getPhoneId(subId);
7923 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7924 return list.get(phoneId);
7925 }
7926 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007927 }
fionaxua13278b2018-03-21 00:08:13 -07007928
7929 @Override
7930 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007931 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933
7934 final long identity = Binder.clearCallingIdentity();
7935 try {
7936 final Phone phone = getPhone(subId);
7937 if (phone == null) {
7938 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7939 return;
7940 }
chen xueaba88a2019-03-15 13:15:10 -07007941 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7942 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07007943 if (carrierPrivilegeRules == null) {
7944 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7945 } else {
7946 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 } finally {
7949 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007950 }
fionaxua13278b2018-03-21 00:08:13 -07007951 }
7952
7953 @Override
7954 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007955 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956
7957 final long identity = Binder.clearCallingIdentity();
7958 try {
7959 final Phone phone = getPhone(subId);
7960 if (phone == null) {
7961 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7962 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7963 }
7964 return phone.getCarrierIdListVersion();
7965 } finally {
7966 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007967 }
fionaxua13278b2018-03-21 00:08:13 -07007968 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007969
7970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007971 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7972 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007974 mApp, subId, callingPackage, callingFeatureId,
7975 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007976 return -1;
7977 }
7978
7979 final long identity = Binder.clearCallingIdentity();
7980 try {
7981 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7982 } finally {
7983 Binder.restoreCallingIdentity(identity);
7984 }
7985 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007986
7987 @Override
7988 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007989 TelephonyPermissions
7990 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007991 mApp, subId, "getCdmaRoamingMode");
7992
7993 final long identity = Binder.clearCallingIdentity();
7994 try {
7995 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7996 } finally {
7997 Binder.restoreCallingIdentity(identity);
7998 }
7999 }
8000
8001 @Override
8002 public boolean setCdmaRoamingMode(int subId, int mode) {
8003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8004 mApp, subId, "setCdmaRoamingMode");
8005
8006 final long identity = Binder.clearCallingIdentity();
8007 try {
8008 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8009 } finally {
8010 Binder.restoreCallingIdentity(identity);
8011 }
8012 }
8013
8014 @Override
8015 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8017 mApp, subId, "setCdmaSubscriptionMode");
8018
8019 final long identity = Binder.clearCallingIdentity();
8020 try {
8021 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8022 } finally {
8023 Binder.restoreCallingIdentity(identity);
8024 }
8025 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008026
sqianc5eccab2018-10-19 18:46:41 -07008027 @Override
sqian8c685422019-02-22 15:55:18 -08008028 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008029 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008031 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8032 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008033 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8034 }
8035 final long identity = Binder.clearCallingIdentity();
8036 try {
sqian854d44b2018-12-12 16:48:18 -08008037 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8038 for (Phone phone: PhoneFactory.getPhones()) {
8039 if (phone.getEmergencyNumberTracker() != null
8040 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8041 emergencyNumberListInternal.put(
8042 phone.getSubId(),
8043 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8044 }
sqian11b7a0e2018-12-05 18:48:28 -08008045 }
sqian854d44b2018-12-12 16:48:18 -08008046 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008047 } finally {
8048 Binder.restoreCallingIdentity(identity);
8049 }
sqianc5eccab2018-10-19 18:46:41 -07008050 }
8051
8052 @Override
sqian8c685422019-02-22 15:55:18 -08008053 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008054 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008055 if (!exactMatch) {
8056 TelephonyPermissions
8057 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008058 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008059 }
8060 final long identity = Binder.clearCallingIdentity();
8061 try {
sqian854d44b2018-12-12 16:48:18 -08008062 for (Phone phone: PhoneFactory.getPhones()) {
8063 if (phone.getEmergencyNumberTracker() != null
8064 && phone.getEmergencyNumberTracker() != null) {
8065 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
8066 number, exactMatch)) {
8067 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008068 }
8069 }
sqian11b7a0e2018-12-05 18:48:28 -08008070 }
8071 return false;
8072 } finally {
8073 Binder.restoreCallingIdentity(identity);
8074 }
8075 }
8076
sqianf4ca7ed2019-01-15 18:32:07 -08008077 /**
8078 * Update emergency number list for test mode.
8079 */
8080 @Override
8081 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8083 "updateEmergencyNumberListTestMode");
8084
8085 final long identity = Binder.clearCallingIdentity();
8086 try {
8087 for (Phone phone: PhoneFactory.getPhones()) {
8088 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8089 if (tracker != null) {
8090 tracker.executeEmergencyNumberTestModeCommand(action, num);
8091 }
8092 }
8093 } finally {
8094 Binder.restoreCallingIdentity(identity);
8095 }
8096 }
8097
8098 /**
8099 * Get the full emergency number list for test mode.
8100 */
8101 @Override
8102 public List<String> getEmergencyNumberListTestMode() {
8103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8104 "getEmergencyNumberListTestMode");
8105
8106 final long identity = Binder.clearCallingIdentity();
8107 try {
8108 Set<String> emergencyNumbers = new HashSet<>();
8109 for (Phone phone: PhoneFactory.getPhones()) {
8110 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8111 if (tracker != null) {
8112 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8113 emergencyNumbers.add(num.getNumber());
8114 }
8115 }
8116 }
8117 return new ArrayList<>(emergencyNumbers);
8118 } finally {
8119 Binder.restoreCallingIdentity(identity);
8120 }
8121 }
8122
chen xud6b45bd2018-10-30 22:27:10 -07008123 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008124 public int getEmergencyNumberDbVersion(int subId) {
8125 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8126
8127 final long identity = Binder.clearCallingIdentity();
8128 try {
8129 final Phone phone = getPhone(subId);
8130 if (phone == null) {
8131 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8132 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8133 }
8134 return phone.getEmergencyNumberDbVersion();
8135 } finally {
8136 Binder.restoreCallingIdentity(identity);
8137 }
8138 }
8139
8140 @Override
8141 public void notifyOtaEmergencyNumberDbInstalled() {
8142 enforceModifyPermission();
8143
8144 final long identity = Binder.clearCallingIdentity();
8145 try {
8146 for (Phone phone: PhoneFactory.getPhones()) {
8147 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8148 if (tracker != null) {
8149 tracker.updateOtaEmergencyNumberDatabase();
8150 }
8151 }
8152 } finally {
8153 Binder.restoreCallingIdentity(identity);
8154 }
8155 }
8156
8157 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008158 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008159 enforceActiveEmergencySessionPermission();
8160
8161 final long identity = Binder.clearCallingIdentity();
8162 try {
8163 for (Phone phone: PhoneFactory.getPhones()) {
8164 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8165 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008166 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8167 }
8168 }
8169 } finally {
8170 Binder.restoreCallingIdentity(identity);
8171 }
8172 }
8173
8174 @Override
8175 public void resetOtaEmergencyNumberDbFilePath() {
8176 enforceActiveEmergencySessionPermission();
8177
8178 final long identity = Binder.clearCallingIdentity();
8179 try {
8180 for (Phone phone: PhoneFactory.getPhones()) {
8181 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8182 if (tracker != null) {
8183 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008184 }
8185 }
8186 } finally {
8187 Binder.restoreCallingIdentity(identity);
8188 }
8189 }
8190
8191 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008192 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8193 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8194 Phone phone = getPhone(subId);
8195 if (phone == null) {
8196 return null;
8197 }
8198 final long identity = Binder.clearCallingIdentity();
8199 try {
8200 UiccProfile profile = UiccController.getInstance()
8201 .getUiccProfileForPhone(phone.getPhoneId());
8202 if (profile != null) {
8203 return profile.getCertsFromCarrierPrivilegeAccessRules();
8204 }
8205 } finally {
8206 Binder.restoreCallingIdentity(identity);
8207 }
8208 return null;
8209 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008210
8211 /**
8212 * Enable or disable a modem stack.
8213 */
8214 @Override
8215 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8216 enforceModifyPermission();
8217
8218 final long identity = Binder.clearCallingIdentity();
8219 try {
8220 Phone phone = PhoneFactory.getPhone(slotIndex);
8221 if (phone == null) {
8222 return false;
8223 } else {
8224 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8225 }
8226 } finally {
8227 Binder.restoreCallingIdentity(identity);
8228 }
8229 }
Michelecea4cf22018-12-21 15:00:11 -08008230
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008231 /**
8232 * Whether a modem stack is enabled or not.
8233 */
8234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008235 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8236 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008237 Phone phone = PhoneFactory.getPhone(slotIndex);
8238 if (phone == null) return false;
8239
8240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008241 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8242 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008243 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8244 }
8245
8246 final long identity = Binder.clearCallingIdentity();
8247 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008248 try {
8249 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8250 } catch (NoSuchElementException ex) {
8251 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8252 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008253 } finally {
8254 Binder.restoreCallingIdentity(identity);
8255 }
8256 }
8257
Michelecea4cf22018-12-21 15:00:11 -08008258 @Override
Michele0ea7d782019-03-19 14:58:42 -07008259 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008260 enforceModifyPermission();
8261
8262 final long identity = Binder.clearCallingIdentity();
8263 try {
8264 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008265 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008266 .commit();
8267 } finally {
8268 Binder.restoreCallingIdentity(identity);
8269 }
8270 }
8271
8272 @Override
Michele0ea7d782019-03-19 14:58:42 -07008273 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008274 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008276 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8277 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008278 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008279 }
Michelecea4cf22018-12-21 15:00:11 -08008280
8281 final long identity = Binder.clearCallingIdentity();
8282 try {
Michele0ea7d782019-03-19 14:58:42 -07008283 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008284 } finally {
8285 Binder.restoreCallingIdentity(identity);
8286 }
8287 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008288
Michele0ea7d782019-03-19 14:58:42 -07008289 @TelephonyManager.IsMultiSimSupportedResult
8290 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008291 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8292 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8293 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008294 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8295 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008296 }
8297 // Check if the hardware supports multisim functionality. If usage of multisim is not
8298 // supported by the modem, indicate that it is restricted.
8299 PhoneCapability staticCapability =
8300 mPhoneConfigurationManager.getStaticPhoneCapability();
8301 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008302 loge("isMultiSimSupportedInternal: no static configuration available");
8303 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008304 }
Sarah Chin7caee492020-02-18 20:49:02 +00008305 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008306 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8307 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008308 }
8309 // Check if support of multiple SIMs is restricted by carrier
8310 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008311 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008312 }
8313
Michele0ea7d782019-03-19 14:58:42 -07008314 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008315 }
8316
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008317 /**
8318 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008319 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8320 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8321 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008322 * @param numOfSims number of active sims we want to switch to
8323 */
8324 @Override
8325 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008326 if (numOfSims == 1) {
8327 enforceModifyPermission();
8328 } else {
8329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8330 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8331 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008332 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008333
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008334 try {
Michele30b57b22019-03-01 12:01:14 -08008335 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008336 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008337 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8338 return;
8339 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008340 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
8343 }
8344 }
8345
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008346 @Override
8347 public boolean isApplicationOnUicc(int subId, int appType) {
8348 enforceReadPrivilegedPermission("isApplicationOnUicc");
8349 Phone phone = getPhone(subId);
8350 if (phone == null) {
8351 return false;
8352 }
8353 final long identity = Binder.clearCallingIdentity();
8354 try {
8355 UiccCard uiccCard = phone.getUiccCard();
8356 if (uiccCard == null) {
8357 return false;
8358 }
8359 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8360 if (uiccProfile == null) {
8361 return false;
8362 }
8363 if (TelephonyManager.APPTYPE_SIM <= appType
8364 && appType <= TelephonyManager.APPTYPE_ISIM) {
8365 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8366 }
8367 return false;
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
8371 }
8372
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008373 /**
chen xub4baa772019-04-03 10:23:41 -07008374 * Get whether making changes to modem configurations will trigger reboot.
8375 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008376 */
8377 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008378 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8379 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008380 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008381 mApp, subId, callingPackage, callingFeatureId,
8382 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008383 return false;
8384 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008385 final long identity = Binder.clearCallingIdentity();
8386 try {
8387 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8388 } finally {
8389 Binder.restoreCallingIdentity(identity);
8390 }
8391 }
8392
Nathan Harold29f5f052019-02-15 13:41:57 -08008393 private void updateModemStateMetrics() {
8394 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8395 // TODO: check the state for each modem if the api is ready.
8396 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8397 }
8398
Pengquan Meng3889a572019-01-23 11:16:29 -08008399 @Override
8400 public int[] getSlotsMapping() {
8401 enforceReadPrivilegedPermission("getSlotsMapping");
8402
8403 final long identity = Binder.clearCallingIdentity();
8404 try {
8405 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8406 // All logical slots should have a mapping to a physical slot.
8407 int[] logicalSlotsMapping = new int[phoneCount];
8408 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8409 for (int i = 0; i < slotInfos.length; i++) {
8410 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8411 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8412 }
8413 }
8414 return logicalSlotsMapping;
8415 } finally {
8416 Binder.restoreCallingIdentity(identity);
8417 }
8418 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008419
8420 /**
8421 * Get the IRadio HAL Version
8422 */
8423 @Override
8424 public int getRadioHalVersion() {
8425 Phone phone = getDefaultPhone();
8426 if (phone == null) return -1;
8427 HalVersion hv = phone.getHalVersion();
8428 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8429 return hv.major * 100 + hv.minor;
8430 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008431
8432 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008433 * Get the current calling package name.
8434 * @return the current calling package name
8435 */
8436 @Override
8437 public String getCurrentPackageName() {
8438 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8439 }
8440
8441 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008442 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8443 * corresponding network requests on a subId.
8444 *
8445 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008446 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008447 * 2) APN is un-metered for this subscription, or
8448 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008449 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008450 *
8451 * @return whether data is allowed for a apn type.
8452 *
8453 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008454 */
8455 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008456 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008457 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8458 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008459
8460 // Now that all security checks passes, perform the operation as ourselves.
8461 final long identity = Binder.clearCallingIdentity();
8462 try {
8463 Phone phone = getPhone(subId);
8464 if (phone == null) return false;
8465
Jack Yu41407ee2019-05-13 16:54:09 -07008466 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008467 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8468 } finally {
8469 Binder.restoreCallingIdentity(identity);
8470 }
8471 }
8472
8473 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008474 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008475 enforceReadPrivilegedPermission("isApnMetered");
8476
8477 // Now that all security checks passes, perform the operation as ourselves.
8478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 Phone phone = getPhone(subId);
8481 if (phone == null) return true; // By default return true.
8482
Jack Yu41407ee2019-05-13 16:54:09 -07008483 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008484 } finally {
8485 Binder.restoreCallingIdentity(identity);
8486 }
8487 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008488
8489 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008490 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8491 int subscriptionId, IBooleanConsumer resultCallback) {
8492 enforceModifyPermission();
8493 long token = Binder.clearCallingIdentity();
8494 try {
8495 Phone phone = getPhone(subscriptionId);
8496 if (phone == null) {
8497 try {
8498 if (resultCallback != null) {
8499 resultCallback.accept(false);
8500 }
8501 } catch (RemoteException e) {
8502 // ignore
8503 }
8504 return;
8505 }
8506 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8507 Pair.create(specifiers, (x) -> {
8508 try {
8509 if (resultCallback != null) {
8510 resultCallback.accept(x);
8511 }
8512 } catch (RemoteException e) {
8513 // ignore
8514 }
8515 });
8516 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8517 } finally {
8518 Binder.restoreCallingIdentity(token);
8519 }
8520 }
8521
8522 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008523 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008524 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008525 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8526 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8527 if (iccRecords == null) {
8528 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8529 return false;
8530 }
8531 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8532 }
8533
8534 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008535 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8536 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008537 if (callingPackage == null) {
8538 callingPackage = getCurrentPackageName();
8539 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008540 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8541 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008542 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8543 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008544 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8545 }
8546 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8547 Intent intent = new Intent();
8548 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8549 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8550 // Bring up choose default SMS subscription dialog right now
8551 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8552 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8553 mApp.startActivity(intent);
8554 }
chen xud5ca2d52019-05-28 15:20:57 -07008555
8556 @Override
8557 public String getMmsUAProfUrl(int subId) {
8558 //TODO investigate if this API should require proper permission check in R b/133791609
8559 final long identity = Binder.clearCallingIdentity();
8560 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008561 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8562 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8563 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8564 return carrierUAProfUrl;
8565 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008566 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8567 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008568 } finally {
8569 Binder.restoreCallingIdentity(identity);
8570 }
8571 }
8572
8573 @Override
8574 public String getMmsUserAgent(int subId) {
8575 //TODO investigate if this API should require proper permission check in R b/133791609
8576 final long identity = Binder.clearCallingIdentity();
8577 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008578 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8579 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8580 if (!TextUtils.isEmpty(carrierUserAgent)) {
8581 return carrierUserAgent;
8582 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008583 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8584 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008585 } finally {
8586 Binder.restoreCallingIdentity(identity);
8587 }
8588 }
Jack Yub07d4972019-05-28 16:12:25 -07008589
8590 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008591 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8592 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8593
8594 final long identity = Binder.clearCallingIdentity();
8595 try {
8596 Phone phone = getPhone(subscriptionId);
8597 if (phone == null) return false;
8598
8599 switch (policy) {
8600 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8601 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8602 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8603 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8604 default:
8605 throw new IllegalArgumentException(policy + " is not a valid policy");
8606 }
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
8610 }
8611
8612 @Override
8613 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8614 boolean enabled) {
8615 enforceModifyPermission();
8616
8617 final long identity = Binder.clearCallingIdentity();
8618 try {
8619 Phone phone = getPhone(subscriptionId);
8620 if (phone == null) return;
8621
8622 switch (policy) {
8623 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8624 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8625 break;
8626 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8627 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8628 break;
8629 default:
8630 throw new IllegalArgumentException(policy + " is not a valid policy");
8631 }
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
8635 }
8636
8637 @Override
Jack Yub07d4972019-05-28 16:12:25 -07008638 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8639 enforceModifyPermission();
8640
8641 // Now that all security checks passes, perform the operation as ourselves.
8642 final long identity = Binder.clearCallingIdentity();
8643 try {
8644 Phone phone = getPhone(subId);
8645 if (phone == null) return false;
8646
8647 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8648 } finally {
8649 Binder.restoreCallingIdentity(identity);
8650 }
8651 }
8652
8653 @Override
8654 public boolean isDataAllowedInVoiceCall(int subId) {
8655 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8656
8657 // Now that all security checks passes, perform the operation as ourselves.
8658 final long identity = Binder.clearCallingIdentity();
8659 try {
8660 Phone phone = getPhone(subId);
8661 if (phone == null) return false;
8662
8663 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8664 } finally {
8665 Binder.restoreCallingIdentity(identity);
8666 }
8667 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008668
changbettyd5c246e2019-12-24 15:40:37 +08008669 @Override
8670 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8671 enforceModifyPermission();
8672
8673 // Now that all security checks passes, perform the operation as ourselves.
8674 final long identity = Binder.clearCallingIdentity();
8675 try {
8676 Phone phone = getPhone(subId);
8677 if (phone == null) return false;
8678
8679 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
8684
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008685 /**
8686 * Updates whether conference event pacakge handling is enabled.
8687 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8688 * otherwise.
8689 */
8690 @Override
8691 public void setCepEnabled(boolean isCepEnabled) {
8692 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8693
8694 final long identity = Binder.clearCallingIdentity();
8695 try {
8696 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8697 for (Phone phone : PhoneFactory.getPhones()) {
8698 Phone defaultPhone = phone.getImsPhone();
8699 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8700 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8701 ImsPhoneCallTracker imsPhoneCallTracker =
8702 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8703 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8704 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8705 + imsPhone.getMsisdn());
8706 }
8707 }
8708 } finally {
8709 Binder.restoreCallingIdentity(identity);
8710 }
8711 }
allenwtsu46dcc572020-01-08 18:24:03 +08008712
8713 /**
8714 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8715 *
8716 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8717 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8718 * before being read.
8719 */
8720 @Override
8721 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8722 isCompressed) {
8723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8724 mApp, subId, "notifyRcsAutoConfigurationReceived");
8725 try {
8726 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8727 if (configBinder == null) {
8728 Rlog.e(LOG_TAG, "null result for getImsConfig");
8729 } else {
8730 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8731 }
8732 } catch (RemoteException e) {
8733 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8734 }
8735 }
zoey chene02881a2019-12-30 16:11:23 +08008736
8737 @Override
8738 public boolean isIccLockEnabled(int subId) {
8739 enforceReadPrivilegedPermission("isIccLockEnabled");
8740
8741 // Now that all security checks passes, perform the operation as ourselves.
8742 final long identity = Binder.clearCallingIdentity();
8743 try {
8744 Phone phone = getPhone(subId);
8745 if (phone != null && phone.getIccCard() != null) {
8746 return phone.getIccCard().getIccLockEnabled();
8747 } else {
8748 return false;
8749 }
8750 } finally {
8751 Binder.restoreCallingIdentity(identity);
8752 }
8753 }
8754
8755 /**
8756 * Set the ICC pin lock enabled or disabled.
8757 *
8758 * @return an integer representing the status of IccLock enabled or disabled in the following
8759 * three cases:
8760 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8761 * successfully.
8762 * - Positive number and zero for remaining password attempts.
8763 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8764 *
8765 */
8766 @Override
8767 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8768 enforceModifyPermission();
8769
8770 Phone phone = getPhone(subId);
8771 if (phone == null) {
8772 return 0;
8773 }
8774 // Now that all security checks passes, perform the operation as ourselves.
8775 final long identity = Binder.clearCallingIdentity();
8776 try {
8777 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8778 new Pair<Boolean, String>(enabled, password), phone, null);
8779 return attemptsRemaining;
8780
8781 } catch (Exception e) {
8782 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8783 } finally {
8784 Binder.restoreCallingIdentity(identity);
8785 }
8786 return 0;
8787 }
8788
8789 /**
8790 * Change the ICC password used in ICC pin lock.
8791 *
8792 * @return an integer representing the status of IccLock changed in the following three cases:
8793 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8794 * - Positive number and zero for remaining password attempts.
8795 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8796 *
8797 */
8798 @Override
8799 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8800 enforceModifyPermission();
8801
8802 Phone phone = getPhone(subId);
8803 if (phone == null) {
8804 return 0;
8805 }
8806 // Now that all security checks passes, perform the operation as ourselves.
8807 final long identity = Binder.clearCallingIdentity();
8808 try {
8809 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8810 new Pair<String, String>(oldPassword, newPassword), phone, null);
8811 return attemptsRemaining;
8812
8813 } catch (Exception e) {
8814 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8815 } finally {
8816 Binder.restoreCallingIdentity(identity);
8817 }
8818 return 0;
8819 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008820
8821 /**
8822 * Request for receiving user activity notification
8823 */
8824 @Override
8825 public void requestUserActivityNotification() {
8826 if (!mNotifyUserActivity.get()
8827 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8828 mNotifyUserActivity.set(true);
8829 }
8830 }
8831
8832 /**
8833 * Called when userActivity is signalled in the power manager.
8834 * This is safe to call from any thread, with any window manager locks held or not.
8835 */
8836 @Override
8837 public void userActivity() {
8838 // ***************************************
8839 // * Inherited from PhoneWindowManager *
8840 // ***************************************
8841 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8842 // WITH ITS LOCKS HELD.
8843 //
8844 // This code must be VERY careful about the locks
8845 // it acquires.
8846 // In fact, the current code acquires way too many,
8847 // and probably has lurking deadlocks.
8848
8849 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8850 throw new SecurityException("Only the OS may call notifyUserActivity()");
8851 }
8852
8853 if (mNotifyUserActivity.getAndSet(false)) {
8854 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8855 USER_ACTIVITY_NOTIFICATION_DELAY);
8856 }
8857 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008858
8859 @Override
8860 public boolean canConnectTo5GInDsdsMode() {
8861 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008863}