blob: ae4b130e584b34b571de3b83aa7059b3d94840dd [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;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080052import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080053import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070054import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import android.util.Slog;
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;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700132import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800133import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800135import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700136import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700137import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700138import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700140import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800141import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700142import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700143import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700144import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700145import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700146import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700148import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800150import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700152import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800153import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700154import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800155import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700156import com.android.internal.telephony.imsphone.ImsPhone;
157import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800158import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700159import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800161import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700164import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800165import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800167import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000168import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800169import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700170import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800171import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700172import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800174import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700175import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700176import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800177import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800178
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700179import java.io.FileDescriptor;
180import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800182import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800183import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800184import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800185import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100186import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800187import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700188import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
191/**
192 * Implementation of the ITelephony interface.
193 */
Santos Cordon117fee72014-05-16 17:56:12 -0700194public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 private static final String LOG_TAG = "PhoneInterfaceManager";
196 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
197 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800198 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199
200 // Message codes used with mMainThreadHandler
201 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700202 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
203 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204 private static final int CMD_OPEN_CHANNEL = 9;
205 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
206 private static final int CMD_CLOSE_CHANNEL = 11;
207 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800208 private static final int CMD_NV_READ_ITEM = 13;
209 private static final int EVENT_NV_READ_ITEM_DONE = 14;
210 private static final int CMD_NV_WRITE_ITEM = 15;
211 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
212 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
213 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700214 private static final int CMD_RESET_MODEM_CONFIG = 19;
215 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800216 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
217 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
218 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
219 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800220 private static final int CMD_SEND_ENVELOPE = 25;
221 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000222 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
223 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700224 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
225 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
226 private static final int CMD_EXCHANGE_SIM_IO = 31;
227 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800228 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
229 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700230 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
231 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700232 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
233 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700234 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
235 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
236 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700238 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
239 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
240 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
241 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700242 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800243 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
244 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000245 private static final int CMD_SWITCH_SLOTS = 50;
246 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700247 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
248 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
249 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
250 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
251 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
252 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
253 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
254 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700255 private static final int CMD_GET_ALL_CELL_INFO = 60;
256 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
257 private static final int CMD_GET_CELL_LOCATION = 62;
258 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700259 private static final int CMD_MODEM_REBOOT = 64;
260 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700261 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
262 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800263 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
264 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700265 private static final int CMD_GET_MODEM_STATUS = 70;
266 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700267 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
268 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700269 private static final int CMD_ERASE_MODEM_CONFIG = 74;
270 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800272 // Parameters of select command.
273 private static final int SELECT_COMMAND = 0xA4;
274 private static final int SELECT_P1 = 0x04;
275 private static final int SELECT_P2 = 0;
276 private static final int SELECT_P3 = 0x10;
277
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 /** The singleton instance. */
279 private static PhoneInterfaceManager sInstance;
280
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800283 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700284 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private AppOpsManager mAppOps;
286 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800287 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800288 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700289 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
Derek Tan97ebb422014-09-05 16:55:38 -0700291 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
292 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800293 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800294 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700295
Michelecea4cf22018-12-21 15:00:11 -0800296 // String to store multi SIM allowed
297 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
298
Derek Tan740e1672017-06-27 14:56:27 -0700299 // The AID of ISD-R.
300 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
301
yinxub1bed742017-04-17 11:45:04 -0700302 private NetworkScanRequestTracker mNetworkScanRequestTracker;
303
David Kelly5e06a7f2018-03-12 14:10:59 +0000304 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
305 private static final int MANUFACTURER_CODE_LENGTH = 8;
306
Derek Tan89e89d42014-07-08 17:00:10 -0700307 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700308 * Experiment flag to enable erase modem config on reset network, default value is false
309 */
310 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
311 "reset_network_erase_modem_config_enabled";
312
313 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700314 * A request object to use for transmitting data to an ICC.
315 */
316 private static final class IccAPDUArgument {
317 public int channel, cla, command, p1, p2, p3;
318 public String data;
319
320 public IccAPDUArgument(int channel, int cla, int command,
321 int p1, int p2, int p3, String data) {
322 this.channel = channel;
323 this.cla = cla;
324 this.command = command;
325 this.p1 = p1;
326 this.p2 = p2;
327 this.p3 = p3;
328 this.data = data;
329 }
330 }
331
332 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700333 * A request object to use for transmitting data to an ICC.
334 */
335 private static final class ManualNetworkSelectionArgument {
336 public OperatorInfo operatorInfo;
337 public boolean persistSelection;
338
339 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
340 this.operatorInfo = operatorInfo;
341 this.persistSelection = persistSelection;
342 }
343 }
344
345 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
347 * request after sending. The main thread will notify the request when it is complete.
348 */
349 private static final class MainThreadRequest {
350 /** The argument to use for the request */
351 public Object argument;
352 /** The result of the request that is run on the main thread */
353 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800354 // The subscriber id that this request applies to. Defaults to
355 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
356 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Nathan Harold92bed182018-10-12 18:16:49 -0700358 // In cases where subId is unavailable, the caller needs to specify the phone.
359 public Phone phone;
360
vagdeviaf9a5b92018-08-15 16:01:53 -0700361 public WorkSource workSource;
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 public MainThreadRequest(Object argument) {
364 this.argument = argument;
365 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800366
Nathan Harold92bed182018-10-12 18:16:49 -0700367 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
368 this.argument = argument;
369 if (phone != null) {
370 this.phone = phone;
371 }
372 this.workSource = workSource;
373 }
374
vagdeviaf9a5b92018-08-15 16:01:53 -0700375 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800376 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800377 if (subId != null) {
378 this.subId = subId;
379 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700380 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 }
383
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800384 private static final class IncomingThirdPartyCallArgs {
385 public final ComponentName component;
386 public final String callId;
387 public final String callerDisplayName;
388
389 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
390 String callerDisplayName) {
391 this.component = component;
392 this.callId = callId;
393 this.callerDisplayName = callerDisplayName;
394 }
395 }
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 /**
398 * A handler that processes messages on the main thread in the phone process. Since many
399 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
400 * inbound binder threads to the main thread in the phone process. The Binder thread
401 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
402 * on, which will be notified when the operation completes and will contain the result of the
403 * request.
404 *
405 * <p>If a MainThreadRequest object is provided in the msg.obj field,
406 * note that request.result must be set to something non-null for the calling thread to
407 * unblock.
408 */
409 private final class MainThreadHandler extends Handler {
410 @Override
411 public void handleMessage(Message msg) {
412 MainThreadRequest request;
413 Message onCompleted;
414 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800415 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800417 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
419 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 case CMD_HANDLE_USSD_REQUEST: {
421 request = (MainThreadRequest) msg.obj;
422 final Phone phone = getPhoneFromRequest(request);
423 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
424 String ussdRequest = ussdObject.first;
425 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 if (!isUssdApiAllowed(request.subId)) {
428 // Carrier does not support use of this API, return failure.
429 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
430 UssdResponse response = new UssdResponse(ussdRequest, null);
431 Bundle returnData = new Bundle();
432 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
433 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700434
Pengquan Menga1bb6272018-09-06 09:59:22 -0700435 request.result = true;
436 notifyRequester(request);
437 return;
438 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700439
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 try {
441 request.result = phone != null
442 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
443 } catch (CallStateException cse) {
444 request.result = false;
445 }
446 // Wake up the requesting thread
447 notifyRequester(request);
448 break;
pkanwar32d516d2016-10-14 19:37:38 -0700449 }
450
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700453 final Phone phone = getPhoneFromRequest(request);
454 request.result = phone != null ?
455 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
456 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800465 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 if (uiccCard == null) {
467 loge("iccTransmitApduLogicalChannel: No UICC");
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
472 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 iccArgument.channel, iccArgument.cla, iccArgument.command,
475 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700477 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 break;
479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 ar = (AsyncResult) msg.obj;
482 request = (MainThreadRequest) ar.userObj;
483 if (ar.exception == null && ar.result != null) {
484 request.result = ar.result;
485 } else {
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
487 if (ar.result == null) {
488 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800489 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800491 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 } else {
493 loge("iccTransmitApduLogicalChannel: Unknown exception");
494 }
495 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 break;
498
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
500 request = (MainThreadRequest) msg.obj;
501 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800502 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 if (uiccCard == null) {
504 loge("iccTransmitApduBasicChannel: No UICC");
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 } else {
508 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
509 request);
510 uiccCard.iccTransmitApduBasicChannel(
511 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
512 iccArgument.p3, iccArgument.data, onCompleted);
513 }
514 break;
515
516 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
517 ar = (AsyncResult) msg.obj;
518 request = (MainThreadRequest) ar.userObj;
519 if (ar.exception == null && ar.result != null) {
520 request.result = ar.result;
521 } else {
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
523 if (ar.result == null) {
524 loge("iccTransmitApduBasicChannel: Empty response");
525 } else if (ar.exception instanceof CommandException) {
526 loge("iccTransmitApduBasicChannel: CommandException: " +
527 ar.exception);
528 } else {
529 loge("iccTransmitApduBasicChannel: Unknown exception");
530 }
531 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 break;
534
535 case CMD_EXCHANGE_SIM_IO:
536 request = (MainThreadRequest) msg.obj;
537 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 if (uiccCard == null) {
540 loge("iccExchangeSimIO: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
545 request);
546 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
547 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
548 iccArgument.data, onCompleted);
549 }
550 break;
551
552 case EVENT_EXCHANGE_SIM_IO_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
557 } else {
558 request.result = new IccIoResult(0x6f, 0, (byte[])null);
559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 break;
562
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 case CMD_SEND_ENVELOPE:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("sendEnvelopeWithStatus: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
572 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 break;
575
576 case EVENT_SEND_ENVELOPE_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
583 if (ar.result == null) {
584 loge("sendEnvelopeWithStatus: Empty response");
585 } else if (ar.exception instanceof CommandException) {
586 loge("sendEnvelopeWithStatus: CommandException: " +
587 ar.exception);
588 } else {
589 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
590 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800593 break;
594
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 case CMD_OPEN_CHANNEL:
596 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800597 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800598 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 if (uiccCard == null) {
600 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800601 request.result = new IccOpenLogicalChannelResponse(-1,
602 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 } else {
605 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800606 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
607 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
611 case EVENT_OPEN_CHANNEL_DONE:
612 ar = (AsyncResult) msg.obj;
613 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 int[] result = (int[]) ar.result;
617 int channelId = result[0];
618 byte[] selectResponse = null;
619 if (result.length > 1) {
620 selectResponse = new byte[result.length - 1];
621 for (int i = 1; i < result.length; ++i) {
622 selectResponse[i - 1] = (byte) result[i];
623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 if (ar.result == null) {
629 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 if (ar.exception != null) {
632 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
633 }
634
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700635 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700636 if (ar.exception instanceof CommandException) {
637 CommandException.Error error =
638 ((CommandException) (ar.exception)).getCommandError();
639 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700640 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700641 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 }
644 }
645 openChannelResp = new IccOpenLogicalChannelResponse(
646 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700648 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case CMD_CLOSE_CHANNEL:
653 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800654 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 if (uiccCard == null) {
656 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900657 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 } else {
660 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
661 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
665 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800666 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
667 break;
668
669 case CMD_NV_READ_ITEM:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800672 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
673 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800674 break;
675
676 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800682 request.result = "";
683 if (ar.result == null) {
684 loge("nvReadItem: Empty response");
685 } else if (ar.exception instanceof CommandException) {
686 loge("nvReadItem: CommandException: " +
687 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800689 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 }
691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 break;
694
Jake Hambye994d462014-02-03 13:10:13 -0800695 case CMD_NV_WRITE_ITEM:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
698 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_WRITE_ITEM_DONE:
704 handleNullReturnEvent(msg, "nvWriteItem");
705 break;
706
707 case CMD_NV_WRITE_CDMA_PRL:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800710 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800711 break;
712
713 case EVENT_NV_WRITE_CDMA_PRL_DONE:
714 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
715 break;
716
chen xu6dac5ab2018-10-26 17:39:23 -0700717 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800718 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700719 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800720 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
chen xu6dac5ab2018-10-26 17:39:23 -0700723 case EVENT_RESET_MODEM_CONFIG_DONE:
724 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 case CMD_GET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700730 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
734 ar = (AsyncResult) msg.obj;
735 request = (MainThreadRequest) ar.userObj;
736 if (ar.exception == null && ar.result != null) {
737 request.result = ar.result; // Integer
738 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800739 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 if (ar.result == null) {
741 loge("getPreferredNetworkType: Empty response");
742 } else if (ar.exception instanceof CommandException) {
743 loge("getPreferredNetworkType: CommandException: " +
744 ar.exception);
745 } else {
746 loge("getPreferredNetworkType: Unknown exception");
747 }
748 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case CMD_SET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
755 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700756 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800757 break;
758
759 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
760 handleNullReturnEvent(msg, "setPreferredNetworkType");
761 break;
762
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
764 request = (MainThreadRequest)msg.obj;
765 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800766 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000767 break;
768
769 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
770 ar = (AsyncResult)msg.obj;
771 request = (MainThreadRequest)ar.userObj;
772 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000774 break;
775
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800776 case CMD_SET_VOICEMAIL_NUMBER:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
779 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800780 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
781 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800782 break;
783
784 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
785 handleNullReturnEvent(msg, "setVoicemailNumber");
786 break;
787
Stuart Scott54788802015-03-30 13:18:01 -0700788 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
791 request);
792 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
793 break;
794
795 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
796 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
797 break;
798
Shishir Agrawal302c8692015-06-19 13:49:39 -0700799 case CMD_PERFORM_NETWORK_SCAN:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
802 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
803 break;
804
805 case EVENT_PERFORM_NETWORK_SCAN_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 CellNetworkScanResult cellScanResult;
809 if (ar.exception == null && ar.result != null) {
810 cellScanResult = new CellNetworkScanResult(
811 CellNetworkScanResult.STATUS_SUCCESS,
812 (List<OperatorInfo>) ar.result);
813 } else {
814 if (ar.result == null) {
815 loge("getCellNetworkScanResults: Empty response");
816 }
817 if (ar.exception != null) {
818 loge("getCellNetworkScanResults: Exception: " + ar.exception);
819 }
820 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
821 if (ar.exception instanceof CommandException) {
822 CommandException.Error error =
823 ((CommandException) (ar.exception)).getCommandError();
824 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
826 } else if (error == CommandException.Error.GENERIC_FAILURE) {
827 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
828 }
829 }
830 cellScanResult = new CellNetworkScanResult(errorCode, null);
831 }
832 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700833 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
836 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
837 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 ManualNetworkSelectionArgument selArg =
839 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
841 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700842 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
843 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
846 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null) {
850 request.result = true;
851 } else {
852 request.result = false;
853 loge("setNetworkSelectionModeManual " + ar.exception);
854 }
855 notifyRequester(request);
856 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700857 break;
858
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700859 case CMD_GET_MODEM_ACTIVITY_INFO:
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700862 if (defaultPhone != null) {
863 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
864 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700865 break;
866
867 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result;
872 } else {
873 if (ar.result == null) {
874 loge("queryModemActivityInfo: Empty response");
875 } else if (ar.exception instanceof CommandException) {
876 loge("queryModemActivityInfo: CommandException: " +
877 ar.exception);
878 } else {
879 loge("queryModemActivityInfo: Unknown exception");
880 }
881 }
Amit Mahajand4766222016-01-28 15:28:28 -0800882 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
883 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800884 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800885 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700886 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700887 break;
888
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 case CMD_SET_ALLOWED_CARRIERS:
890 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800891 CarrierRestrictionRules argument =
892 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800894 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 break;
896
897 case EVENT_SET_ALLOWED_CARRIERS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800903 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
904 if (ar.exception instanceof CommandException) {
905 loge("setAllowedCarriers: CommandException: " + ar.exception);
906 CommandException.Error error =
907 ((CommandException) (ar.exception)).getCommandError();
908 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
909 request.result =
910 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
911 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700912 } else {
913 loge("setAllowedCarriers: Unknown exception");
914 }
915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 break;
918
919 case CMD_GET_ALLOWED_CARRIERS:
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800922 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 break;
924
925 case EVENT_GET_ALLOWED_CARRIERS_DONE:
926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result;
930 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800931 request.result = new IllegalStateException(
932 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 if (ar.result == null) {
934 loge("getAllowedCarriers: Empty response");
935 } else if (ar.exception instanceof CommandException) {
936 loge("getAllowedCarriers: CommandException: " +
937 ar.exception);
938 } else {
939 loge("getAllowedCarriers: Unknown exception");
940 }
941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700943 break;
944
Nathan Haroldb3014052017-01-25 15:57:32 -0800945 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
946 ar = (AsyncResult) msg.obj;
947 request = (MainThreadRequest) ar.userObj;
948 if (ar.exception == null && ar.result != null) {
949 request.result = ar.result;
950 } else {
951 request.result = new IllegalArgumentException(
952 "Failed to retrieve Forbidden Plmns");
953 if (ar.result == null) {
954 loge("getForbiddenPlmns: Empty response");
955 } else {
956 loge("getForbiddenPlmns: Unknown exception");
957 }
958 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700959 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800960 break;
961
962 case CMD_GET_FORBIDDEN_PLMNS:
963 request = (MainThreadRequest) msg.obj;
964 uiccCard = getUiccCardFromRequest(request);
965 if (uiccCard == null) {
966 loge("getForbiddenPlmns() UiccCard is null");
967 request.result = new IllegalArgumentException(
968 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800970 break;
971 }
972 Integer appType = (Integer) request.argument;
973 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
974 if (uiccApp == null) {
975 loge("getForbiddenPlmns() no app with specified type -- "
976 + appType);
977 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700978 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800979 break;
980 } else {
981 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
982 + " specified type -- " + appType);
983 }
984 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
985 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
986 onCompleted);
987 break;
988
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000989 case CMD_SWITCH_SLOTS:
990 request = (MainThreadRequest) msg.obj;
991 int[] physicalSlots = (int[]) request.argument;
992 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
993 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
994 break;
995
996 case EVENT_SWITCH_SLOTS_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
1001 break;
1002 case CMD_GET_NETWORK_SELECTION_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1005 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1006 break;
1007
1008 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 if (ar.exception != null) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1013 } else {
1014 int mode = ((int[]) ar.result)[0];
1015 if (mode == 0) {
1016 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1017 } else {
1018 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1019 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001020 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001021 notifyRequester(request);
1022 break;
1023 case CMD_GET_CDMA_ROAMING_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1026 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1027 break;
1028 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 if (ar.exception != null) {
1032 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1033 } else {
1034 request.result = ((int[]) ar.result)[0];
1035 }
1036 notifyRequester(request);
1037 break;
1038 case CMD_SET_CDMA_ROAMING_MODE:
1039 request = (MainThreadRequest) msg.obj;
1040 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1041 int mode = (int) request.argument;
1042 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1043 break;
1044 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 request.result = ar.exception == null;
1048 notifyRequester(request);
1049 break;
1050 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1053 int subscriptionMode = (int) request.argument;
1054 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1055 break;
1056 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 request.result = ar.exception == null;
1060 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001061 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 case CMD_GET_ALL_CELL_INFO:
1063 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001065 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 case EVENT_GET_ALL_CELL_INFO_DONE:
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001070 // If a timeout occurs, the response will be null
1071 request.result = (ar.exception == null && ar.result != null)
1072 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 synchronized (request) {
1074 request.notifyAll();
1075 }
1076 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 case CMD_REQUEST_CELL_INFO_UPDATE:
1078 request = (MainThreadRequest) msg.obj;
1079 request.phone.requestCellInfoUpdate(request.workSource,
1080 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1081 break;
1082 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
1085 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1086 try {
1087 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001089 cb.onError(
1090 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1091 ar.exception.getClass().getName(),
1092 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001095 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 } else {
1097 // use the result as returned
1098 cb.onCellInfo((List<CellInfo>) ar.result);
1099 }
1100 } catch (RemoteException re) {
1101 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1102 }
1103 break;
1104 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001105 request = (MainThreadRequest) msg.obj;
1106 WorkSource ws = (WorkSource) request.argument;
1107 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001108 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001109 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001110 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
1113 if (ar.exception == null) {
1114 request.result = ar.result;
1115 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001116 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001117 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001118 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001119 }
1120
1121 synchronized (request) {
1122 request.notifyAll();
1123 }
1124 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001125 case CMD_MODEM_REBOOT:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001128 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001129 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001130 case EVENT_CMD_MODEM_REBOOT_DONE:
1131 handleNullReturnEvent(msg, "rebootModem");
1132 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001133 case CMD_REQUEST_ENABLE_MODEM:
1134 request = (MainThreadRequest) msg.obj;
1135 boolean enable = (boolean) request.argument;
1136 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001137 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001138 PhoneConfigurationManager.getInstance()
1139 .enablePhone(request.phone, enable, onCompleted);
1140 break;
1141 case EVENT_ENABLE_MODEM_DONE:
1142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001145 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001146 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001147 if ((boolean) request.result) {
1148 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1149 updateModemStateMetrics();
1150 } else {
1151 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1152 + ar.exception);
1153 }
1154 notifyRequester(request);
1155 break;
1156 case CMD_GET_MODEM_STATUS:
1157 request = (MainThreadRequest) msg.obj;
1158 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1159 PhoneConfigurationManager.getInstance()
1160 .getPhoneStatusFromModem(request.phone, onCompleted);
1161 break;
1162 case EVENT_GET_MODEM_STATUS_DONE:
1163 ar = (AsyncResult) msg.obj;
1164 request = (MainThreadRequest) ar.userObj;
1165 int id = request.phone.getPhoneId();
1166 if (ar.exception == null && ar.result != null) {
1167 request.result = ar.result;
1168 //update the cache as modem status has changed
1169 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1170 (boolean) request.result);
1171 } else {
1172 // Return true if modem status cannot be retrieved. For most cases,
1173 // modem status is on. And for older version modems, GET_MODEM_STATUS
1174 // and disable modem are not supported. Modem is always on.
1175 // TODO: this should be fixed in R to support a third
1176 // status UNKNOWN b/131631629
1177 request.result = true;
1178 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1179 + ar.exception);
1180 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001181 notifyRequester(request);
1182 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001183 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 if (ar.exception == null && ar.result != null) {
1187 request.result = ar.result;
1188 } else {
1189 request.result = -1;
1190 loge("Failed to set Forbidden Plmns");
1191 if (ar.result == null) {
1192 loge("setForbidenPlmns: Empty response");
1193 } else if (ar.exception != null) {
1194 loge("setForbiddenPlmns: Exception: " + ar.exception);
1195 request.result = -1;
1196 } else {
1197 loge("setForbiddenPlmns: Unknown exception");
1198 }
1199 }
1200 notifyRequester(request);
1201 break;
1202 case CMD_SET_FORBIDDEN_PLMNS:
1203 request = (MainThreadRequest) msg.obj;
1204 uiccCard = getUiccCardFromRequest(request);
1205 if (uiccCard == null) {
1206 loge("setForbiddenPlmns: UiccCard is null");
1207 request.result = -1;
1208 notifyRequester(request);
1209 break;
1210 }
1211 Pair<Integer, List<String>> setFplmnsArgs =
1212 (Pair<Integer, List<String>>) request.argument;
1213 appType = setFplmnsArgs.first;
1214 List<String> fplmns = setFplmnsArgs.second;
1215 uiccApp = uiccCard.getApplicationByType(appType);
1216 if (uiccApp == null) {
1217 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1218 request.result = -1;
1219 loge("Failed to get UICC App");
1220 notifyRequester(request);
1221 } else {
1222 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1223 ((SIMRecords) uiccApp.getIccRecords())
1224 .setForbiddenPlmns(onCompleted, fplmns);
1225 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001226 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001227 case CMD_ERASE_MODEM_CONFIG:
1228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1230 defaultPhone.eraseModemConfig(onCompleted);
1231 break;
1232 case EVENT_ERASE_MODEM_CONFIG_DONE:
1233 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001234 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 default:
1236 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1237 break;
1238 }
1239 }
Jake Hambye994d462014-02-03 13:10:13 -08001240
Pengquan Menga1bb6272018-09-06 09:59:22 -07001241 private void notifyRequester(MainThreadRequest request) {
1242 synchronized (request) {
1243 request.notifyAll();
1244 }
1245 }
1246
Jake Hambye994d462014-02-03 13:10:13 -08001247 private void handleNullReturnEvent(Message msg, String command) {
1248 AsyncResult ar = (AsyncResult) msg.obj;
1249 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1250 if (ar.exception == null) {
1251 request.result = true;
1252 } else {
1253 request.result = false;
1254 if (ar.exception instanceof CommandException) {
1255 loge(command + ": CommandException: " + ar.exception);
1256 } else {
1257 loge(command + ": Unknown exception");
1258 }
1259 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001260 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 }
1263
1264 /**
1265 * Posts the specified command to be executed on the main thread,
1266 * waits for the request to complete, and returns the result.
1267 * @see #sendRequestAsync
1268 */
1269 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001270 return sendRequest(
1271 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001272 }
1273
1274 /**
1275 * Posts the specified command to be executed on the main thread,
1276 * waits for the request to complete, and returns the result.
1277 * @see #sendRequestAsync
1278 */
1279 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1280 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001281 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
1284 /**
1285 * Posts the specified command to be executed on the main thread,
1286 * waits for the request to complete, and returns the result.
1287 * @see #sendRequestAsync
1288 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001289 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001290 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001291 }
1292
1293 /**
1294 * Posts the specified command to be executed on the main thread,
1295 * waits for the request to complete, and returns the result.
1296 * @see #sendRequestAsync
1297 */
Nathan Harold92bed182018-10-12 18:16:49 -07001298 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1299 return sendRequest(command, argument, subId, null, workSource);
1300 }
1301
1302 /**
1303 * Posts the specified command to be executed on the main thread,
1304 * waits for the request to complete, and returns the result.
1305 * @see #sendRequestAsync
1306 */
1307 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1308 return sendRequest(
1309 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1310 }
1311
1312 /**
1313 * Posts the specified command to be executed on the main thread,
1314 * waits for the request to complete, and returns the result.
1315 * @see #sendRequestAsync
1316 */
1317 private Object sendRequest(
1318 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1320 throw new RuntimeException("This method will deadlock if called from the main thread.");
1321 }
1322
Nathan Harold92bed182018-10-12 18:16:49 -07001323 MainThreadRequest request = null;
1324 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1325 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1326 } else if (phone != null) {
1327 request = new MainThreadRequest(argument, phone, workSource);
1328 } else {
1329 request = new MainThreadRequest(argument, subId, workSource);
1330 }
1331
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 Message msg = mMainThreadHandler.obtainMessage(command, request);
1333 msg.sendToTarget();
1334
1335 // Wait for the request to complete
1336 synchronized (request) {
1337 while (request.result == null) {
1338 try {
1339 request.wait();
1340 } catch (InterruptedException e) {
1341 // Do nothing, go back and wait until the request is complete
1342 }
1343 }
1344 }
1345 return request.result;
1346 }
1347
1348 /**
1349 * Asynchronous ("fire and forget") version of sendRequest():
1350 * Posts the specified command to be executed on the main thread, and
1351 * returns immediately.
1352 * @see #sendRequest
1353 */
1354 private void sendRequestAsync(int command) {
1355 mMainThreadHandler.sendEmptyMessage(command);
1356 }
1357
1358 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001359 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001360 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001361 */
1362 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001363 sendRequestAsync(command, argument, null, null);
1364 }
1365
1366 /**
1367 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1368 * @see {@link #sendRequest(int,Object)}
1369 */
1370 private void sendRequestAsync(
1371 int command, Object argument, Phone phone, WorkSource workSource) {
1372 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001373 Message msg = mMainThreadHandler.obtainMessage(command, request);
1374 msg.sendToTarget();
1375 }
1376
1377 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 * Initialize the singleton PhoneInterfaceManager instance.
1379 * This is only done once, at startup, from PhoneApp.onCreate().
1380 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 synchronized (PhoneInterfaceManager.class) {
1383 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001384 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 } else {
1386 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1387 }
1388 return sInstance;
1389 }
1390 }
1391
1392 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001393 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001396 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001397 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001398 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1399 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001400 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001401 mTelephonySharedPreferences =
1402 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001403 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001404 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 publish();
1407 }
1408
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001409 private Phone getDefaultPhone() {
1410 Phone thePhone = getPhone(getDefaultSubscription());
1411 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1412 }
1413
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414 private void publish() {
1415 if (DBG) log("publish: " + this);
1416
Peter Wangc035ce42020-01-08 21:00:22 -08001417 TelephonyFrameworkInitializer
1418 .getTelephonyServiceManager()
1419 .getTelephonyServiceRegisterer()
1420 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421 }
1422
Stuart Scott584921c2015-01-15 17:10:34 -08001423 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001424 if (request.phone != null) {
1425 return request.phone;
1426 } else {
1427 return getPhoneFromSubId(request.subId);
1428 }
1429 }
1430
1431 private Phone getPhoneFromSubId(int subId) {
1432 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1433 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001434 }
1435
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001436 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1437 Phone phone = getPhoneFromRequest(request);
1438 return phone == null ? null :
1439 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1440 }
1441
Wink Saville36469e72014-06-11 15:17:00 -07001442 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001443 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001444 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446
Naina Nallurid63128d2019-09-17 14:10:30 -07001447 private void sendEraseModemConfig(Phone phone) {
1448 if (phone != null) {
1449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1450 mApp, phone.getSubId(), "eraseModemConfig");
1451 final long identity = Binder.clearCallingIdentity();
1452 try {
1453 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1454 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1455 } finally {
1456 Binder.restoreCallingIdentity(identity);
1457 }
1458 }
1459 }
1460
Peter Wang44b186e2020-01-13 23:33:09 -08001461 private boolean isImsAvailableOnDevice() {
1462 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1463 if (pm == null) {
1464 // For some reason package manger is not available.. This will fail internally anyway,
1465 // so do not throw error and allow.
1466 return true;
1467 }
1468 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1469 }
1470
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001472 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001473 }
1474
Wink Savilleb564aae2014-10-23 10:18:09 -07001475 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476 if (DBG) log("dial: " + number);
1477 // No permission check needed here: This is just a wrapper around the
1478 // ACTION_DIAL intent, which is available to any app since it puts up
1479 // the UI before it does anything.
1480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001481 final long identity = Binder.clearCallingIdentity();
1482 try {
1483 String url = createTelUrl(number);
1484 if (url == null) {
1485 return;
1486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001488 // PENDING: should we just silently fail if phone is offhook or ringing?
1489 PhoneConstants.State state = mCM.getState(subId);
1490 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1491 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1492 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1493 mApp.startActivity(intent);
1494 }
1495 } finally {
1496 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 }
1498 }
1499
1500 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001501 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001502 }
1503
Wink Savilleb564aae2014-10-23 10:18:09 -07001504 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 if (DBG) log("call: " + number);
1506
1507 // This is just a wrapper around the ACTION_CALL intent, but we still
1508 // need to do a permission check since we're calling startActivity()
1509 // from the context of the phone app.
1510 enforceCallPermission();
1511
Jordan Liu1617b712019-07-10 15:06:26 -07001512 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513 != AppOpsManager.MODE_ALLOWED) {
1514 return;
1515 }
1516
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001517 final long identity = Binder.clearCallingIdentity();
1518 try {
1519 String url = createTelUrl(number);
1520 if (url == null) {
1521 return;
1522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001524 boolean isValid = false;
1525 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1526 if (slist != null) {
1527 for (SubscriptionInfo subInfoRecord : slist) {
1528 if (subInfoRecord.getSubscriptionId() == subId) {
1529 isValid = true;
1530 break;
1531 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001532 }
Wink Saville08874612014-08-31 19:19:58 -07001533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001534 if (!isValid) {
1535 return;
1536 }
Wink Saville08874612014-08-31 19:19:58 -07001537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001538 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1539 intent.putExtra(SUBSCRIPTION_KEY, subId);
1540 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1541 mApp.startActivity(intent);
1542 } finally {
1543 Binder.restoreCallingIdentity(identity);
1544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 }
1546
Wink Savilleb564aae2014-10-23 10:18:09 -07001547 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001548 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001549 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1550 }
1551
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001553 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001554 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1555 }
1556
Wink Savilleb564aae2014-10-23 10:18:09 -07001557 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001559
1560 final long identity = Binder.clearCallingIdentity();
1561 try {
1562 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1563 checkSimPin.start();
1564 return checkSimPin.unlockSim(null, pin);
1565 } finally {
1566 Binder.restoreCallingIdentity(identity);
1567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 }
1569
Wink Savilleb564aae2014-10-23 10:18:09 -07001570 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001572
1573 final long identity = Binder.clearCallingIdentity();
1574 try {
1575 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1576 checkSimPuk.start();
1577 return checkSimPuk.unlockSim(puk, pin);
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
1580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 }
1582
1583 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001584 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 * a synchronous one.
1586 */
1587 private static class UnlockSim extends Thread {
1588
1589 private final IccCard mSimCard;
1590
1591 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001592 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1593 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594
1595 // For replies from SimCard interface
1596 private Handler mHandler;
1597
1598 // For async handler to identify request type
1599 private static final int SUPPLY_PIN_COMPLETE = 100;
1600
1601 public UnlockSim(IccCard simCard) {
1602 mSimCard = simCard;
1603 }
1604
1605 @Override
1606 public void run() {
1607 Looper.prepare();
1608 synchronized (UnlockSim.this) {
1609 mHandler = new Handler() {
1610 @Override
1611 public void handleMessage(Message msg) {
1612 AsyncResult ar = (AsyncResult) msg.obj;
1613 switch (msg.what) {
1614 case SUPPLY_PIN_COMPLETE:
1615 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1616 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001617 mRetryCount = msg.arg1;
1618 if (ar.exception != null) {
1619 if (ar.exception instanceof CommandException &&
1620 ((CommandException)(ar.exception)).getCommandError()
1621 == CommandException.Error.PASSWORD_INCORRECT) {
1622 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1623 } else {
1624 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1625 }
1626 } else {
1627 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 mDone = true;
1630 UnlockSim.this.notifyAll();
1631 }
1632 break;
1633 }
1634 }
1635 };
1636 UnlockSim.this.notifyAll();
1637 }
1638 Looper.loop();
1639 }
1640
1641 /*
1642 * Use PIN or PUK to unlock SIM card
1643 *
1644 * If PUK is null, unlock SIM card with PIN
1645 *
1646 * If PUK is not null, unlock SIM card with PUK and set PIN code
1647 */
Wink Saville9de0f752013-10-22 19:04:03 -07001648 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649
1650 while (mHandler == null) {
1651 try {
1652 wait();
1653 } catch (InterruptedException e) {
1654 Thread.currentThread().interrupt();
1655 }
1656 }
1657 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1658
1659 if (puk == null) {
1660 mSimCard.supplyPin(pin, callback);
1661 } else {
1662 mSimCard.supplyPuk(puk, pin, callback);
1663 }
1664
1665 while (!mDone) {
1666 try {
1667 Log.d(LOG_TAG, "wait for done");
1668 wait();
1669 } catch (InterruptedException e) {
1670 // Restore the interrupted status
1671 Thread.currentThread().interrupt();
1672 }
1673 }
1674 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001675 int[] resultArray = new int[2];
1676 resultArray[0] = mResult;
1677 resultArray[1] = mRetryCount;
1678 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 }
1680 }
1681
1682 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001683 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001684
1685 }
1686
Wink Savilleb564aae2014-10-23 10:18:09 -07001687 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 // No permission check needed here: this call is harmless, and it's
1689 // needed for the ServiceState.requestStateUpdate() call (which is
1690 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001691 final long identity = Binder.clearCallingIdentity();
1692 try {
1693 final Phone phone = getPhone(subId);
1694 if (phone != null) {
1695 phone.updateServiceLocation();
1696 }
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 }
1701
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001702 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001703 @Override
1704 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001705 return isRadioOnWithFeature(callingPackage, null);
1706 }
1707
1708
1709 @Override
1710 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1711 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1712 callingFeatureId);
1713 }
1714
1715 @Deprecated
1716 @Override
1717 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1718 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001719 }
1720
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001721 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001722 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1723 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001725 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001726 return false;
1727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728
1729 final long identity = Binder.clearCallingIdentity();
1730 try {
1731 return isRadioOnForSubscriber(subId);
1732 } finally {
1733 Binder.restoreCallingIdentity(identity);
1734 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001735 }
1736
1737 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 final Phone phone = getPhone(subId);
1741 if (phone != null) {
1742 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1743 } else {
1744 return false;
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
1750
1751 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001752 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 }
Wink Saville36469e72014-06-11 15:17:00 -07001754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
1762 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1763 }
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 }
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
1768
1769 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001770 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001771 }
1772
Wink Savilleb564aae2014-10-23 10:18:09 -07001773 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 final Phone phone = getPhone(subId);
1779 if (phone == null) {
1780 return false;
1781 }
1782 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1783 toggleRadioOnOffForSubscriber(subId);
1784 }
1785 return true;
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
Wink Saville36469e72014-06-11 15:17:00 -07001790
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001791 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001792 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 /*
1794 * If any of the Radios are available, it will need to be
1795 * shutdown. So return true if any Radio is available.
1796 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1800 Phone phone = PhoneFactory.getPhone(i);
1801 if (phone != null && phone.isRadioAvailable()) return true;
1802 }
1803 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1804 return false;
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001808 }
1809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001810 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 enforceModifyPermission();
1813
1814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1817 logv("Shutting down Phone " + i);
1818 shutdownRadioUsingPhoneId(i);
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001822 }
1823 }
1824
1825 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001826 Phone phone = PhoneFactory.getPhone(phoneId);
1827 if (phone != null && phone.isRadioAvailable()) {
1828 phone.shutdownRadio();
1829 }
1830 }
1831
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1838 if (defaultPhone != null) {
1839 defaultPhone.setRadioPower(turnOn);
1840 return true;
1841 } else {
1842 loge("There's no default phone.");
1843 return false;
1844 }
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001847 }
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
Wink Savilleb564aae2014-10-23 10:18:09 -07001850 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852
1853 final long identity = Binder.clearCallingIdentity();
1854 try {
1855 final Phone phone = getPhone(subId);
1856 if (phone != null) {
1857 phone.setRadioPower(turnOn);
1858 return true;
1859 } else {
1860 return false;
1861 }
1862 } finally {
1863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001865 }
1866
Wink Saville36469e72014-06-11 15:17:00 -07001867 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 public boolean enableDataConnectivity() {
1870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001871
1872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 int subId = mSubscriptionController.getDefaultDataSubId();
1875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001877 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878 return true;
1879 } else {
1880 return false;
1881 }
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
Wink Saville36469e72014-06-11 15:17:00 -07001887 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 public boolean disableDataConnectivity() {
1890 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891
1892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 int subId = mSubscriptionController.getDefaultDataSubId();
1895 final Phone phone = getPhone(subId);
1896 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001897 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898 return true;
1899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001908 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 final long identity = Binder.clearCallingIdentity();
1910 try {
1911 final Phone phone = getPhone(subId);
1912 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001913 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 } else {
1915 return false;
1916 }
1917 } finally {
1918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
1922 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001923 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001924 }
1925
pkanwarae03a6b2016-11-06 20:37:09 -08001926 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927 enforceCallPermission();
1928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1932 return;
1933 }
1934 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1935 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1936 } finally {
1937 Binder.restoreCallingIdentity(identity);
1938 }
pkanwar32d516d2016-10-14 19:37:38 -07001939 };
1940
Wink Savilleb564aae2014-10-23 10:18:09 -07001941 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001943
1944 final long identity = Binder.clearCallingIdentity();
1945 try {
1946 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1947 return false;
1948 }
1949 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001956 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001959 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001960 final long identity = Binder.clearCallingIdentity();
1961 try {
1962 Phone phone = PhoneFactory.getPhone(slotIndex);
1963 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1964 PhoneConstantConversions.convertCallState(phone.getState());
1965 } finally {
1966 Binder.restoreCallingIdentity(identity);
1967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001971 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001972 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1973 }
1974
1975 @Override
1976 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001977 final long identity = Binder.clearCallingIdentity();
1978 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001979 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 if (phone != null) {
1981 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1982 } else {
1983 return PhoneConstantConversions.convertDataState(
1984 PhoneConstants.DataState.DISCONNECTED);
1985 }
1986 } finally {
1987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001992 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001993 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1994 }
1995
1996 @Override
1997 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998 final long identity = Binder.clearCallingIdentity();
1999 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002000 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001 if (phone != null) {
2002 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2003 } else {
2004 return TelephonyManager.DATA_ACTIVITY_NONE;
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
2011 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002012 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002013 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002014 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002015
2016 LocationAccessPolicy.LocationPermissionResult locationResult =
2017 LocationAccessPolicy.checkLocationPermission(mApp,
2018 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2019 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002020 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002021 .setCallingPid(Binder.getCallingPid())
2022 .setCallingUid(Binder.getCallingUid())
2023 .setMethod("getCellLocation")
2024 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2025 .build());
2026 switch (locationResult) {
2027 case DENIED_HARD:
2028 throw new SecurityException("Not allowed to access cell location");
2029 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002030 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2031 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 }
2033
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002034 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002035 final long identity = Binder.clearCallingIdentity();
2036 try {
2037 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002038 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002039 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 } finally {
2041 Binder.restoreCallingIdentity(identity);
2042 }
Svetoslav64fad262015-04-14 14:35:21 -07002043 }
2044
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002046 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2047 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002048 if (!TextUtils.isEmpty(callingPackage)) {
2049 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2051 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002052 return "";
2053 }
2054 }
2055
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002056 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2057 // registered cell info, so return a NULL country instead.
2058 final long identity = Binder.clearCallingIdentity();
2059 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002060 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2061 // Get default phone in this case.
2062 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2063 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002064 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002065 // Todo: fix this when we can get the actual cellular network info when the device
2066 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002067 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002068 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2069 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002070 return "";
2071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 Phone phone = PhoneFactory.getPhone(phoneId);
2073 if (phone != null) {
2074 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002075 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076 if (sst != null) {
2077 LocaleTracker lt = sst.getLocaleTracker();
2078 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002079 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2080 return lt.getCurrentCountry();
2081 } else if (emergencyNumberTracker != null) {
2082 return emergencyNumberTracker.getEmergencyCountryIso();
2083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002084 }
2085 }
2086 }
2087 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002088 } finally {
2089 Binder.restoreCallingIdentity(identity);
2090 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002091 }
2092
2093 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002095 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002096 }
2097
Sanket Padawe356d7632015-06-22 14:03:32 -07002098 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002099 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 mApp.enforceCallingOrSelfPermission(
2101 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102
2103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
2107 phone.enableLocationUpdates();
2108 }
2109 } finally {
2110 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
2114 @Override
2115 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002116 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002117 }
2118
Sanket Padawe356d7632015-06-22 14:03:32 -07002119 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002120 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 mApp.enforceCallingOrSelfPermission(
2122 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002123
2124 final long identity = Binder.clearCallingIdentity();
2125 try {
2126 final Phone phone = getPhone(subId);
2127 if (phone != null) {
2128 phone.disableLocationUpdates();
2129 }
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 }
2134
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 /**
2136 * Returns the target SDK version number for a given package name.
2137 *
Nathan Haroldec184742019-07-10 17:04:16 -07002138 * This call MUST be invoked before clearing the calling UID.
2139 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002140 * @return target SDK if the package is found or INT_MAX.
2141 */
2142 private int getTargetSdk(String packageName) {
2143 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002144 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002145 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002146 if (ai != null) return ai.targetSdkVersion;
2147 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002148 loge("Failed to get package info for pkg="
2149 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002150 }
2151 return Integer.MAX_VALUE;
2152 }
2153
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 @Override
2155 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002156 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2157 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002158 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002159 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2160 throw new SecurityException(
2161 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2162 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002163
Jordan Liu1617b712019-07-10 15:06:26 -07002164 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2166 return null;
2167 }
Svetoslav64fad262015-04-14 14:35:21 -07002168
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002169 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002171 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002172 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173
Nathan Haroldf180aac2018-06-01 18:43:55 -07002174 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2175 for (CellInfo ci : info) {
2176 if (ci instanceof CellInfoGsm) {
2177 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2178 } else if (ci instanceof CellInfoWcdma) {
2179 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002182 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
2184
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002185 private List<CellInfo> getCachedCellInfo() {
2186 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2187 for (Phone phone : PhoneFactory.getPhones()) {
2188 List<CellInfo> info = phone.getAllCellInfo();
2189 if (info != null) cellInfos.addAll(info);
2190 }
2191 return cellInfos;
2192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193
2194 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002195 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002196 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002197 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002198
2199 LocationAccessPolicy.LocationPermissionResult locationResult =
2200 LocationAccessPolicy.checkLocationPermission(mApp,
2201 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2202 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002203 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002204 .setCallingPid(Binder.getCallingPid())
2205 .setCallingUid(Binder.getCallingUid())
2206 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002207 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002208 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2209 .build());
2210 switch (locationResult) {
2211 case DENIED_HARD:
2212 throw new SecurityException("Not allowed to access cell info");
2213 case DENIED_SOFT:
2214 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002217 final int targetSdk = getTargetSdk(callingPackage);
2218 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2219 return getCachedCellInfo();
2220 }
2221
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002222 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002223 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2227 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002228 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002229 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230 if (info != null) cellInfos.addAll(info);
2231 }
2232 return cellInfos;
2233 } finally {
2234 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 }
2236 }
2237
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002238 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002239 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2240 String callingFeatureId) {
2241 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2242 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 }
2244
2245 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002246 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2247 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002248 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002249 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002250 }
2251
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002252 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2253 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002254 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002255 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002256
2257 LocationAccessPolicy.LocationPermissionResult locationResult =
2258 LocationAccessPolicy.checkLocationPermission(mApp,
2259 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2260 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002261 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002262 .setCallingPid(Binder.getCallingPid())
2263 .setCallingUid(Binder.getCallingUid())
2264 .setMethod("requestCellInfoUpdate")
2265 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2266 .build());
2267 switch (locationResult) {
2268 case DENIED_HARD:
2269 throw new SecurityException("Not allowed to access cell info");
2270 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002271 try {
2272 cb.onCellInfo(new ArrayList<CellInfo>());
2273 } catch (RemoteException re) {
2274 // Drop without consequences
2275 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002276 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002277 }
2278
Nathan Harolda939a962019-05-09 10:13:47 -07002279
2280 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002281 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2282
2283 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2284 }
2285
2286 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002288 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002289 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002293 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294 } finally {
2295 Binder.restoreCallingIdentity(identity);
2296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
Shishir Agrawala9f32182016-04-12 12:00:16 -07002299 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002300 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002301 Phone phone = PhoneFactory.getPhone(slotIndex);
2302 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002303 return null;
2304 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002305 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002306 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002307 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002308 return null;
2309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002310
2311 final long identity = Binder.clearCallingIdentity();
2312 try {
2313 return phone.getImei();
2314 } finally {
2315 Binder.restoreCallingIdentity(identity);
2316 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002317 }
2318
2319 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002320 public String getTypeAllocationCodeForSlot(int slotIndex) {
2321 Phone phone = PhoneFactory.getPhone(slotIndex);
2322 String tac = null;
2323 if (phone != null) {
2324 String imei = phone.getImei();
2325 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2326 }
2327 return tac;
2328 }
2329
2330 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002331 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002332 Phone phone = PhoneFactory.getPhone(slotIndex);
2333 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002334 return null;
2335 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002336
Jeff Davidson913390f2018-02-23 17:11:49 -08002337 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002338 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002339 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002340 return null;
2341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 return phone.getMeid();
2346 } finally {
2347 Binder.restoreCallingIdentity(identity);
2348 }
Jack Yu2af8d712017-03-15 17:14:14 -07002349 }
2350
2351 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002352 public String getManufacturerCodeForSlot(int slotIndex) {
2353 Phone phone = PhoneFactory.getPhone(slotIndex);
2354 String manufacturerCode = null;
2355 if (phone != null) {
2356 String meid = phone.getMeid();
2357 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2358 }
2359 return manufacturerCode;
2360 }
2361
2362 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002363 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2364 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002365 Phone phone = PhoneFactory.getPhone(slotIndex);
2366 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002367 return null;
2368 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002369 int subId = phone.getSubId();
2370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002371 mApp, subId, callingPackage, callingFeatureId,
2372 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002373 return null;
2374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375
2376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 return phone.getDeviceSvn();
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
2381 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002382 }
2383
fionaxu43304da2017-11-27 22:51:16 -08002384 @Override
2385 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002386 final long identity = Binder.clearCallingIdentity();
2387 try {
2388 final Phone phone = getPhone(subId);
2389 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
2392 }
fionaxu43304da2017-11-27 22:51:16 -08002393 }
2394
2395 @Override
2396 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 final Phone phone = getPhone(subId);
2400 return phone == null ? null : phone.getCarrierName();
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
fionaxu43304da2017-11-27 22:51:16 -08002404 }
2405
calvinpanffe225e2018-11-01 19:43:06 +08002406 @Override
chen xu0026ca62019-03-06 15:28:50 -08002407 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 final Phone phone = getPhone(subId);
2411 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002412 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
2416 }
2417
2418 @Override
chen xu0026ca62019-03-06 15:28:50 -08002419 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002420 final long identity = Binder.clearCallingIdentity();
2421 try {
2422 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002423 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
2427 }
2428
chen xu651eec72018-11-11 19:03:44 -08002429 @Override
chen xu864e11c2018-12-06 22:10:03 -08002430 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2431 if (!isSubscriptionMccMnc) {
2432 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2433 }
chen xu651eec72018-11-11 19:03:44 -08002434 final Phone phone = PhoneFactory.getPhone(slotIndex);
2435 if (phone == null) {
2436 return TelephonyManager.UNKNOWN_CARRIER_ID;
2437 }
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
2443 }
2444 }
2445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 //
2447 // Internal helper methods.
2448 //
2449
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002450 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2452 *
2453 * @throws SecurityException if the caller does not have the required permission
2454 */
2455 private void enforceModifyPermission() {
2456 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2457 }
2458
Shuo Qiancd19c462020-01-16 20:51:11 -08002459 /**
2460 * Make sure the caller is system.
2461 *
2462 * @throws SecurityException if the caller is not system.
2463 */
2464 private void enforceSystemCaller() {
2465 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2466 throw new SecurityException("Caller must be system");
2467 }
2468 }
2469
Shuo Qian3b6ee772019-11-13 17:43:31 -08002470 private void enforceActiveEmergencySessionPermission() {
2471 mApp.enforceCallingOrSelfPermission(
2472 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2473 }
2474
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 /**
2476 * Make sure the caller has the CALL_PHONE permission.
2477 *
2478 * @throws SecurityException if the caller does not have the required permission
2479 */
2480 private void enforceCallPermission() {
2481 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2482 }
2483
paulhu5a773602019-08-23 19:17:33 +08002484 private void enforceSettingsPermission() {
2485 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002486 }
2487
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 private String createTelUrl(String number) {
2489 if (TextUtils.isEmpty(number)) {
2490 return null;
2491 }
2492
Jake Hambye994d462014-02-03 13:10:13 -08002493 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 }
2495
Ihab Awadf9e92732013-12-05 18:02:52 -08002496 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2498 }
2499
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002500 private static void logv(String msg) {
2501 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2502 }
2503
Ihab Awadf9e92732013-12-05 18:02:52 -08002504 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2506 }
2507
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002508 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002510 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002511 }
2512
Sanket Padawe356d7632015-06-22 14:03:32 -07002513 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002514 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002515 final long identity = Binder.clearCallingIdentity();
2516 try {
2517 final Phone phone = PhoneFactory.getPhone(slotIndex);
2518 if (phone == null) {
2519 return PhoneConstants.PHONE_TYPE_NONE;
2520 } else {
2521 return phone.getPhoneType();
2522 }
2523 } finally {
2524 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 }
2527
2528 /**
2529 * Returns the CDMA ERI icon index to display
2530 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002532 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2533 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2534 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002535 }
2536
Sanket Padawe356d7632015-06-22 14:03:32 -07002537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002538 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2539 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002541 mApp, subId, callingPackage, callingFeatureId,
2542 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002543 return -1;
2544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545
2546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 final Phone phone = getPhone(subId);
2549 if (phone != null) {
2550 return phone.getCdmaEriIconIndex();
2551 } else {
2552 return -1;
2553 }
2554 } finally {
2555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 }
2558
2559 /**
2560 * Returns the CDMA ERI icon mode,
2561 * 0 - ON
2562 * 1 - FLASHING
2563 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002564 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002565 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2566 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2567 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002568 }
2569
Sanket Padawe356d7632015-06-22 14:03:32 -07002570 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002571 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2572 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002574 mApp, subId, callingPackage, callingFeatureId,
2575 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002576 return -1;
2577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 final Phone phone = getPhone(subId);
2582 if (phone != null) {
2583 return phone.getCdmaEriIconMode();
2584 } else {
2585 return -1;
2586 }
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 }
2591
2592 /**
2593 * Returns the CDMA ERI text,
2594 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002595 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002596 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2597 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2598 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002599 }
2600
Sanket Padawe356d7632015-06-22 14:03:32 -07002601 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002602 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2603 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002605 mApp, subId, callingPackage, callingFeatureId,
2606 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002607 return null;
2608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609
2610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 final Phone phone = getPhone(subId);
2613 if (phone != null) {
2614 return phone.getCdmaEriText();
2615 } else {
2616 return null;
2617 }
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 }
2622
2623 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002624 * Returns the CDMA MDN.
2625 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002626 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002627 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2629 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630
2631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002634 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635 return phone.getLine1Number();
2636 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002637 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 return null;
2639 }
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002642 }
2643 }
2644
2645 /**
2646 * Returns the CDMA MIN.
2647 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002648 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002649 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2651 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652
2653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 final Phone phone = getPhone(subId);
2656 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2657 return phone.getCdmaMin();
2658 } else {
2659 return null;
2660 }
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002663 }
2664 }
2665
Hall Liud892bec2018-11-30 14:51:45 -08002666 @Override
2667 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2668 INumberVerificationCallback callback, String callingPackage) {
2669 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2670 != PERMISSION_GRANTED) {
2671 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2672 }
2673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2674
2675 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2676 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2677 throw new SecurityException("Calling package must be configured in the device config");
2678 }
2679
2680 if (range == null) {
2681 throw new NullPointerException("Range must be non-null");
2682 }
2683
2684 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002685 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002686
2687 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2688 }
2689
Junda Liuca05d5d2014-08-14 22:36:34 -07002690 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 * Returns true if CDMA provisioning needs to run.
2692 */
2693 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694 final long identity = Binder.clearCallingIdentity();
2695 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002696 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 } finally {
2698 Binder.restoreCallingIdentity(identity);
2699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 }
2701
2702 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002703 * Sets the voice mail number of a given subId.
2704 */
2705 @Override
2706 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002707 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2708 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709
2710 final long identity = Binder.clearCallingIdentity();
2711 try {
2712 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2713 new Pair<String, String>(alphaTag, number), new Integer(subId));
2714 return success;
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
2717 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002718 }
2719
Ta-wei Yen87c49842016-05-13 21:19:52 -07002720 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002721 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002723 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2724 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002725 if (!TextUtils.equals(callingPackage, systemDialer)) {
2726 throw new SecurityException("caller must be system dialer");
2727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002728
2729 final long identity = Binder.clearCallingIdentity();
2730 try {
2731 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2732 if (phoneAccountHandle == null) {
2733 return null;
2734 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002735 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 } finally {
2737 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002738 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002739 }
2740
2741 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002742 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2743 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002744 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002746 mApp, subId, callingPackage, callingFeatureId,
2747 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002748 return null;
2749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002751 final long identity = Binder.clearCallingIdentity();
2752 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002753 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002757 }
2758
2759 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002760 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2761 VisualVoicemailSmsFilterSettings settings) {
2762 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002767 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768 } finally {
2769 Binder.restoreCallingIdentity(identity);
2770 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002771 }
2772
2773 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002774 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776
2777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002780 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781 } finally {
2782 Binder.restoreCallingIdentity(identity);
2783 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002784 }
2785
2786 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002787 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2788 String callingPackage, int subId) {
2789 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790
2791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002794 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 } finally {
2796 Binder.restoreCallingIdentity(identity);
2797 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002798 }
2799
2800 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002801 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002802 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002807 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 } finally {
2809 Binder.restoreCallingIdentity(identity);
2810 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002811 }
2812
2813 @Override
2814 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2815 String number, int port, String text, PendingIntent sentIntent) {
2816 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002817 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002818 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002819 SmsController smsController = PhoneFactory.getSmsController();
2820 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2821 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002822 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002823
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002824 /**
fionaxu0152e512016-11-14 13:36:14 -08002825 * Sets the voice activation state of a given subId.
2826 */
2827 @Override
2828 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2830 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831
2832 final long identity = Binder.clearCallingIdentity();
2833 try {
2834 final Phone phone = getPhone(subId);
2835 if (phone != null) {
2836 phone.setVoiceActivationState(activationState);
2837 } else {
2838 loge("setVoiceActivationState fails with invalid subId: " + subId);
2839 }
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002842 }
2843 }
2844
2845 /**
2846 * Sets the data activation state of a given subId.
2847 */
2848 @Override
2849 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2851 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 final Phone phone = getPhone(subId);
2856 if (phone != null) {
2857 phone.setDataActivationState(activationState);
2858 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002859 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860 }
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002863 }
2864 }
2865
2866 /**
2867 * Returns the voice activation state of a given subId.
2868 */
2869 @Override
2870 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002871 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
fionaxu0152e512016-11-14 13:36:14 -08002873 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 if (phone != null) {
2877 return phone.getVoiceActivationState();
2878 } else {
2879 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2880 }
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002883 }
2884 }
2885
2886 /**
2887 * Returns the data activation state of a given subId.
2888 */
2889 @Override
2890 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002891 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892
fionaxu0152e512016-11-14 13:36:14 -08002893 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 if (phone != null) {
2897 return phone.getDataActivationState();
2898 } else {
2899 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2900 }
2901 } finally {
2902 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002903 }
2904 }
2905
2906 /**
Wink Saville36469e72014-06-11 15:17:00 -07002907 * Returns the unread count of voicemails for a subId
2908 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002910 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2911 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002913 mApp, subId, callingPackage, callingFeatureId,
2914 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002915 return 0;
2916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 final Phone phone = getPhone(subId);
2920 if (phone != null) {
2921 return phone.getVoiceMessageCount();
2922 } else {
2923 return 0;
2924 }
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 }
2929
2930 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002931 * returns true, if the device is in a state where both voice and data
2932 * are supported simultaneously. This can change based on location or network condition.
2933 */
2934 @Override
2935 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 final Phone phone = getPhone(subId);
2939 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002943 }
2944
2945 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002946 * Send the dialer code if called from the current default dialer or the caller has
2947 * carrier privilege.
2948 * @param inputCode The dialer code to send
2949 */
2950 @Override
2951 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002952 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002953 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002954 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2955 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002956 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002957 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002958 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960
2961 final long identity = Binder.clearCallingIdentity();
2962 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002963 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
fionaxu235cc5e2017-03-06 22:25:57 -08002967 }
2968
Pengquan Menga1bb6272018-09-06 09:59:22 -07002969 @Override
2970 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002971 if (!isActiveSubscription(subId)) {
2972 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2973 }
2974
Pengquan Menga1bb6272018-09-06 09:59:22 -07002975 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2976 }
2977
Brad Ebinger35c841c2018-10-01 10:40:55 -07002978 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002979 public boolean isInEmergencySmsMode() {
2980 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 for (Phone phone : PhoneFactory.getPhones()) {
2984 if (phone.isInEmergencySmsMode()) {
2985 return true;
2986 }
2987 }
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
2991 return false;
2992 }
2993
2994 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002995 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2996 throws RemoteException {
2997 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002998 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2999 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3000 "IMS not available on device.");
3001 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003002 final long token = Binder.clearCallingIdentity();
3003 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003005 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003006 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003007 } catch (ImsException e) {
3008 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003009 } finally {
3010 Binder.restoreCallingIdentity(token);
3011 }
3012 }
3013
3014 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003015 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3016 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003017 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3018 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3019 }
Meng Wangafbc5852019-09-19 17:37:13 -07003020 final long token = Binder.clearCallingIdentity();
3021 try {
3022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3023 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3024 .removeRegistrationCallbackForSubscription(c, subId);
3025 } catch (ImsException e) {
3026 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3027 + "is inactive, ignoring unregister.");
3028 // If the subscription is no longer active, just return, since the callback
3029 // will already have been removed internally.
3030 } finally {
3031 Binder.restoreCallingIdentity(token);
3032 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003033 }
3034
Brad Ebingera34a6c22019-10-22 17:36:18 -07003035 /**
3036 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3037 */
3038 @Override
3039 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3040 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3041 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3042 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3043 "IMS not available on device.");
3044 }
3045 final long token = Binder.clearCallingIdentity();
3046 try {
3047 Phone phone = getPhone(subId);
3048 if (phone == null) {
3049 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3050 + subId + "'");
3051 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3052 }
3053 phone.getImsRegistrationState(regState -> {
3054 try {
3055 consumer.accept((regState == null)
3056 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3057 } catch (RemoteException e) {
3058 // Ignore if the remote process is no longer available to call back.
3059 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3060 }
3061 });
3062 } finally {
3063 Binder.restoreCallingIdentity(token);
3064 }
3065 }
3066
3067 /**
3068 * Get the transport type for the IMS service registration state.
3069 */
3070 @Override
3071 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3072 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3073 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3074 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3075 "IMS not available on device.");
3076 }
3077 final long token = Binder.clearCallingIdentity();
3078 try {
3079 Phone phone = getPhone(subId);
3080 if (phone == null) {
3081 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3082 + subId + "'");
3083 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3084 }
3085 phone.getImsRegistrationTech(regTech -> {
3086 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3087 int regTechConverted = (regTech == null)
3088 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3089 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3090 regTechConverted);
3091 try {
3092 consumer.accept(regTechConverted);
3093 } catch (RemoteException e) {
3094 // Ignore if the remote process is no longer available to call back.
3095 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3096 }
3097 });
3098 } finally {
3099 Binder.restoreCallingIdentity(token);
3100 }
3101 }
3102
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003104 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3105 throws RemoteException {
3106 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003107 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3108 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3109 "IMS not available on device.");
3110 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3112 final long token = Binder.clearCallingIdentity();
3113 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003114 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003115 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003116 } catch (ImsException e) {
3117 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003118 } finally {
3119 Binder.restoreCallingIdentity(token);
3120 }
3121 }
3122
3123 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003124 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3125 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003126 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3127 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3128 }
Meng Wangafbc5852019-09-19 17:37:13 -07003129
3130 final long token = Binder.clearCallingIdentity();
3131 try {
3132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3133 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003134 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003135 } catch (ImsException e) {
3136 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3137 + "is inactive, ignoring unregister.");
3138 // If the subscription is no longer active, just return, since the callback
3139 // will already have been removed internally.
3140 } finally {
3141 Binder.restoreCallingIdentity(token);
3142 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 }
3144
3145 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003146 public boolean isCapable(int subId, int capability, int regTech) {
3147 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3149 final long token = Binder.clearCallingIdentity();
3150 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003151 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003152 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003153 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3155 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003156 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003157 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3158 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003159 } finally {
3160 Binder.restoreCallingIdentity(token);
3161 }
3162 }
3163
3164 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003165 public boolean isAvailable(int subId, int capability, int regTech) {
3166 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003167 final long token = Binder.clearCallingIdentity();
3168 try {
3169 Phone phone = getPhone(subId);
3170 if (phone == null) return false;
3171 return phone.isImsCapabilityAvailable(capability, regTech);
3172 } finally {
3173 Binder.restoreCallingIdentity(token);
3174 }
3175 }
3176
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003177 /**
3178 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3179 * subscription.
3180 * @param subId The subscription to use to check the configuration.
3181 * @param callback The callback that will be used to send the result.
3182 * @param capability The MmTelFeature capability that will be used to send the result.
3183 * @param transportType The transport type of the MmTelFeature capability.
3184 */
3185 @Override
3186 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3187 int transportType) {
3188 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3189 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3190 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3191 "IMS not available on device.");
3192 }
3193 final long token = Binder.clearCallingIdentity();
3194 try {
3195 int slotId = getSlotIndex(subId);
3196 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3197 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3198 + subId + "'");
3199 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3200 }
3201 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3202 transportType, aBoolean -> {
3203 try {
3204 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3205 } catch (RemoteException e) {
3206 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3207 + "running. Ignore");
3208 }
3209 });
3210 } finally {
3211 Binder.restoreCallingIdentity(token);
3212 }
3213 }
3214
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 @Override
3216 public boolean isAdvancedCallingSettingEnabled(int subId) {
3217 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3218 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3219 final long token = Binder.clearCallingIdentity();
3220 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003221 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003223 } catch (ImsException e) {
3224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 } finally {
3226 Binder.restoreCallingIdentity(token);
3227 }
3228 }
3229
3230 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003231 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003233 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003237 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003239 } catch (ImsException e) {
3240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
3244 }
3245
3246 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003247 public boolean isVtSettingEnabled(int subId) {
3248 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003252 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3253 } catch (ImsException e) {
3254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 } finally {
3256 Binder.restoreCallingIdentity(identity);
3257 }
3258 }
3259
3260 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003261 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003263 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003267 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003268 } catch (ImsException e) {
3269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 } finally {
3271 Binder.restoreCallingIdentity(identity);
3272 }
3273 }
3274
3275 @Override
3276 public boolean isVoWiFiSettingEnabled(int subId) {
3277 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003283 } catch (ImsException e) {
3284 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
3288 }
3289
3290 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003291 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003293 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003297 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003298 } catch (ImsException e) {
3299 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003300 } finally {
3301 Binder.restoreCallingIdentity(identity);
3302 }
3303 }
3304
3305 @Override
3306 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3307 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003311 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003313 } catch (ImsException e) {
3314 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
3318 }
3319
3320 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003321 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003323 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003327 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003328 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003329 } catch (ImsException e) {
3330 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
3334 }
3335
3336 @Override
3337 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3339 "setVoWiFiNonPersistent");
3340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003343 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003344 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003345 } catch (ImsException e) {
3346 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
3350 }
3351
3352 @Override
3353 public int getVoWiFiModeSetting(int subId) {
3354 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003358 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003359 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003360 } catch (ImsException e) {
3361 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
3365 }
3366
3367 @Override
3368 public void setVoWiFiModeSetting(int subId, int mode) {
3369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3370 "setVoWiFiModeSetting");
3371 final long identity = Binder.clearCallingIdentity();
3372 try {
3373 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003374 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003375 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003376 } catch (ImsException e) {
3377 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003378 } finally {
3379 Binder.restoreCallingIdentity(identity);
3380 }
3381 }
3382
3383 @Override
3384 public int getVoWiFiRoamingModeSetting(int subId) {
3385 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003389 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003390 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003391 } catch (ImsException e) {
3392 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
3396 }
3397
3398 @Override
3399 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3401 "setVoWiFiRoamingModeSetting");
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003405 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003407 } catch (ImsException e) {
3408 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003409 } finally {
3410 Binder.restoreCallingIdentity(identity);
3411 }
3412 }
3413
3414 @Override
3415 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3417 "setRttCapabilityEnabled");
3418 final long identity = Binder.clearCallingIdentity();
3419 try {
3420 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003421 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3422 } catch (ImsException e) {
3423 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
3429 @Override
3430 public boolean isTtyOverVolteEnabled(int subId) {
3431 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3432 final long identity = Binder.clearCallingIdentity();
3433 try {
3434 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003435 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003437 } catch (ImsException e) {
3438 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003439 } finally {
3440 Binder.restoreCallingIdentity(identity);
3441 }
3442 }
3443
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003444 @Override
3445 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3446 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3447 final long identity = Binder.clearCallingIdentity();
3448 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003449 if (!isImsAvailableOnDevice()) {
3450 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3451 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003452 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003453 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003454 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003455 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003456 } catch (ImsException e) {
3457 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003458 } finally {
3459 Binder.restoreCallingIdentity(identity);
3460 }
3461 }
3462
3463 @Override
3464 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3465 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3466 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003467 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3468 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3469 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003470 try {
3471 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003472 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003473 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003474 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003475 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3476 + "is inactive, ignoring unregister.");
3477 // If the subscription is no longer active, just return, since the callback will already
3478 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
3482 }
3483
allenwtsu99c623b2020-01-03 18:24:23 +08003484
3485 private void checkModifyPhoneStatePermission(int subId, String message) {
3486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3487 message);
3488 }
3489
3490 private boolean isImsProvisioningRequired(int subId, int capability,
3491 boolean isMmtelCapability) {
3492 Phone phone = getPhone(subId);
3493 if (phone == null) {
3494 loge("phone instance null for subid " + subId);
3495 return false;
3496 }
3497 if (isMmtelCapability) {
3498 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3499 return false;
3500 }
3501 } else {
3502 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3503 return false;
3504 }
3505 }
3506 return true;
3507 }
3508
3509 @Override
3510 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3511 boolean isProvisioned) {
3512 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3513
3514 final long identity = Binder.clearCallingIdentity();
3515 try {
3516 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3517 if (!isImsProvisioningRequired(subId, capability, false)) {
3518 return;
3519 }
3520
3521 // this capability requires provisioning, route to the correct API.
3522 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3523 switch (capability) {
3524 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3525 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3526 ims.setEabProvisioned(isProvisioned);
3527 break;
3528 default: {
3529 throw new IllegalArgumentException("Tried to set provisioning for "
3530 + "rcs capability '" + capability + "', which does not require "
3531 + "provisioning.");
3532 }
3533 }
3534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
3537
3538 }
3539
3540
3541 @Override
3542 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3543 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3547 if (!isImsProvisioningRequired(subId, capability, false)) {
3548 return true;
3549 }
3550
3551 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3552 switch (capability) {
3553 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3554 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3555 return ims.isEabProvisionedOnDevice();
3556
3557 default: {
3558 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3559 + "capability '" + capability + "', which does not require "
3560 + "provisioning.");
3561 }
3562 }
3563
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
3566 }
3567 }
3568
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003569 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003570 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3571 boolean isProvisioned) {
3572 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3573 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3574 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3575 }
allenwtsu99c623b2020-01-03 18:24:23 +08003576 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003580 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003581 return;
3582 }
3583
3584 // this capability requires provisioning, route to the correct API.
3585 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3586 switch (capability) {
3587 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3588 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3589 ims.setVolteProvisioned(isProvisioned);
3590 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3591 ims.setWfcProvisioned(isProvisioned);
3592 }
3593 break;
3594 }
3595 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3596 // There is currently no difference in VT provisioning type.
3597 ims.setVtProvisioned(isProvisioned);
3598 break;
3599 }
3600 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3601 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3602 // change the capability of the feature instead if needed.
3603 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3604 == isProvisioned) {
3605 // No change in provisioning.
3606 return;
3607 }
3608 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3609 try {
3610 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003611 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003612 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3613 + ", Exception" + e.getMessage());
3614 }
3615 break;
3616 }
3617 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003618 throw new IllegalArgumentException("Tried to set provisioning for "
3619 + "MmTel capability '" + capability + "', which does not require "
3620 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003621 }
3622 }
3623
3624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
3627 }
3628
3629 @Override
3630 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3631 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3632 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3633 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3634 }
3635 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003639 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003640 return true;
3641 }
3642
3643 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3644 switch (capability) {
3645 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3646 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3647 return ims.isVolteProvisionedOnDevice();
3648 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3649 return ims.isWfcProvisionedOnDevice();
3650 }
3651 // This should never happen, since we are checking tech above to make sure it
3652 // is either LTE or IWLAN.
3653 throw new IllegalArgumentException("Invalid radio technology for voice "
3654 + "capability.");
3655 }
3656 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3657 // There is currently no difference in VT provisioning type.
3658 return ims.isVtProvisionedOnDevice();
3659 }
3660 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3661 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3662 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3663 }
3664 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003665 throw new IllegalArgumentException(
3666 "Tried to get provisioning for MmTel capability '" + capability
3667 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003668 }
3669 }
3670
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
3673 }
3674 }
3675
3676 @Override
3677 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3678 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3679 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3680 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3681 }
3682 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3683 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3684 return (provisionedBits & capability) > 0;
3685 }
3686
3687 @Override
3688 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3689 boolean isProvisioned) {
3690 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3691 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3692 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3693 }
3694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3695 "setProvisioningStatusForCapability");
3696 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3697 // If the current provisioning status for capability already matches isProvisioned,
3698 // do nothing.
3699 if (((provisionedBits & capability) > 0) == isProvisioned) {
3700 return;
3701 }
3702 if (isProvisioned) {
3703 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3704 } else {
3705 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3706 }
3707 }
3708
3709 /**
3710 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3711 * technology. The bitfield should mirror the bitfield defined by
3712 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3713 */
3714 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3715 String key = getMmTelProvisioningKey(subId, tech);
3716 // Default is no capabilities are provisioned.
3717 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3718 }
3719
3720 /**
3721 * Sets the MmTel capability provisioning bitfield (defined by
3722 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3723 * technology specified.
3724 *
3725 * Note: This is a synchronous command and should not be called on UI thread.
3726 */
3727 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3728 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3729 String key = getMmTelProvisioningKey(subId, tech);
3730 editor.putInt(key, newField);
3731 editor.commit();
3732 }
3733
3734 private static String getMmTelProvisioningKey(int subId, int tech) {
3735 // resulting key is provision_ims_mmtel_{subId}_{tech}
3736 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3737 }
3738
3739 /**
3740 * Query CarrierConfig to see if the specified capability requires provisioning for the
3741 * carrier associated with the subscription id.
3742 */
3743 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3744 int capability) {
3745 CarrierConfigManager configManager = new CarrierConfigManager(context);
3746 PersistableBundle c = configManager.getConfigForSubId(subId);
3747 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003748 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003749 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3750 false);
3751 boolean requireVoiceVtProvisioning = c.getBoolean(
3752 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3753
3754 // First check to make sure that the capability requires provisioning.
3755 switch (capability) {
3756 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3757 // intentional fallthrough
3758 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3759 if (requireVoiceVtProvisioning) {
3760 // Voice and Video requires provisioning
3761 return true;
3762 }
3763 break;
3764 }
3765 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3766 if (requireUtProvisioning) {
3767 // UT requires provisioning
3768 return true;
3769 }
3770 break;
3771 }
3772 }
3773 return false;
3774 }
3775
allenwtsu99c623b2020-01-03 18:24:23 +08003776 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3777 int capability) {
3778 CarrierConfigManager configManager = new CarrierConfigManager(context);
3779 PersistableBundle c = configManager.getConfigForSubId(subId);
3780
3781 boolean requireRcsProvisioning = c.getBoolean(
3782 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3783
3784 // First check to make sure that the capability requires provisioning.
3785 switch (capability) {
3786 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3787 // intentional fallthrough
3788 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3789 if (requireRcsProvisioning) {
3790 // OPTION or PRESENCE requires provisioning
3791 return true;
3792 }
3793 break;
3794 }
3795 }
3796 return false;
3797 }
3798
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003799 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003800 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003801 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3802 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3803 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003804 enforceReadPrivilegedPermission("getImsProvisioningInt");
3805 final long identity = Binder.clearCallingIdentity();
3806 try {
3807 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003808 int slotId = getSlotIndex(subId);
3809 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3810 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3811 + subId + "' for key:" + key);
3812 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3813 }
3814 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003815 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003816 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3817 + subId + "' for key:" + key);
3818 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003819 } finally {
3820 Binder.restoreCallingIdentity(identity);
3821 }
3822 }
3823
3824 @Override
3825 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003826 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3827 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3828 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003829 enforceReadPrivilegedPermission("getImsProvisioningString");
3830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003833 int slotId = getSlotIndex(subId);
3834 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3835 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3836 + subId + "' for key:" + key);
3837 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3838 }
3839 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003840 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003841 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3842 + subId + "' for key:" + key);
3843 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003844 } finally {
3845 Binder.restoreCallingIdentity(identity);
3846 }
3847 }
3848
3849 @Override
3850 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003851 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3852 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3853 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3855 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003859 int slotId = getSlotIndex(subId);
3860 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3861 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3862 + subId + "' for key:" + key);
3863 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3864 }
3865 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003866 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003867 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3868 + "' for key:" + key);
3869 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003870 } finally {
3871 Binder.restoreCallingIdentity(identity);
3872 }
3873 }
3874
3875 @Override
3876 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003877 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3878 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3879 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3881 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003885 int slotId = getSlotIndex(subId);
3886 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3887 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3888 + subId + "' for key:" + key);
3889 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3890 }
3891 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003892 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003893 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3894 + "' for key:" + key);
3895 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003896 } finally {
3897 Binder.restoreCallingIdentity(identity);
3898 }
3899 }
3900
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003901 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 int slotId = SubscriptionManager.getSlotIndex(subId);
3903 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003904 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3905 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 }
3907 return slotId;
3908 }
3909
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003910 private int getSlotIndex(int subId) {
3911 int slotId = SubscriptionManager.getSlotIndex(subId);
3912 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3913 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3914 }
3915 return slotId;
3916 }
3917
Wink Saville36469e72014-06-11 15:17:00 -07003918 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003919 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003920 */
3921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003922 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3923 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003924 final int targetSdk = getTargetSdk(callingPackage);
3925 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003926 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003927 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003928 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003929 mApp, subId, callingPackage, callingFeatureId,
3930 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003931 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3932 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 final Phone phone = getPhone(subId);
3937 if (phone != null) {
3938 return phone.getServiceState().getDataNetworkType();
3939 } else {
3940 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3941 }
3942 } finally {
3943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003945 }
3946
3947 /**
3948 * Returns the data network type
3949 */
3950 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003951 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3952 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3953 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003954 }
3955
3956 /**
3957 * Returns the data network type for a subId
3958 */
3959 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003960 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3961 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003963 mApp, subId, callingPackage, callingFeatureId,
3964 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003965 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3966 }
3967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 final Phone phone = getPhone(subId);
3971 if (phone != null) {
3972 return phone.getServiceState().getDataNetworkType();
3973 } else {
3974 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3975 }
3976 } finally {
3977 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003979 }
3980
3981 /**
Wink Saville36469e72014-06-11 15:17:00 -07003982 * Returns the Voice network type for a subId
3983 */
3984 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003985 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3986 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003988 mApp, subId, callingPackage, callingFeatureId,
3989 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003990 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3991 }
3992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 final Phone phone = getPhone(subId);
3996 if (phone != null) {
3997 return phone.getServiceState().getVoiceNetworkType();
3998 } else {
3999 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4000 }
4001 } finally {
4002 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004004 }
4005
4006 /**
4007 * @return true if a ICC card is present
4008 */
4009 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004010 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004011 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4012 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004013 }
4014
4015 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004016 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004017 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004018 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004019 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 final Phone phone = PhoneFactory.getPhone(slotIndex);
4023 if (phone != null) {
4024 return phone.getIccCard().hasIccCard();
4025 } else {
4026 return false;
4027 }
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004031 }
4032
4033 /**
4034 * Return if the current radio is LTE on CDMA. This
4035 * is a tri-state return value as for a period of time
4036 * the mode may be unknown.
4037 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004038 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004039 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004040 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004041 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004042 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004043 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4044 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4045 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004046 }
4047
Sanket Padawe356d7632015-06-22 14:03:32 -07004048 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004049 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4050 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004052 mApp, subId, callingPackage, callingFeatureId,
4053 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004054 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4055 }
4056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004057 final long identity = Binder.clearCallingIdentity();
4058 try {
4059 final Phone phone = getPhone(subId);
4060 if (phone == null) {
4061 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4062 } else {
4063 return phone.getLteOnCdmaMode();
4064 }
4065 } finally {
4066 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004067 }
Wink Saville36469e72014-06-11 15:17:00 -07004068 }
4069
Wink Saville36469e72014-06-11 15:17:00 -07004070 /**
4071 * {@hide}
4072 * Returns Default subId, 0 in the case of single standby.
4073 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004074 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004075 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004076 }
4077
Shishir Agrawala9f32182016-04-12 12:00:16 -07004078 private int getSlotForDefaultSubscription() {
4079 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4080 }
4081
Wink Savilleb564aae2014-10-23 10:18:09 -07004082 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004083 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004084 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004085
Pengquan Menge92a50d2018-09-21 15:54:48 -07004086 private boolean isActiveSubscription(int subId) {
4087 return mSubscriptionController.isActiveSubId(subId);
4088 }
4089
Ihab Awadf2177b72013-11-25 13:33:23 -08004090 /**
4091 * @see android.telephony.TelephonyManager.WifiCallingChoices
4092 */
4093 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 final long identity = Binder.clearCallingIdentity();
4095 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004096 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4098 getWhenToMakeWifiCallsDefaultPreference());
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
4101 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004102 }
4103
4104 /**
4105 * @see android.telephony.TelephonyManager.WifiCallingChoices
4106 */
4107 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004111 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004116 }
4117
Sailesh Nepald1e68152013-12-12 19:08:02 -08004118 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004119 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004120 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004121 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004122
Jordan Liu4c733742019-02-28 12:03:40 -08004123 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4124 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4125 if (phoneId == -1) {
4126 throw new IllegalArgumentException("Given slot index: " + slotIndex
4127 + " does not correspond to an active phone");
4128 }
4129 return PhoneFactory.getPhone(phoneId);
4130 }
4131
Shishir Agrawal566b7612013-10-28 14:41:00 -07004132 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004133 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4134 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4136 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004138 if (DBG) {
4139 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4140 }
4141 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4142 p2);
4143 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004144
Jordan Liu4c733742019-02-28 12:03:40 -08004145
4146 @Override
4147 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4148 int slotIndex, String callingPackage, String aid, int p2) {
4149 enforceModifyPermission();
4150 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4151 if (DBG) {
4152 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4153 }
4154 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4155 callingPackage, aid, p2);
4156 }
4157
4158 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4159 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 if (TextUtils.equals(ISDR_AID, aid)) {
4163 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004164 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4165 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 if (bestComponent == null
4167 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4168 loge("The calling package is not allowed to access ISD-R.");
4169 throw new SecurityException(
4170 "The calling package is not allowed to access ISD-R.");
4171 }
Derek Tan740e1672017-06-27 14:56:27 -07004172 }
Derek Tan740e1672017-06-27 14:56:27 -07004173
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004174 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004175 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4176 null /* workSource */);
4177 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178 return response;
4179 } finally {
4180 Binder.restoreCallingIdentity(identity);
4181 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004182 }
4183
4184 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004185 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4187 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004188 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4189 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4190 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004191
Jordan Liu4c733742019-02-28 12:03:40 -08004192 @Override
4193 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4194 enforceModifyPermission();
4195 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4196 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4197 channel);
4198 }
4199
4200 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201 final long identity = Binder.clearCallingIdentity();
4202 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203 if (channel < 0) {
4204 return false;
4205 }
Jordan Liu4c733742019-02-28 12:03:40 -08004206 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4207 null /* workSource */);
4208 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209 return success;
4210 } finally {
4211 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004212 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004213 }
4214
4215 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004216 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004217 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4219 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004220 if (DBG) {
4221 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4222 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4223 + p3 + " data=" + data);
4224 }
4225 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4226 command, p1, p2, p3, data);
4227 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004228
Jordan Liu4c733742019-02-28 12:03:40 -08004229 @Override
4230 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4231 int command, int p1, int p2, int p3, String data) {
4232 enforceModifyPermission();
4233 if (DBG) {
4234 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4235 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4236 + p3 + " data=" + data);
4237 }
4238 return iccTransmitApduLogicalChannelWithPermission(
4239 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4240 data);
4241 }
4242
4243 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4244 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 final long identity = Binder.clearCallingIdentity();
4246 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004247 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248 return "";
4249 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004252 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4253 null /* workSource */);
4254 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 // Append the returned status code to the end of the response payload.
4257 String s = Integer.toHexString(
4258 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4259 if (response.payload != null) {
4260 s = IccUtils.bytesToHexString(response.payload) + s;
4261 }
4262 return s;
4263 } finally {
4264 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004265 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004266 }
Jake Hambye994d462014-02-03 13:10:13 -08004267
Evan Charltonc66da362014-05-16 14:06:40 -07004268 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004269 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4270 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4272 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004274 if (DBG) {
4275 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4276 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4277 }
4278 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4279 cla, command, p1, p2, p3, data);
4280 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004281
Jordan Liu4c733742019-02-28 12:03:40 -08004282 @Override
4283 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4284 int command, int p1, int p2, int p3, String data) {
4285 enforceModifyPermission();
4286 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4287 if (DBG) {
4288 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4289 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4290 + " data=" + data);
4291 }
4292
4293 return iccTransmitApduBasicChannelWithPermission(
4294 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4295 p2, p3, data);
4296 }
4297
4298 // open APDU basic channel assuming the caller has sufficient permissions
4299 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4300 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4304 && TextUtils.equals(ISDR_AID, data)) {
4305 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004306 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4307 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 if (bestComponent == null
4309 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4310 loge("The calling package is not allowed to select ISD-R.");
4311 throw new SecurityException(
4312 "The calling package is not allowed to select ISD-R.");
4313 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004314 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004317 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4318 null /* workSource */);
4319 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321 // Append the returned status code to the end of the response payload.
4322 String s = Integer.toHexString(
4323 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4324 if (response.payload != null) {
4325 s = IccUtils.bytesToHexString(response.payload) + s;
4326 }
4327 return s;
4328 } finally {
4329 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004330 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004331 }
4332
4333 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004334 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004335 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4337 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339 final long identity = Binder.clearCallingIdentity();
4340 try {
4341 if (DBG) {
4342 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4343 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4344 }
4345
4346 IccIoResult response =
4347 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4348 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4349 subId);
4350
4351 if (DBG) {
4352 log("Exchange SIM_IO [R]" + response);
4353 }
4354
4355 byte[] result = null;
4356 int length = 2;
4357 if (response.payload != null) {
4358 length = 2 + response.payload.length;
4359 result = new byte[length];
4360 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4361 } else {
4362 result = new byte[length];
4363 }
4364
4365 result[length - 1] = (byte) response.sw2;
4366 result[length - 2] = (byte) response.sw1;
4367 return result;
4368 } finally {
4369 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004370 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004371 }
4372
Nathan Haroldb3014052017-01-25 15:57:32 -08004373 /**
4374 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4375 * on a particular subscription
4376 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004377 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4378 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004379 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004380 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004381 return null;
4382 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383
4384 final long identity = Binder.clearCallingIdentity();
4385 try {
4386 if (appType != TelephonyManager.APPTYPE_USIM
4387 && appType != TelephonyManager.APPTYPE_SIM) {
4388 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4389 return null;
4390 }
4391 Object response = sendRequest(
4392 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4393 if (response instanceof String[]) {
4394 return (String[]) response;
4395 }
yincheng zhao2737e882019-09-06 17:06:54 -07004396 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004398 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004399 } finally {
4400 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004401 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004402 }
4403
yincheng zhao2737e882019-09-06 17:06:54 -07004404 /**
4405 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4406 * subscription.
4407 *
4408 * @param subId the id of the subscription.
4409 * @param appType the uicc app type, must be USIM or SIM.
4410 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4411 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004412 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004413 * @return number of fplmns that is successfully written to the SIM.
4414 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004415 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4416 String callingFeatureId) {
4417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4418 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004419 if (DBG) logv("no permissions for setForbiddenplmns");
4420 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4421 }
4422 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4423 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4424 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4425 }
4426 if (fplmns == null) {
4427 throw new IllegalArgumentException("Fplmn List provided is null");
4428 }
4429 for (String fplmn : fplmns) {
4430 if (!CellIdentity.isValidPlmn(fplmn)) {
4431 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4432 }
4433 }
4434 final long identity = Binder.clearCallingIdentity();
4435 try {
4436 Object response = sendRequest(
4437 CMD_SET_FORBIDDEN_PLMNS,
4438 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4439 subId);
4440 return (int) response;
4441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
4444 }
4445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004446 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004447 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4449 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004450
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004451 final long identity = Binder.clearCallingIdentity();
4452 try {
4453 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4454 if (response.payload == null) {
4455 return "";
4456 }
Evan Charltonc66da362014-05-16 14:06:40 -07004457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 // Append the returned status code to the end of the response payload.
4459 String s = Integer.toHexString(
4460 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4461 s = IccUtils.bytesToHexString(response.payload) + s;
4462 return s;
4463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
Evan Charltonc66da362014-05-16 14:06:40 -07004466 }
4467
Jake Hambye994d462014-02-03 13:10:13 -08004468 /**
4469 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4470 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4471 *
4472 * @param itemID the ID of the item to read
4473 * @return the NV item as a String, or null on error.
4474 */
4475 @Override
4476 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004477 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4479 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480
4481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004484 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4486 return value;
4487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
Jake Hambye994d462014-02-03 13:10:13 -08004490 }
4491
4492 /**
4493 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4494 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4495 *
4496 * @param itemID the ID of the item to read
4497 * @param itemValue the value to write, as a String
4498 * @return true on success; false on any failure
4499 */
4500 @Override
4501 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004502 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4504 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004505
4506 final long identity = Binder.clearCallingIdentity();
4507 try {
4508 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4509 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004510 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4512 return success;
4513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
Jake Hambye994d462014-02-03 13:10:13 -08004516 }
4517
4518 /**
4519 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4520 * Used for device configuration by some CDMA operators.
4521 *
4522 * @param preferredRoamingList byte array containing the new PRL
4523 * @return true on success; false on any failure
4524 */
4525 @Override
4526 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4528 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529
4530 final long identity = Binder.clearCallingIdentity();
4531 try {
4532 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4533 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4534 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4535 return success;
4536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
Jake Hambye994d462014-02-03 13:10:13 -08004539 }
4540
4541 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004542 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004543 * Used for device configuration by some CDMA operators.
4544 *
chen xu6dac5ab2018-10-26 17:39:23 -07004545 * @param slotIndex - device slot.
4546 *
Jake Hambye994d462014-02-03 13:10:13 -08004547 * @return true on success; false on any failure
4548 */
4549 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004550 public boolean resetModemConfig(int slotIndex) {
4551 Phone phone = PhoneFactory.getPhone(slotIndex);
4552 if (phone != null) {
4553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4554 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555
chen xu6dac5ab2018-10-26 17:39:23 -07004556 final long identity = Binder.clearCallingIdentity();
4557 try {
4558 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4559 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4560 return success;
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 }
chen xu6dac5ab2018-10-26 17:39:23 -07004565 return false;
4566 }
4567
4568 /**
4569 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4570 *
4571 * @param slotIndex - device slot.
4572 *
4573 * @return true on success; false on any failure
4574 */
4575 @Override
4576 public boolean rebootModem(int slotIndex) {
4577 Phone phone = PhoneFactory.getPhone(slotIndex);
4578 if (phone != null) {
4579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4580 mApp, phone.getSubId(), "rebootModem");
4581
4582 final long identity = Binder.clearCallingIdentity();
4583 try {
4584 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4585 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4586 return success;
4587 } finally {
4588 Binder.restoreCallingIdentity(identity);
4589 }
4590 }
4591 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004592 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004593
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004594 public String[] getPcscfAddress(String apnType, String callingPackage,
4595 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004596 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4598 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004599 return new String[0];
4600 }
4601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004602 final long identity = Binder.clearCallingIdentity();
4603 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004604 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605 } finally {
4606 Binder.restoreCallingIdentity(identity);
4607 }
Wink Saville36469e72014-06-11 15:17:00 -07004608 }
4609
Brad Ebinger51f743a2017-01-23 13:50:20 -08004610 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004611 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4612 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004613 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004614 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004615 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616
4617 final long identity = Binder.clearCallingIdentity();
4618 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004619 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004620 // may happen if the device does not support IMS.
4621 return;
4622 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004623 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 } finally {
4625 Binder.restoreCallingIdentity(identity);
4626 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004627 }
4628
4629 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004630 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4631 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004632 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004633 public void disableIms(int slotId) {
4634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635
4636 final long identity = Binder.clearCallingIdentity();
4637 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004638 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004639 // may happen if the device does not support IMS.
4640 return;
4641 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004642 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004646 }
4647
4648 /**
4649 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4650 * feature or {@link null} if the service is not available. If the feature is available, the
4651 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4652 */
4653 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004654 IImsServiceFeatureCallback callback) {
4655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656
4657 final long identity = Binder.clearCallingIdentity();
4658 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004659 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004660 // may happen if the device does not support IMS.
4661 return null;
4662 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004663 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 } finally {
4665 Binder.restoreCallingIdentity(identity);
4666 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004667 }
4668
4669 /**
4670 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4671 * feature during emergency calling or {@link null} if the service is not available. If the
4672 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4673 * listener for feature updates.
4674 */
4675 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4676 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677
4678 final long identity = Binder.clearCallingIdentity();
4679 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004680 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004681 // may happen if the device does not support IMS.
4682 return null;
4683 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004684 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 } finally {
4686 Binder.restoreCallingIdentity(identity);
4687 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004688 }
4689
Brad Ebinger5f64b052017-12-14 14:26:15 -08004690 /**
4691 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004692 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004693 */
4694 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4695 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696
4697 final long identity = Binder.clearCallingIdentity();
4698 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004699 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004700 // may happen if the device does not support IMS.
4701 return null;
4702 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004703 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704 } finally {
4705 Binder.restoreCallingIdentity(identity);
4706 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004707 }
4708
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004709 /**
4710 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004711 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004712 */
4713 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004715
4716 final long identity = Binder.clearCallingIdentity();
4717 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004718 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004719 // may happen if the device does not support IMS.
4720 return null;
4721 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004722 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723 } finally {
4724 Binder.restoreCallingIdentity(identity);
4725 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004726 }
4727
Brad Ebinger884c07b2018-02-15 16:17:40 -08004728 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004729 * Sets the ImsService Package Name that Telephony will bind to.
4730 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004731 * @param slotIndex the slot ID that the ImsService should bind for.
4732 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004733 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004734 * @param featureTypes An integer array of feature types associated with a packageName.
4735 * @param packageName The name of the package that the current configuration will be replaced
4736 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004737 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004738 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004739 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4740 int[] featureTypes, String packageName) {
4741 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4742 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4744 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004745 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747 final long identity = Binder.clearCallingIdentity();
4748 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004749 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004750 // may happen if the device does not support IMS.
4751 return false;
4752 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004753 Map<Integer, String> featureConfig = new HashMap<>();
4754 for (int featureType : featureTypes) {
4755 featureConfig.put(featureType, packageName);
4756 }
4757 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4758 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004762 }
4763
4764 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004765 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004766 *
4767 * @param slotId The slot that the ImsService is associated with.
4768 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4769 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004770 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004771 * @return the package name of the ImsService configuration.
4772 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004773 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4774 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004775 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004776 TelephonyPermissions
4777 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4778 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4779 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 final long identity = Binder.clearCallingIdentity();
4782 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004783 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004784 // may happen if the device does not support IMS.
4785 return "";
4786 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004787 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004788 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4789 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 } finally {
4791 Binder.restoreCallingIdentity(identity);
4792 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004793 }
4794
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004795 /**
4796 * Get the MmTelFeature state associated with the requested subscription id.
4797 * @param subId The subscription that the MmTelFeature is associated with.
4798 * @param callback A callback with an integer containing the
4799 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4800 */
4801 @Override
4802 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4803 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4804 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4805 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4806 "IMS not available on device.");
4807 }
4808 final long token = Binder.clearCallingIdentity();
4809 try {
4810 int slotId = getSlotIndex(subId);
4811 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4812 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4813 + subId + "'");
4814 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4815 }
4816 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4817 try {
4818 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4819 } catch (RemoteException e) {
4820 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4821 + "Ignore");
4822 }
4823 });
4824 } finally {
4825 Binder.restoreCallingIdentity(token);
4826 }
4827 }
4828
Wink Saville36469e72014-06-11 15:17:00 -07004829 public void setImsRegistrationState(boolean registered) {
4830 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831
4832 final long identity = Binder.clearCallingIdentity();
4833 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004834 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004835 } finally {
4836 Binder.restoreCallingIdentity(identity);
4837 }
Wink Saville36469e72014-06-11 15:17:00 -07004838 }
4839
4840 /**
Stuart Scott54788802015-03-30 13:18:01 -07004841 * Set the network selection mode to automatic.
4842 *
4843 */
4844 @Override
4845 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4847 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848
Pengquan Menge92a50d2018-09-21 15:54:48 -07004849 if (!isActiveSubscription(subId)) {
4850 return;
4851 }
4852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 final long identity = Binder.clearCallingIdentity();
4854 try {
4855 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4856 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
Stuart Scott54788802015-03-30 13:18:01 -07004860 }
4861
Pengquan Mengea84e042018-09-20 14:57:26 -07004862 /**
4863 * Ask the radio to connect to the input network and change selection mode to manual.
4864 *
4865 * @param subId the id of the subscription.
4866 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4867 * the operator to attach to.
4868 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4869 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4870 * normal network selection next time.
4871 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004872 */
4873 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004874 public boolean setNetworkSelectionModeManual(
4875 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4877 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004878
4879 if (!isActiveSubscription(subId)) {
4880 return false;
4881 }
4882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883 final long identity = Binder.clearCallingIdentity();
4884 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004885 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004886 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004887 if (DBG) {
4888 log("setNetworkSelectionModeManual: subId: " + subId
4889 + " operator: " + operatorInfo);
4890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4892 } finally {
4893 Binder.restoreCallingIdentity(identity);
4894 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004895 }
4896
4897 /**
4898 * Scans for available networks.
4899 */
4900 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004901 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4902 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4904 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004905 LocationAccessPolicy.LocationPermissionResult locationResult =
4906 LocationAccessPolicy.checkLocationPermission(mApp,
4907 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4908 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004909 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004910 .setCallingPid(Binder.getCallingPid())
4911 .setCallingUid(Binder.getCallingUid())
4912 .setMethod("getCellNetworkScanResults")
4913 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4914 .build());
4915 switch (locationResult) {
4916 case DENIED_HARD:
4917 throw new SecurityException("Not allowed to access scan results -- location");
4918 case DENIED_SOFT:
4919 return null;
4920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921
Pengquan Menga1bb6272018-09-06 09:59:22 -07004922 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 try {
4924 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004925 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 } finally {
4928 Binder.restoreCallingIdentity(identity);
4929 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004930 }
4931
4932 /**
yinxub1bed742017-04-17 11:45:04 -07004933 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004934 *
yinxub1bed742017-04-17 11:45:04 -07004935 * @param subId id of the subscription
4936 * @param request contains the radio access networks with bands/channels to scan
4937 * @param messenger callback messenger for scan results or errors
4938 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004939 * @return the id of the requested scan which can be used to stop the scan.
4940 */
4941 @Override
4942 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004943 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4945 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004946 LocationAccessPolicy.LocationPermissionResult locationResult =
4947 LocationAccessPolicy.checkLocationPermission(mApp,
4948 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4949 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004950 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004951 .setCallingPid(Binder.getCallingPid())
4952 .setCallingUid(Binder.getCallingUid())
4953 .setMethod("requestNetworkScan")
4954 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4955 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004956 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004957 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004958 if (e != null) {
4959 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4960 throw e;
4961 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004962 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004963 return TelephonyScanManager.INVALID_SCAN_ID;
4964 }
4965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 }
Hall Liu912dfd32019-04-25 14:02:26 -07004967 int callingUid = Binder.getCallingUid();
4968 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004969 final long identity = Binder.clearCallingIdentity();
4970 try {
4971 return mNetworkScanRequestTracker.startNetworkScan(
4972 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004973 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
yinxu504e1392017-04-12 16:03:22 -07004977 }
4978
Hall Liub2ac8ef2019-02-28 15:56:23 -08004979 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004980 NetworkScanRequest request, int subId) {
4981 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4982 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4983 boolean hasNetworkScanPermission =
4984 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4985 == PERMISSION_GRANTED;
4986
4987 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4988 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4989 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004990 }
4991
4992 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4993 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004994 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4995 return new SecurityException("Specific channels must not be"
4996 + " scanned without location access.");
4997 }
4998 }
4999 }
5000
Hall Liub2ac8ef2019-02-28 15:56:23 -08005001 return null;
5002 }
5003
yinxu504e1392017-04-12 16:03:22 -07005004 /**
5005 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005006 *
5007 * @param subId id of the subscription
5008 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005009 */
5010 @Override
5011 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5013 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014
Hall Liu912dfd32019-04-25 14:02:26 -07005015 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 final long identity = Binder.clearCallingIdentity();
5017 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005018 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005019 } finally {
5020 Binder.restoreCallingIdentity(identity);
5021 }
yinxu504e1392017-04-12 16:03:22 -07005022 }
5023
5024 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005025 * Get the calculated preferred network type.
5026 * Used for debugging incorrect network type.
5027 *
5028 * @return the preferred network type, defined in RILConstants.java.
5029 */
5030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005031 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005032 final Phone defaultPhone = getDefaultPhone();
5033 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005034 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005035 return RILConstants.PREFERRED_NETWORK_MODE;
5036 }
5037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 final long identity = Binder.clearCallingIdentity();
5039 try {
5040 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005041 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 } finally {
5043 Binder.restoreCallingIdentity(identity);
5044 }
Junda Liu84d15a22014-07-02 11:21:04 -07005045 }
5046
5047 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005048 * Get the preferred network type.
5049 * Used for device configuration by some CDMA operators.
5050 *
5051 * @return the preferred network type, defined in RILConstants.java.
5052 */
5053 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005054 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005055 TelephonyPermissions
5056 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5057 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058
5059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 if (DBG) log("getPreferredNetworkType");
5062 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5063 int networkType = (result != null ? result[0] : -1);
5064 if (DBG) log("getPreferredNetworkType: " + networkType);
5065 return networkType;
5066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005069 }
5070
5071 /**
5072 * Set the preferred network type.
5073 * Used for device configuration by some CDMA operators.
5074 *
5075 * @param networkType the preferred network type, defined in RILConstants.java.
5076 * @return true on success; false on any failure.
5077 */
5078 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005079 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5081 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082
5083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
5086 Boolean success = (Boolean) sendRequest(
5087 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5088 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5089 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005090 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5092 }
5093 return success;
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005096 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005097 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005098
5099 /**
Miaoa84611c2019-03-15 09:21:10 +08005100 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005101 *
Miaoa84611c2019-03-15 09:21:10 +08005102 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005103 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005104 * @hide
5105 */
5106 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005107 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005108 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005110 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 try {
Miaoa84611c2019-03-15 09:21:10 +08005112 if (phone != null) {
5113 return phone.hasMatchedTetherApnSetting();
5114 } else {
5115 return false;
5116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 } finally {
5118 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005119 }
Junda Liu475951f2014-11-07 16:45:03 -08005120 }
5121
5122 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005123 * Set mobile data enabled
5124 * Used by the user through settings etc to turn on/off mobile data
5125 *
5126 * @param enable {@code true} turn turn data on, else {@code false}
5127 */
5128 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005129 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5131 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132
5133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 int phoneId = mSubscriptionController.getPhoneId(subId);
5136 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5137 Phone phone = PhoneFactory.getPhone(phoneId);
5138 if (phone != null) {
5139 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005140 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005142 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 }
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005146 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005147 }
5148
5149 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005150 * Enable or disable always reporting signal strength changes from radio.
5151 *
5152 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5153 */
5154 @Override
5155 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5156 enforceModifyPermission();
5157 enforceSystemCaller();
5158
5159 final long identity = Binder.clearCallingIdentity();
5160 final Phone phone = getPhone(subId);
5161 try {
5162 if (phone != null) {
5163 if (DBG) {
5164 log("setAlwaysReportSignalStrength: subId=" + subId
5165 + " isEnable=" + isEnable);
5166 }
5167 phone.setAlwaysReportSignalStrength(isEnable);
5168 } else {
5169 loge("setAlwaysReportSignalStrength: no phone found for subId="
5170 + subId);
5171 }
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
5175 }
5176
5177 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005178 * Get the user enabled state of Mobile Data.
5179 *
5180 * TODO: remove and use isUserDataEnabled.
5181 * This can't be removed now because some vendor codes
5182 * calls through ITelephony directly while they should
5183 * use TelephonyManager.
5184 *
5185 * @return true on enabled
5186 */
5187 @Override
5188 public boolean getDataEnabled(int subId) {
5189 return isUserDataEnabled(subId);
5190 }
5191
5192 /**
5193 * Get whether mobile data is enabled per user setting.
5194 *
5195 * There are other factors deciding whether mobile data is actually enabled, but they are
5196 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005197 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005198 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005199 *
5200 * @return {@code true} if data is enabled else {@code false}
5201 */
5202 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005203 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005204 try {
5205 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5206 null);
5207 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5209 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211
5212 final long identity = Binder.clearCallingIdentity();
5213 try {
5214 int phoneId = mSubscriptionController.getPhoneId(subId);
5215 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5216 Phone phone = PhoneFactory.getPhone(phoneId);
5217 if (phone != null) {
5218 boolean retVal = phone.isUserDataEnabled();
5219 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5220 return retVal;
5221 } else {
5222 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5223 return false;
5224 }
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005227 }
5228 }
5229
5230 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005231 * Checks if the device is capable of mobile data by considering whether whether the
5232 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5233 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005234 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005235 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005236 */
5237 @Override
5238 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005239 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005240
5241 final long identity = Binder.clearCallingIdentity();
5242 try {
5243 int phoneId = mSubscriptionController.getPhoneId(subId);
5244 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5245 Phone phone = PhoneFactory.getPhone(phoneId);
5246 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005247 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5249 return retVal;
5250 } else {
5251 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5252 return false;
5253 }
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005256 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005257 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005258
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005259 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5260 Phone phone) {
5261 //load access rules from carrier configs, and check those as well: b/139133814
5262 SubscriptionController subController = SubscriptionController.getInstance();
5263 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5264 || subController == null) return privilegeFromSim;
5265
5266 int uid = Binder.getCallingUid();
5267 PackageManager pkgMgr = phone.getContext().getPackageManager();
5268 String[] packages = pkgMgr.getPackagesForUid(uid);
5269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5273 SubscriptionManager subManager = (SubscriptionManager)
5274 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5275 for (String pkg : packages) {
5276 if (subManager.canManageSubscription(subInfo, pkg)) {
5277 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5278 }
5279 }
5280 return privilegeFromSim;
5281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
5284 }
5285
5286 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5287 String pkgName) {
5288 //load access rules from carrier configs, and check those as well: b/139133814
5289 SubscriptionController subController = SubscriptionController.getInstance();
5290 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5291 || subController == null) return privilegeFromSim;
5292
5293 final long identity = Binder.clearCallingIdentity();
5294 try {
5295 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5296 SubscriptionManager subManager = (SubscriptionManager)
5297 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5298 return subManager.canManageSubscription(subInfo, pkgName)
5299 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
5303 }
5304
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005305 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005306 public int getCarrierPrivilegeStatus(int subId) {
5307 final Phone phone = getPhone(subId);
5308 if (phone == null) {
5309 loge("getCarrierPrivilegeStatus: Invalid subId");
5310 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5311 }
5312 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005313 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005314 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005315 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5316 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005317
5318 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5319 card.getCarrierPrivilegeStatusForCurrentTransaction(
5320 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005321 }
Junda Liu29340342014-07-10 15:23:27 -07005322
5323 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005324 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005325 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005326 final Phone phone = getPhone(subId);
5327 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005328 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005329 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5330 }
5331 UiccProfile profile =
5332 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5333 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005334 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005335 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5336 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005337 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005338 profile.getCarrierPrivilegeStatusForUid(
5339 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005340 }
5341
5342 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005343 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5344 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005345 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005346 }
5347
5348 int phoneId = SubscriptionManager.getPhoneId(subId);
5349 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005350 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005351 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005352 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5353 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005354 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5355 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5356 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005357 }
5358
5359 @Override
5360 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005361 if (TextUtils.isEmpty(pkgName))
5362 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005363 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5364 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5365 UiccCard card = UiccController.getInstance().getUiccCard(i);
5366 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005367 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005368 continue;
5369 }
5370
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005371 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5372 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5373 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005374 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5375 break;
5376 }
5377 }
5378
5379 return result;
Junda Liu29340342014-07-10 15:23:27 -07005380 }
Derek Tan89e89d42014-07-08 17:00:10 -07005381
5382 @Override
Junda Liue64de782015-04-16 17:19:16 -07005383 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5384 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5385 loge("phoneId " + phoneId + " is not valid.");
5386 return null;
5387 }
5388 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005389 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005390 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005391 return null ;
5392 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005393 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005394 }
5395
Amith Yamasani6e118872016-02-19 12:53:51 -08005396 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005397 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005398 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005399 List<String> privilegedPackages = new ArrayList<>();
5400 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005401 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5402 // has UICC in that slot.
5403 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005404 if (card.hasCarrierPrivilegeRules()) {
5405 if (packages == null) {
5406 // Only check packages in user 0 for now
5407 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005408 PackageManager.MATCH_DISABLED_COMPONENTS
5409 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005410 | PackageManager.GET_SIGNING_CERTIFICATES,
5411 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005412 }
5413 for (int p = packages.size() - 1; p >= 0; p--) {
5414 PackageInfo pkgInfo = packages.get(p);
5415 if (pkgInfo != null && pkgInfo.packageName != null
5416 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005417 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005418 privilegedPackages.add(pkgInfo.packageName);
5419 }
5420 }
5421 }
5422 }
5423 return privilegedPackages;
5424 }
5425
chen xuf7e9fe82019-05-09 19:31:02 -07005426 @Override
5427 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005428 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5429
5430 final long identity = Binder.clearCallingIdentity();
5431
chen xuf7e9fe82019-05-09 19:31:02 -07005432 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005433 try {
5434 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5435 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5436 }
5437 } finally {
5438 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005439 }
5440 return privilegedPackages;
5441 }
5442
Wink Savilleb564aae2014-10-23 10:18:09 -07005443 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005444 final Phone phone = getPhone(subId);
5445 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005446 if (card == null) {
5447 loge("getIccId: No UICC");
5448 return null;
5449 }
5450 String iccId = card.getIccId();
5451 if (TextUtils.isEmpty(iccId)) {
5452 loge("getIccId: ICC ID is null or empty.");
5453 return null;
5454 }
5455 return iccId;
5456 }
5457
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005458 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005459 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5460 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005461 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005462 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 final long identity = Binder.clearCallingIdentity();
5465 try {
5466 final String iccId = getIccId(subId);
5467 final Phone phone = getPhone(subId);
5468 if (phone == null) {
5469 return false;
5470 }
5471 final String subscriberId = phone.getSubscriberId();
5472
5473 if (DBG_MERGE) {
5474 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5475 + subscriberId + " to " + number);
5476 }
5477
5478 if (TextUtils.isEmpty(iccId)) {
5479 return false;
5480 }
5481
5482 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5483
5484 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5485 if (alphaTag == null) {
5486 editor.remove(alphaTagPrefKey);
5487 } else {
5488 editor.putString(alphaTagPrefKey, alphaTag);
5489 }
5490
5491 // Record both the line number and IMSI for this ICCID, since we need to
5492 // track all merged IMSIs based on line number
5493 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5494 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5495 if (number == null) {
5496 editor.remove(numberPrefKey);
5497 editor.remove(subscriberPrefKey);
5498 } else {
5499 editor.putString(numberPrefKey, number);
5500 editor.putString(subscriberPrefKey, subscriberId);
5501 }
5502
5503 editor.commit();
5504 return true;
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005507 }
Derek Tan7226c842014-07-02 17:42:23 -07005508 }
5509
5510 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005511 public String getLine1NumberForDisplay(int subId, String callingPackage,
5512 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005513 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005515 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005516 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005517 return null;
5518 }
Derek Tan97ebb422014-09-05 16:55:38 -07005519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 String iccId = getIccId(subId);
5523 if (iccId != null) {
5524 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5525 if (DBG_MERGE) {
5526 log("getLine1NumberForDisplay returning "
5527 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5528 }
5529 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5532 return null;
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005535 }
Derek Tan7226c842014-07-02 17:42:23 -07005536 }
5537
5538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005539 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5540 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005542 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005543 return null;
5544 }
Derek Tan97ebb422014-09-05 16:55:38 -07005545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 String iccId = getIccId(subId);
5549 if (iccId != null) {
5550 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5551 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5552 }
5553 return null;
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005556 }
Derek Tan7226c842014-07-02 17:42:23 -07005557 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005558
5559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005560 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5561 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005562 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5563 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005565 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005566 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005567 return null;
5568 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005569
Jordan Liub49b04b2019-05-06 14:45:15 -07005570 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5571 // the process, where TelephonyManager was instantiated.
5572 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005573 final long identity = Binder.clearCallingIdentity();
5574 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005575 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 final TelephonyManager tele = TelephonyManager.from(context);
5577 final SubscriptionManager sub = SubscriptionManager.from(context);
5578
5579 // Figure out what subscribers are currently active
5580 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581
Jordan Liub49b04b2019-05-06 14:45:15 -07005582 // Only consider subs which match the current subId
5583 // This logic can be simplified. See b/131189269 for progress.
5584 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005585 activeSubscriberIds.add(tele.getSubscriberId(subId));
5586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587
5588 // First pass, find a number override for an active subscriber
5589 String mergeNumber = null;
5590 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5591 for (String key : prefs.keySet()) {
5592 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5593 final String subscriberId = (String) prefs.get(key);
5594 if (activeSubscriberIds.contains(subscriberId)) {
5595 final String iccId = key.substring(
5596 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5597 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5598 mergeNumber = (String) prefs.get(numberKey);
5599 if (DBG_MERGE) {
5600 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5601 + " for active subscriber " + subscriberId);
5602 }
5603 if (!TextUtils.isEmpty(mergeNumber)) {
5604 break;
5605 }
5606 }
5607 }
5608 }
5609
5610 // Shortcut when no active merged subscribers
5611 if (TextUtils.isEmpty(mergeNumber)) {
5612 return null;
5613 }
5614
5615 // Second pass, find all subscribers under that line override
5616 final ArraySet<String> result = new ArraySet<>();
5617 for (String key : prefs.keySet()) {
5618 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5619 final String number = (String) prefs.get(key);
5620 if (mergeNumber.equals(number)) {
5621 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5622 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5623 final String subscriberId = (String) prefs.get(subscriberKey);
5624 if (!TextUtils.isEmpty(subscriberId)) {
5625 result.add(subscriberId);
5626 }
5627 }
5628 }
5629 }
5630
5631 final String[] resultArray = result.toArray(new String[result.size()]);
5632 Arrays.sort(resultArray);
5633 if (DBG_MERGE) {
5634 Slog.d(LOG_TAG,
5635 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5636 }
5637 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005638 } finally {
5639 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005640 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005641 }
5642
5643 @Override
zoey chen38003472019-12-13 17:16:31 +08005644 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5645 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005646
5647 final long identity = Binder.clearCallingIdentity();
5648 try {
5649 final TelephonyManager telephonyManager = mApp.getSystemService(
5650 TelephonyManager.class);
5651 String subscriberId = telephonyManager.getSubscriberId(subId);
5652 if (subscriberId == null) {
5653 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005654 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005655 + subId);
5656 }
5657 return null;
5658 }
5659
5660 final SubscriptionInfo info = SubscriptionController.getInstance()
5661 .getSubscriptionInfo(subId);
5662 final ParcelUuid groupUuid = info.getGroupUuid();
5663 // If it doesn't belong to any group, return just subscriberId of itself.
5664 if (groupUuid == null) {
5665 return new String[]{subscriberId};
5666 }
5667
5668 // Get all subscriberIds from the group.
5669 final List<String> mergedSubscriberIds = new ArrayList<>();
5670 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005671 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5672 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005673 for (SubscriptionInfo subInfo : groupInfos) {
5674 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5675 if (subscriberId != null) {
5676 mergedSubscriberIds.add(subscriberId);
5677 }
5678 }
5679
5680 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683
5684 }
5685 }
5686
5687 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005688 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005689 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005690 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691
5692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 final Phone phone = getPhone(subId);
5695 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005699 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005700
5701 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005702 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005703 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5704 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005705 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5706 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707
5708 final long identity = Binder.clearCallingIdentity();
5709 try {
5710 final Phone phone = getPhone(subId);
5711 if (phone == null) {
5712 return false;
5713 }
5714 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5715 cdmaNonRoamingList);
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005718 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005719 }
5720
5721 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005722 @Deprecated
5723 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5724 enforceModifyPermission();
5725
5726 int returnValue = 0;
5727 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005728 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005729 if(result.exception == null) {
5730 if (result.result != null) {
5731 byte[] responseData = (byte[])(result.result);
5732 if(responseData.length > oemResp.length) {
5733 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5734 responseData.length + "bytes. Buffer Size is " +
5735 oemResp.length + "bytes.");
5736 }
5737 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5738 returnValue = responseData.length;
5739 }
5740 } else {
5741 CommandException ex = (CommandException) result.exception;
5742 returnValue = ex.getCommandError().ordinal();
5743 if(returnValue > 0) returnValue *= -1;
5744 }
5745 } catch (RuntimeException e) {
5746 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5747 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5748 if(returnValue > 0) returnValue *= -1;
5749 }
5750
5751 return returnValue;
5752 }
5753
5754 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005755 public void setRadioCapability(RadioAccessFamily[] rafs) {
5756 try {
5757 ProxyController.getInstance().setRadioCapability(rafs);
5758 } catch (RuntimeException e) {
5759 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5760 }
5761 }
5762
5763 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005764 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005765 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005766 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005767 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005768 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 final long identity = Binder.clearCallingIdentity();
5771 try {
chen xub97461a2018-10-26 14:17:57 -07005772 TelephonyPermissions
5773 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5774 mApp, phone.getSubId(), "getRadioAccessFamily");
5775 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
chen xub97461a2018-10-26 14:17:57 -07005779 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005780 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005781
5782 @Override
5783 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005784 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005785 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005789 ImsManager.getInstance(defaultPhone.getContext(),
5790 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 } finally {
5792 Binder.restoreCallingIdentity(identity);
5793 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005794 }
5795
5796 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005797 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005798 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5800 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005801 return false;
5802 }
Svet Ganovb320e182015-04-16 12:30:10 -07005803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 final long identity = Binder.clearCallingIdentity();
5805 try {
5806 // Check the user preference and the system-level IMS setting. Even if the user has
5807 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5808 // In the long run, we may instead need to check if there exists a connection service
5809 // which can support video calling.
5810 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005811 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 return imsManager.isVtEnabledByPlatform()
5813 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5814 && imsManager.isVtEnabledByUser();
5815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005818 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005819
Andrew Leea1239f22015-03-02 17:44:07 -08005820 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005821 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5822 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005824 mApp, subId, callingPackage, callingFeatureId,
5825 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 return false;
5827 }
5828
5829 final long identity = Binder.clearCallingIdentity();
5830 try {
5831 CarrierConfigManager configManager =
5832 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005833 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5835 } finally {
5836 Binder.restoreCallingIdentity(identity);
5837 }
Andrew Leea1239f22015-03-02 17:44:07 -08005838 }
5839
5840 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005841 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005843 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 return false;
5845 }
5846
5847 final long identity = Binder.clearCallingIdentity();
5848 try {
5849 CarrierConfigManager configManager =
5850 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005851 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5853 } finally {
5854 Binder.restoreCallingIdentity(identity);
5855 }
Andrew Leea1239f22015-03-02 17:44:07 -08005856 }
5857
Andrew Lee9431b832015-03-09 18:46:45 -07005858 @Override
5859 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005860 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005861 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005862 }
5863
5864 @Override
5865 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 final long identity = Binder.clearCallingIdentity();
5867 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005868 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
Andrew Lee9431b832015-03-09 18:46:45 -07005872 }
5873
Hall Liuf6668912018-10-31 17:05:23 -07005874 /**
5875 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5876 * support for the feature and device firmware support.
5877 *
5878 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5879 */
5880 @Override
5881 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005883 final Phone phone = getPhone(subscriptionId);
5884 if (phone == null) {
5885 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5886 return false;
5887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005889 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5891 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005892 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 return isCarrierSupported && isDeviceSupported;
5894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
Hall Liu98187582018-01-22 19:15:32 -08005897 }
5898
Hall Liuf6668912018-10-31 17:05:23 -07005899 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005900 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5901 * RTT setting, will return true if the device and carrier both support RTT.
5902 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005903 */
5904 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905 final long identity = Binder.clearCallingIdentity();
5906 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005907 boolean isRttSupported = isRttSupported(subscriptionId);
5908 boolean isUserRttSettingOn = Settings.Secure.getInt(
5909 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5910 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5911 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5912 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005916 }
5917
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005918 @Deprecated
5919 @Override
5920 public String getDeviceId(String callingPackage) {
5921 return getDeviceIdWithFeature(callingPackage, null);
5922 }
5923
Sanket Padawe7310cc72015-01-14 09:53:20 -08005924 /**
5925 * Returns the unique device ID of phone, for example, the IMEI for
5926 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5927 *
5928 * <p>Requires Permission:
5929 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5930 */
5931 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005932 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005933 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005934 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005935 return null;
5936 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005937 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005938 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005939 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005940 return null;
5941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942
5943 final long identity = Binder.clearCallingIdentity();
5944 try {
5945 return phone.getDeviceId();
5946 } finally {
5947 Binder.restoreCallingIdentity(identity);
5948 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005949 }
5950
Ping Sunc67b7c22016-03-02 19:16:45 +08005951 /**
5952 * {@hide}
5953 * Returns the IMS Registration Status on a particular subid
5954 *
5955 * @param subId
5956 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005957 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005958 Phone phone = getPhone(subId);
5959 if (phone != null) {
5960 return phone.isImsRegistered();
5961 } else {
5962 return false;
5963 }
5964 }
5965
Santos Cordon7a1885b2015-02-03 11:15:19 -08005966 @Override
5967 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005974 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005975
Tyler Gunnf70ed162019-04-03 15:28:53 -07005976 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005977 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005978 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005980 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005981 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5982 }
5983 final long identity = Binder.clearCallingIdentity();
5984 try {
5985 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5986 } finally {
5987 Binder.restoreCallingIdentity(identity);
5988 }
5989 }
5990
5991 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005992 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5993 final long identity = Binder.clearCallingIdentity();
5994 try {
5995 Phone phone = getPhone(subscriptionId);
5996 if (phone == null) {
5997 return null;
5998 }
5999 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6000 } finally {
6001 Binder.restoreCallingIdentity(identity);
6002 }
6003 }
6004
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006005 /**
6006 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006007 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006008 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 final long identity = Binder.clearCallingIdentity();
6010 try {
6011 Phone phone = getPhone(subId);
6012 if (phone != null) {
6013 return phone.isWifiCallingEnabled();
6014 } else {
6015 return false;
6016 }
6017 } finally {
6018 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006019 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006020 }
6021
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006022 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006023 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006024 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006025 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 final long identity = Binder.clearCallingIdentity();
6027 try {
6028 Phone phone = getPhone(subId);
6029 if (phone != null) {
6030 return phone.isVideoEnabled();
6031 } else {
6032 return false;
6033 }
6034 } finally {
6035 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006036 }
6037 }
6038
6039 /**
6040 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6041 * defined in {@link ImsRegistrationImplBase}.
6042 */
6043 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 final long identity = Binder.clearCallingIdentity();
6045 try {
6046 Phone phone = getPhone(subId);
6047 if (phone != null) {
6048 return phone.getImsRegistrationTech();
6049 } else {
6050 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6051 }
6052 } finally {
6053 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006054 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006055 }
6056
Stuart Scott8eef64f2015-04-08 15:13:54 -07006057 @Override
6058 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006059 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006060 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6061 return;
6062 }
6063
Svet Ganovcc087f82015-05-12 20:35:54 -07006064 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006065
Svet Ganovcc087f82015-05-12 20:35:54 -07006066 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006067 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6068 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006069 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006070 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006071 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006072 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6073 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006074 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006075 // There has been issues when Sms raw table somehow stores orphan
6076 // fragments. They lead to garbled message when new fragments come
6077 // in and combined with those stale ones. In case this happens again,
6078 // user can reset all network settings which will clean up this table.
6079 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006080 // Clean up IMS settings as well here.
6081 int slotId = getSlotIndex(subId);
6082 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6083 ImsManager.getInstance(mApp, slotId).factoryReset();
6084 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006085
6086 // Erase modem config if erase modem on network setting is enabled.
6087 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6088 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6089 if (configValue != null && Boolean.parseBoolean(configValue)) {
6090 sendEraseModemConfig(getDefaultPhone());
6091 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006092 } finally {
6093 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006094 }
6095 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006096
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006097 private void cleanUpSmsRawTable(Context context) {
6098 ContentResolver resolver = context.getContentResolver();
6099 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6100 resolver.delete(uri, null, null);
6101 }
6102
Narayan Kamath1c496c22015-04-16 14:40:19 +01006103 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006104 public String getSimLocaleForSubscriber(int subId) {
6105 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6106 final Phone phone = getPhone(subId);
6107 if (phone == null) {
6108 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006109 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 final long identity = Binder.clearCallingIdentity();
6112 try {
chen xu5d3637b2019-01-21 23:31:38 -08006113 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006114 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006115 if (info == null) {
6116 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6117 return null;
6118 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119 // Try and fetch the locale from the carrier properties or from the SIM language
6120 // preferences (EF-PL and EF-LI)...
6121 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006123 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6124 if (localeFromDefaultSim != null) {
6125 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6126 if (DBG) log("Using locale from subId: " + subId + " locale: "
6127 + localeFromDefaultSim);
6128 return localeFromDefaultSim.toLanguageTag();
6129 } else {
6130 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 }
6132 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 // The SIM language preferences only store a language (e.g. fr = French), not an
6135 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6136 // the SIM and carrier preferences does not include a country we add the country
6137 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006138 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006140 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 return mccLocale.toLanguageTag();
6142 }
6143
6144 if (DBG) log("No locale found - returning null");
6145 return null;
6146 } finally {
6147 Binder.restoreCallingIdentity(identity);
6148 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006149 }
6150
6151 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006152 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6153 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006154 }
6155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 /**
6157 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6158 */
6159 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006160 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6161 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006162 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006163
Chenjie Yu1ba97252018-01-11 18:16:20 -08006164 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006165 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006166
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006167 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006168 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6169 * representing the state of the modem.
6170 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006171 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6172 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006173 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006174 */
6175 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006176 public void requestModemActivityInfo(ResultReceiver result) {
6177 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006178 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179
6180 final long identity = Binder.clearCallingIdentity();
6181 try {
6182 ModemActivityInfo ret = null;
6183 synchronized (mLastModemActivityInfo) {
6184 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6185 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006186 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006187 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006189 int[] txTimeMs = info.getTransmitTimeMillis();
6190 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006191 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006192 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 }
6194 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006195 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6196 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 mLastModemActivityInfo.setIdleTimeMillis(
6198 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006199 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6200 mLastModemActivityInfo.setReceiveTimeMillis(
6201 info.getReceiveTimeMillis() + mLastModemActivityInfo
6202 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006203 }
Chen Xud78231e2019-09-10 18:49:52 -07006204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6206 mLastModemActivityInfo.getSleepTimeMillis(),
6207 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006208 mLastModemActivityInfo.getTransmitTimeMillis(),
6209 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211 Bundle bundle = new Bundle();
6212 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6213 result.send(0, bundle);
6214 } finally {
6215 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006216 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006217 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006218
Siddharth Rayb8114062018-06-17 15:02:38 -07006219 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6220 // less than total activity duration.
6221 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6222 if (info == null) {
6223 return false;
6224 }
6225 int activityDurationMs =
6226 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6227 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006228 int[] txTimeMs = info.getTransmitTimeMillis();
6229 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6230 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006231 }
6232 return (info.isValid()
6233 && (info.getSleepTimeMillis() <= activityDurationMs)
6234 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006235 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006236 && (totalTxTimeMs <= activityDurationMs));
6237 }
6238
Jack Yu85bd38a2015-11-09 11:34:32 -08006239 /**
6240 * {@hide}
6241 * Returns the service state information on specified subscription.
6242 */
6243 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006244 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6245 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006247 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006248 return null;
6249 }
6250
Hall Liuf19c44f2018-11-27 14:38:17 -08006251 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6252 LocationAccessPolicy.checkLocationPermission(mApp,
6253 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6254 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006255 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006256 .setCallingPid(Binder.getCallingPid())
6257 .setCallingUid(Binder.getCallingUid())
6258 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006259 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006260 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6261 .build());
6262
6263 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6264 LocationAccessPolicy.checkLocationPermission(mApp,
6265 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6266 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006267 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006268 .setCallingPid(Binder.getCallingPid())
6269 .setCallingUid(Binder.getCallingUid())
6270 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006271 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006272 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6273 .build());
6274 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6275 boolean hasFinePermission =
6276 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6277 boolean hasCoarsePermission =
6278 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 final long identity = Binder.clearCallingIdentity();
6281 try {
6282 final Phone phone = getPhone(subId);
6283 if (phone == null) {
6284 return null;
6285 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006286
Hall Liuf19c44f2018-11-27 14:38:17 -08006287 ServiceState ss = phone.getServiceState();
6288
6289 // Scrub out the location info in ServiceState depending on what level of access
6290 // the caller has.
6291 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006292 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6293 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 } finally {
6295 Binder.restoreCallingIdentity(identity);
6296 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006297 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006298
6299 /**
6300 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6301 *
6302 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6303 * voicemail ringtone.
6304 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6305 * PhoneAccount.
6306 */
6307 @Override
6308 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 final long identity = Binder.clearCallingIdentity();
6310 try {
6311 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6312 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006313 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006320 }
6321
6322 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006323 * Sets the per-account voicemail ringtone.
6324 *
6325 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6326 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6327 *
6328 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6329 * voicemail ringtone.
6330 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6331 * PhoneAccount.
6332 */
6333 @Override
6334 public void setVoicemailRingtoneUri(String callingPackage,
6335 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006336 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006338 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6339 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6341 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6342 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344
6345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6348 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006349 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350 }
6351 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6352 } finally {
6353 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006354 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006355 }
6356
6357 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006358 * Returns whether vibration is set for voicemail notification in Phone settings.
6359 *
6360 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6361 * voicemail vibration setting.
6362 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6363 */
6364 @Override
6365 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006366 final long identity = Binder.clearCallingIdentity();
6367 try {
6368 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6369 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006370 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6374 } finally {
6375 Binder.restoreCallingIdentity(identity);
6376 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006377 }
6378
Youhan Wange64578a2016-05-02 15:32:42 -07006379 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006380 * Sets the per-account voicemail vibration.
6381 *
6382 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6383 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6384 *
6385 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6386 * voicemail vibration setting.
6387 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6388 * specific PhoneAccount.
6389 */
6390 @Override
6391 public void setVoicemailVibrationEnabled(String callingPackage,
6392 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006393 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006394 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006395 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6396 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6398 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6399 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006400 }
6401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 final long identity = Binder.clearCallingIdentity();
6403 try {
6404 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6405 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006406 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 }
6408 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006411 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006412 }
6413
6414 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006415 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6416 *
6417 * @throws SecurityException if the caller does not have the required permission
6418 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006419 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006420 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006421 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006422 }
6423
6424 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006425 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6426 * permission.
6427 *
6428 * @throws SecurityException if the caller does not have the required permission
6429 */
6430 private void enforceSendSmsPermission() {
6431 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6432 }
6433
6434 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006435 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006436 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006437 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006438 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006439 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 final long identity = Binder.clearCallingIdentity();
6441 try {
6442 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006443 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444 if (componentName == null) {
6445 throw new SecurityException(
6446 "Caller not current active visual voicemail package[null]");
6447 }
6448 String vvmPackage = componentName.getPackageName();
6449 if (!callingPackage.equals(vvmPackage)) {
6450 throw new SecurityException("Caller not current active visual voicemail package["
6451 + vvmPackage + "]");
6452 }
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006455 }
6456 }
6457
6458 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006459 * Return the application ID for the app type.
6460 *
6461 * @param subId the subscription ID that this request applies to.
6462 * @param appType the uicc app type.
6463 * @return Application ID for specificied app type, or null if no uicc.
6464 */
6465 @Override
6466 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006467 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006468 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469
6470 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006471 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 if (phone == null) {
6473 return null;
6474 }
6475 String aid = null;
6476 try {
6477 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6478 .getApplicationByType(appType).getAid();
6479 } catch (Exception e) {
6480 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6481 }
6482 return aid;
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006485 }
Youhan Wange64578a2016-05-02 15:32:42 -07006486 }
6487
Youhan Wang4001d252016-05-11 10:29:41 -07006488 /**
6489 * Return the Electronic Serial Number.
6490 *
6491 * @param subId the subscription ID that this request applies to.
6492 * @return ESN or null if error.
6493 */
6494 @Override
6495 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006496 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006497 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498
6499 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006500 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501 if (phone == null) {
6502 return null;
6503 }
6504 String esn = null;
6505 try {
6506 esn = phone.getEsn();
6507 } catch (Exception e) {
6508 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6509 }
6510 return esn;
6511 } finally {
6512 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006513 }
Youhan Wang4001d252016-05-11 10:29:41 -07006514 }
6515
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006516 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006517 * Return the Preferred Roaming List Version.
6518 *
6519 * @param subId the subscription ID that this request applies to.
6520 * @return PRLVersion or null if error.
6521 */
6522 @Override
6523 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006524 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006525 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526
6527 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006528 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 if (phone == null) {
6530 return null;
6531 }
6532 String cdmaPrlVersion = null;
6533 try {
6534 cdmaPrlVersion = phone.getCdmaPrlVersion();
6535 } catch (Exception e) {
6536 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6537 }
6538 return cdmaPrlVersion;
6539 } finally {
6540 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006541 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006542 }
6543
6544 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006545 * Get snapshot of Telephony histograms
6546 * @return List of Telephony histograms
6547 * @hide
6548 */
6549 @Override
6550 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6552 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553
6554 final long identity = Binder.clearCallingIdentity();
6555 try {
6556 return RIL.getTelephonyRILTimingHistograms();
6557 } finally {
6558 Binder.restoreCallingIdentity(identity);
6559 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006560 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006561
6562 /**
6563 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006564 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6565 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006566 * Require system privileges. In the future we may add this to carrier APIs.
6567 *
Michele Berionne482f8202018-11-27 18:57:59 -08006568 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006569 */
6570 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006571 @TelephonyManager.SetCarrierRestrictionResult
6572 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006573 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006574 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006575
Michele Berionne482f8202018-11-27 18:57:59 -08006576 if (carrierRestrictionRules == null) {
6577 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006578 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 final long identity = Binder.clearCallingIdentity();
6581 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006582 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006583 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 } finally {
6585 Binder.restoreCallingIdentity(identity);
6586 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006587 }
6588
6589 /**
6590 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006591 * Get the allowed carrier list and the excluded carrier list, including the priority between
6592 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006593 * Require system privileges. In the future we may add this to carrier APIs.
6594 *
Michele Berionne482f8202018-11-27 18:57:59 -08006595 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006596 */
6597 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006598 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006599 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006600 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006604 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6605 if (response instanceof CarrierRestrictionRules) {
6606 return (CarrierRestrictionRules) response;
6607 }
6608 // Response is an Exception of some kind,
6609 // which is signalled to the user as a NULL retval
6610 return null;
6611 } catch (Exception e) {
6612 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6613 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006617 }
6618
fionaxu59545b42016-05-25 15:53:37 -07006619 /**
6620 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6621 * @param subId the subscription ID that this action applies to.
6622 * @param enabled control enable or disable metered apns.
6623 * {@hide}
6624 */
6625 @Override
6626 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6627 enforceModifyPermission();
6628 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629
6630 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006631 if (phone == null) {
6632 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6633 return;
6634 }
6635 try {
6636 phone.carrierActionSetMeteredApnsEnabled(enabled);
6637 } catch (Exception e) {
6638 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 } finally {
6640 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006641 }
6642 }
6643
6644 /**
6645 * Action set from carrier signalling broadcast receivers to enable/disable radio
6646 * @param subId the subscription ID that this action applies to.
6647 * @param enabled control enable or disable radio.
6648 * {@hide}
6649 */
6650 @Override
6651 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6652 enforceModifyPermission();
6653 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654
6655 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006656 if (phone == null) {
6657 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6658 return;
6659 }
6660 try {
6661 phone.carrierActionSetRadioEnabled(enabled);
6662 } catch (Exception e) {
6663 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664 } finally {
6665 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006666 }
6667 }
6668
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006669 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006670 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6671 * network status based on which carrier apps could apply actions accordingly,
6672 * enable/disable default url handler for example.
6673 *
6674 * @param subId the subscription ID that this action applies to.
6675 * @param report control start/stop reporting the default network status.
6676 * {@hide}
6677 */
6678 @Override
6679 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6680 enforceModifyPermission();
6681 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006682
6683 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006684 if (phone == null) {
6685 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6686 return;
6687 }
6688 try {
6689 phone.carrierActionReportDefaultNetworkStatus(report);
6690 } catch (Exception e) {
6691 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 } finally {
6693 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006694 }
6695 }
6696
6697 /**
fionaxud9622282017-07-17 17:51:30 -07006698 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6699 * @param subId the subscription ID that this action applies to.
6700 * {@hide}
6701 */
6702 @Override
6703 public void carrierActionResetAll(int subId) {
6704 enforceModifyPermission();
6705 final Phone phone = getPhone(subId);
6706 if (phone == null) {
6707 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6708 return;
6709 }
6710 try {
6711 phone.carrierActionResetAll();
6712 } catch (Exception e) {
6713 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6714 }
6715 }
6716
6717 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006718 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6719 * bug report is being generated.
6720 */
6721 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006722 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006723 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6724 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006725 writer.println("Permission Denial: can't dump Phone from pid="
6726 + Binder.getCallingPid()
6727 + ", uid=" + Binder.getCallingUid()
6728 + "without permission "
6729 + android.Manifest.permission.DUMP);
6730 return;
6731 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006732 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006733 }
Jack Yueb89b242016-06-22 13:27:47 -07006734
Brad Ebingerdac2f002018-04-03 15:17:52 -07006735 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006736 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6737 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6738 @NonNull String[] args) {
6739 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6740 this, in.getFileDescriptor(), out.getFileDescriptor(),
6741 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006742 }
6743
Jack Yueb89b242016-06-22 13:27:47 -07006744 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006745 * Get aggregated video call data usage since boot.
6746 *
6747 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6748 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006749 * {@hide}
6750 */
6751 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006752 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006753 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6754 null);
6755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 final long identity = Binder.clearCallingIdentity();
6757 try {
6758 // NetworkStatsService keeps tracking the active network interface and identity. It
6759 // records the delta with the corresponding network identity.
6760 // We just return the total video call data usage snapshot since boot.
6761 Phone phone = getPhone(subId);
6762 if (phone != null) {
6763 return phone.getVtDataUsage(perUidStats);
6764 }
6765 return null;
6766 } finally {
6767 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006768 }
Jack Yueb89b242016-06-22 13:27:47 -07006769 }
Jack Yu75ab2952016-07-08 14:29:33 -07006770
6771 /**
6772 * Policy control of data connection. Usually used when data limit is passed.
6773 * @param enabled True if enabling the data, otherwise disabling.
6774 * @param subId Subscription index
6775 * {@hide}
6776 */
6777 @Override
6778 public void setPolicyDataEnabled(boolean enabled, int subId) {
6779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780
6781 final long identity = Binder.clearCallingIdentity();
6782 try {
6783 Phone phone = getPhone(subId);
6784 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006785 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 }
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006789 }
6790 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006791
6792 /**
6793 * Get Client request stats
6794 * @return List of Client Request Stats
6795 * @hide
6796 */
6797 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006798 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6799 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006801 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006802 return null;
6803 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006804 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 if (phone != null) {
6809 return phone.getClientRequestStats();
6810 }
6811
6812 return null;
6813 } finally {
6814 Binder.restoreCallingIdentity(identity);
6815 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006816 }
6817
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006818 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006819 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006820 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006821 }
Jack Yueb4124c2017-02-16 15:32:43 -08006822
6823 /**
Grace Chen70990072017-03-24 17:21:30 -07006824 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006825 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006826 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006827 * @param state State of SIM (power down, power up, pass through)
6828 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6829 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6830 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006831 *
6832 **/
6833 @Override
Grace Chen70990072017-03-24 17:21:30 -07006834 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006835 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006836 Phone phone = PhoneFactory.getPhone(slotIndex);
6837
vagdeviaf9a5b92018-08-15 16:01:53 -07006838 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 final long identity = Binder.clearCallingIdentity();
6841 try {
6842 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006843 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844 }
6845 } finally {
6846 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006847 }
6848 }
Shuo Qiandd210312017-04-12 22:11:33 +00006849
Tyler Gunn65d45c22017-06-05 11:22:26 -07006850 private boolean isUssdApiAllowed(int subId) {
6851 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006852 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006853 if (configManager == null) {
6854 return false;
6855 }
6856 PersistableBundle pb = configManager.getConfigForSubId(subId);
6857 if (pb == null) {
6858 return false;
6859 }
6860 return pb.getBoolean(
6861 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6862 }
6863
Shuo Qiandd210312017-04-12 22:11:33 +00006864 /**
6865 * Check if phone is in emergency callback mode
6866 * @return true if phone is in emergency callback mode
6867 * @param subId sub id
6868 */
goneil9c5f4872017-12-05 14:07:56 -08006869 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006870 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006871 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006872 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 if (phone != null) {
6877 return phone.isInEcm();
6878 } else {
6879 return false;
6880 }
6881 } finally {
6882 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006883 }
6884 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006885
6886 /**
6887 * Get the current signal strength information for the given subscription.
6888 * Because this information is not updated when the device is in a low power state
6889 * it should not be relied-upon to be current.
6890 * @param subId Subscription index
6891 * @return the most recent cached signal strength info from the modem
6892 */
6893 @Override
6894 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 final long identity = Binder.clearCallingIdentity();
6896 try {
6897 Phone p = getPhone(subId);
6898 if (p == null) {
6899 return null;
6900 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 return p.getSignalStrength();
6903 } finally {
6904 Binder.restoreCallingIdentity(identity);
6905 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006906 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006907
Pengquan Meng77b7f132018-08-22 14:49:57 -07006908 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006909 * Get the current modem radio state for the given slot.
6910 * @param slotIndex slot index.
6911 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006912 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006913 * @return the current radio power state from the modem
6914 */
6915 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006916 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006917 Phone phone = PhoneFactory.getPhone(slotIndex);
6918 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6920 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006921 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6922 }
6923
6924 final long identity = Binder.clearCallingIdentity();
6925 try {
6926 return phone.getRadioPowerState();
6927 } finally {
6928 Binder.restoreCallingIdentity(identity);
6929 }
6930 }
6931 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6932 }
6933
6934 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006935 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6936 *
6937 * <p>Requires one of the following permissions:
6938 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6939 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6940 * privileges.
6941 *
6942 * @param subId subscription id
6943 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6944 * {@code false}.
6945 */
6946 @Override
6947 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006948 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6949 null /* message */);
6950
Pengquan Menga1bb6272018-09-06 09:59:22 -07006951 boolean isEnabled = false;
6952 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006953 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006954 Phone phone = getPhone(subId);
6955 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006956 } catch (Exception e) {
6957 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6958 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006959 } finally {
6960 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006961 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006962 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006963 }
6964
6965
6966 /**
6967 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6968 *
6969 * <p> Requires permission:
6970 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6971 * privileges.
6972 *
6973 * @param subId subscription id
6974 * @param isEnabled {@code true} means enable, {@code false} means disable.
6975 */
6976 @Override
6977 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6979 mApp, subId, "setDataRoamingEnabled");
6980
Pengquan Menga1bb6272018-09-06 09:59:22 -07006981 final long identity = Binder.clearCallingIdentity();
6982 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006983 Phone phone = getPhone(subId);
6984 if (phone != null) {
6985 phone.setDataRoamingEnabled(isEnabled);
6986 }
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006989 }
6990 }
6991
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006992 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006993 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006994 TelephonyPermissions
6995 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006996 mApp, subId, "isManualNetworkSelectionAllowed");
6997
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006998 boolean isAllowed = true;
6999 final long identity = Binder.clearCallingIdentity();
7000 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007001 Phone phone = getPhone(subId);
7002 if (phone != null) {
7003 isAllowed = phone.isCspPlmnEnabled();
7004 }
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
7008 return isAllowed;
7009 }
7010
7011 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007012 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007013 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007014 try {
7015 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007016 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007017 } catch (SecurityException e) {
7018 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7019 // has carrier privileges on an active UICC
7020 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7021 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007022 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007023 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007024 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007025
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007028 UiccController uiccController = UiccController.getInstance();
7029 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007030 if (hasReadPermission) {
7031 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007032 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007033
7034 // Remove private info if the caller doesn't have access
7035 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7036 for (UiccCardInfo cardInfo : cardInfos) {
7037 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7038 // is available
7039 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7040 if (card == null || card.getUiccProfile() == null) {
7041 // assume no access if the card or profile is unavailable
7042 filteredInfos.add(cardInfo.getUnprivileged());
7043 continue;
7044 }
7045 UiccProfile profile = card.getUiccProfile();
7046 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7047 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7048 filteredInfos.add(cardInfo);
7049 } else {
7050 filteredInfos.add(cardInfo.getUnprivileged());
7051 }
7052 }
7053 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007054 } finally {
7055 Binder.restoreCallingIdentity(identity);
7056 }
7057 }
7058
7059 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007060 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007061 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 final long identity = Binder.clearCallingIdentity();
7064 try {
7065 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7066 if (slots == null) {
7067 Rlog.i(LOG_TAG, "slots is null.");
7068 return null;
7069 }
7070
7071 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7072 for (int i = 0; i < slots.length; i++) {
7073 UiccSlot slot = slots[i];
7074 if (slot == null) {
7075 continue;
7076 }
7077
Jordan Liu7be7e652019-05-06 18:55:02 +00007078 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 UiccCard card = slot.getUiccCard();
7080 if (card != null) {
7081 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007082 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007083 cardId = slot.getEid();
7084 if (TextUtils.isEmpty(cardId)) {
7085 cardId = slot.getIccId();
7086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 }
7088
Jordan Liu857451f2019-05-09 16:35:35 -07007089 if (cardId != null) {
7090 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7091 // if cardId is an EID, it's all digits so this is fine
7092 cardId = IccUtils.stripTrailingFs(cardId);
7093 }
7094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 int cardState = 0;
7096 switch (slot.getCardState()) {
7097 case CARDSTATE_ABSENT:
7098 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7099 break;
7100 case CARDSTATE_PRESENT:
7101 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7102 break;
7103 case CARDSTATE_ERROR:
7104 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7105 break;
7106 case CARDSTATE_RESTRICTED:
7107 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7108 break;
7109 default:
7110 break;
7111
7112 }
7113
7114 infos[i] = new UiccSlotInfo(
7115 slot.isActive(),
7116 slot.isEuicc(),
7117 cardId,
7118 cardState,
7119 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007120 slot.isExtendedApduSupported(),
7121 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 }
7123 return infos;
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007126 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007127 }
7128
7129 @Override
7130 public boolean switchSlots(int[] physicalSlots) {
7131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007132
7133 final long identity = Binder.clearCallingIdentity();
7134 try {
7135 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007139 }
Jack Yu4c988042018-02-27 15:30:01 -08007140
7141 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007142 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007143 final long identity = Binder.clearCallingIdentity();
7144 try {
7145 return UiccController.getInstance().getCardIdForDefaultEuicc();
7146 } finally {
7147 Binder.restoreCallingIdentity(identity);
7148 }
7149 }
7150
7151 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007152 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7153 enforceModifyPermission();
7154 final Phone phone = getPhone(subId);
7155 if (phone == null) {
7156 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7157 return;
7158 }
7159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 final long identity = Binder.clearCallingIdentity();
7161 try {
7162 phone.setRadioIndicationUpdateMode(filters, mode);
7163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
Jack Yu4c988042018-02-27 15:30:01 -08007166 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007167
7168 /**
goneil47ffb6e2018-04-06 15:40:58 -07007169 * A test API to reload the UICC profile.
7170 *
7171 * <p>Requires that the calling app has permission
7172 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7173 * @hide
7174 */
7175 @Override
7176 public void refreshUiccProfile(int subId) {
7177 enforceModifyPermission();
7178
7179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 Phone phone = getPhone(subId);
7182 if (phone == null) {
7183 return;
7184 }
7185 UiccCard uiccCard = phone.getUiccCard();
7186 if (uiccCard == null) {
7187 return;
7188 }
7189 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7190 if (uiccProfile == null) {
7191 return;
7192 }
7193 uiccProfile.refresh();
7194 } finally {
7195 Binder.restoreCallingIdentity(identity);
7196 }
7197 }
7198
7199 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007200 * Returns false if the mobile data is disabled by default, otherwise return true.
7201 */
7202 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007203 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007204 }
7205
7206 /**
7207 * Returns true if the data roaming is enabled by default, i.e the system property
7208 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7209 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7210 */
7211 private boolean getDefaultDataRoamingEnabled(int subId) {
7212 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007213 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007214 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007215 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7216 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7217 return isDataRoamingEnabled;
7218 }
7219
7220 /**
7221 * Returns the default network type for the given {@code subId}, if the default network type is
7222 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7223 */
7224 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007225 List<Integer> list = TelephonyProperties.default_network();
7226 int phoneId = mSubscriptionController.getPhoneId(subId);
7227 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7228 return list.get(phoneId);
7229 }
7230 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007231 }
fionaxua13278b2018-03-21 00:08:13 -07007232
7233 @Override
7234 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007235 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007236 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 final Phone phone = getPhone(subId);
7241 if (phone == null) {
7242 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7243 return;
7244 }
chen xueaba88a2019-03-15 13:15:10 -07007245 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7246 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247 } finally {
7248 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007249 }
fionaxua13278b2018-03-21 00:08:13 -07007250 }
7251
7252 @Override
7253 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007254 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255
7256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 final Phone phone = getPhone(subId);
7259 if (phone == null) {
7260 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7261 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7262 }
7263 return phone.getCarrierIdListVersion();
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007266 }
fionaxua13278b2018-03-21 00:08:13 -07007267 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007268
7269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007270 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7271 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007273 mApp, subId, callingPackage, callingFeatureId,
7274 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007275 return -1;
7276 }
7277
7278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
7283 }
7284 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007285
7286 @Override
7287 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007288 TelephonyPermissions
7289 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007290 mApp, subId, "getCdmaRoamingMode");
7291
7292 final long identity = Binder.clearCallingIdentity();
7293 try {
7294 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7295 } finally {
7296 Binder.restoreCallingIdentity(identity);
7297 }
7298 }
7299
7300 @Override
7301 public boolean setCdmaRoamingMode(int subId, int mode) {
7302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7303 mApp, subId, "setCdmaRoamingMode");
7304
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7308 } finally {
7309 Binder.restoreCallingIdentity(identity);
7310 }
7311 }
7312
7313 @Override
7314 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7316 mApp, subId, "setCdmaSubscriptionMode");
7317
7318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
7324 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007325
sqianc5eccab2018-10-19 18:46:41 -07007326 @Override
sqian8c685422019-02-22 15:55:18 -08007327 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007328 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007330 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7331 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007332 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7333 }
7334 final long identity = Binder.clearCallingIdentity();
7335 try {
sqian854d44b2018-12-12 16:48:18 -08007336 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7337 for (Phone phone: PhoneFactory.getPhones()) {
7338 if (phone.getEmergencyNumberTracker() != null
7339 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7340 emergencyNumberListInternal.put(
7341 phone.getSubId(),
7342 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7343 }
sqian11b7a0e2018-12-05 18:48:28 -08007344 }
sqian854d44b2018-12-12 16:48:18 -08007345 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007346 } finally {
7347 Binder.restoreCallingIdentity(identity);
7348 }
sqianc5eccab2018-10-19 18:46:41 -07007349 }
7350
7351 @Override
sqian8c685422019-02-22 15:55:18 -08007352 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007353 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007354 if (!exactMatch) {
7355 TelephonyPermissions
7356 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007357 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007358 }
7359 final long identity = Binder.clearCallingIdentity();
7360 try {
sqian854d44b2018-12-12 16:48:18 -08007361 for (Phone phone: PhoneFactory.getPhones()) {
7362 if (phone.getEmergencyNumberTracker() != null
7363 && phone.getEmergencyNumberTracker() != null) {
7364 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7365 number, exactMatch)) {
7366 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007367 }
7368 }
sqian11b7a0e2018-12-05 18:48:28 -08007369 }
7370 return false;
7371 } finally {
7372 Binder.restoreCallingIdentity(identity);
7373 }
7374 }
7375
sqianf4ca7ed2019-01-15 18:32:07 -08007376 /**
7377 * Update emergency number list for test mode.
7378 */
7379 @Override
7380 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7381 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7382 "updateEmergencyNumberListTestMode");
7383
7384 final long identity = Binder.clearCallingIdentity();
7385 try {
7386 for (Phone phone: PhoneFactory.getPhones()) {
7387 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7388 if (tracker != null) {
7389 tracker.executeEmergencyNumberTestModeCommand(action, num);
7390 }
7391 }
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
7395 }
7396
7397 /**
7398 * Get the full emergency number list for test mode.
7399 */
7400 @Override
7401 public List<String> getEmergencyNumberListTestMode() {
7402 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7403 "getEmergencyNumberListTestMode");
7404
7405 final long identity = Binder.clearCallingIdentity();
7406 try {
7407 Set<String> emergencyNumbers = new HashSet<>();
7408 for (Phone phone: PhoneFactory.getPhones()) {
7409 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7410 if (tracker != null) {
7411 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7412 emergencyNumbers.add(num.getNumber());
7413 }
7414 }
7415 }
7416 return new ArrayList<>(emergencyNumbers);
7417 } finally {
7418 Binder.restoreCallingIdentity(identity);
7419 }
7420 }
7421
chen xud6b45bd2018-10-30 22:27:10 -07007422 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007423 public int getEmergencyNumberDbVersion(int subId) {
7424 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7425
7426 final long identity = Binder.clearCallingIdentity();
7427 try {
7428 final Phone phone = getPhone(subId);
7429 if (phone == null) {
7430 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7431 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7432 }
7433 return phone.getEmergencyNumberDbVersion();
7434 } finally {
7435 Binder.restoreCallingIdentity(identity);
7436 }
7437 }
7438
7439 @Override
7440 public void notifyOtaEmergencyNumberDbInstalled() {
7441 enforceModifyPermission();
7442
7443 final long identity = Binder.clearCallingIdentity();
7444 try {
7445 for (Phone phone: PhoneFactory.getPhones()) {
7446 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7447 if (tracker != null) {
7448 tracker.updateOtaEmergencyNumberDatabase();
7449 }
7450 }
7451 } finally {
7452 Binder.restoreCallingIdentity(identity);
7453 }
7454 }
7455
7456 @Override
7457 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7458 enforceActiveEmergencySessionPermission();
7459
7460 final long identity = Binder.clearCallingIdentity();
7461 try {
7462 for (Phone phone: PhoneFactory.getPhones()) {
7463 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7464 if (tracker != null) {
7465 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7466 }
7467 }
7468 } finally {
7469 Binder.restoreCallingIdentity(identity);
7470 }
7471 }
7472
7473 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007474 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7475 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7476 Phone phone = getPhone(subId);
7477 if (phone == null) {
7478 return null;
7479 }
7480 final long identity = Binder.clearCallingIdentity();
7481 try {
7482 UiccProfile profile = UiccController.getInstance()
7483 .getUiccProfileForPhone(phone.getPhoneId());
7484 if (profile != null) {
7485 return profile.getCertsFromCarrierPrivilegeAccessRules();
7486 }
7487 } finally {
7488 Binder.restoreCallingIdentity(identity);
7489 }
7490 return null;
7491 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007492
7493 /**
7494 * Enable or disable a modem stack.
7495 */
7496 @Override
7497 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7498 enforceModifyPermission();
7499
7500 final long identity = Binder.clearCallingIdentity();
7501 try {
7502 Phone phone = PhoneFactory.getPhone(slotIndex);
7503 if (phone == null) {
7504 return false;
7505 } else {
7506 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7507 }
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
7511 }
Michelecea4cf22018-12-21 15:00:11 -08007512
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007513 /**
7514 * Whether a modem stack is enabled or not.
7515 */
7516 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007517 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7518 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007519 Phone phone = PhoneFactory.getPhone(slotIndex);
7520 if (phone == null) return false;
7521
7522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007523 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7524 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007525 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7526 }
7527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007530 try {
7531 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7532 } catch (NoSuchElementException ex) {
7533 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7534 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
7538 }
7539
Michelecea4cf22018-12-21 15:00:11 -08007540 @Override
Michele0ea7d782019-03-19 14:58:42 -07007541 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007542 enforceModifyPermission();
7543
7544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007547 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007548 .commit();
7549 } finally {
7550 Binder.restoreCallingIdentity(identity);
7551 }
7552 }
7553
7554 @Override
Michele0ea7d782019-03-19 14:58:42 -07007555 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007556 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007558 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7559 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007560 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007561 }
Michelecea4cf22018-12-21 15:00:11 -08007562
7563 final long identity = Binder.clearCallingIdentity();
7564 try {
Michele0ea7d782019-03-19 14:58:42 -07007565 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007566 } finally {
7567 Binder.restoreCallingIdentity(identity);
7568 }
7569 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007570
Michele0ea7d782019-03-19 14:58:42 -07007571 @TelephonyManager.IsMultiSimSupportedResult
7572 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007573 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7574 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7575 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007576 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7577 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007578 }
7579 // Check if the hardware supports multisim functionality. If usage of multisim is not
7580 // supported by the modem, indicate that it is restricted.
7581 PhoneCapability staticCapability =
7582 mPhoneConfigurationManager.getStaticPhoneCapability();
7583 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007584 loge("isMultiSimSupportedInternal: no static configuration available");
7585 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007586 }
7587 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007588 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7589 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007590 }
7591 // Check if support of multiple SIMs is restricted by carrier
7592 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007593 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007594 }
7595
Michele0ea7d782019-03-19 14:58:42 -07007596 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007597 }
7598
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007599 /**
7600 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007601 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7602 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7603 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007604 * @param numOfSims number of active sims we want to switch to
7605 */
7606 @Override
7607 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007608 if (numOfSims == 1) {
7609 enforceModifyPermission();
7610 } else {
7611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7612 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7613 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007614 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007615
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007616 try {
Michele30b57b22019-03-01 12:01:14 -08007617 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007618 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007619 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7620 return;
7621 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007622 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7623 } finally {
7624 Binder.restoreCallingIdentity(identity);
7625 }
7626 }
7627
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007628 @Override
7629 public boolean isApplicationOnUicc(int subId, int appType) {
7630 enforceReadPrivilegedPermission("isApplicationOnUicc");
7631 Phone phone = getPhone(subId);
7632 if (phone == null) {
7633 return false;
7634 }
7635 final long identity = Binder.clearCallingIdentity();
7636 try {
7637 UiccCard uiccCard = phone.getUiccCard();
7638 if (uiccCard == null) {
7639 return false;
7640 }
7641 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7642 if (uiccProfile == null) {
7643 return false;
7644 }
7645 if (TelephonyManager.APPTYPE_SIM <= appType
7646 && appType <= TelephonyManager.APPTYPE_ISIM) {
7647 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7648 }
7649 return false;
7650 } finally {
7651 Binder.restoreCallingIdentity(identity);
7652 }
7653 }
7654
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007655 /**
chen xub4baa772019-04-03 10:23:41 -07007656 * Get whether making changes to modem configurations will trigger reboot.
7657 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007658 */
7659 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007660 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7661 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007662 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007663 mApp, subId, callingPackage, callingFeatureId,
7664 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007665 return false;
7666 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007667 final long identity = Binder.clearCallingIdentity();
7668 try {
7669 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7670 } finally {
7671 Binder.restoreCallingIdentity(identity);
7672 }
7673 }
7674
Nathan Harold29f5f052019-02-15 13:41:57 -08007675 private void updateModemStateMetrics() {
7676 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7677 // TODO: check the state for each modem if the api is ready.
7678 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7679 }
7680
Pengquan Meng3889a572019-01-23 11:16:29 -08007681 @Override
7682 public int[] getSlotsMapping() {
7683 enforceReadPrivilegedPermission("getSlotsMapping");
7684
7685 final long identity = Binder.clearCallingIdentity();
7686 try {
7687 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7688 // All logical slots should have a mapping to a physical slot.
7689 int[] logicalSlotsMapping = new int[phoneCount];
7690 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7691 for (int i = 0; i < slotInfos.length; i++) {
7692 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7693 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7694 }
7695 }
7696 return logicalSlotsMapping;
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
7699 }
7700 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007701
7702 /**
7703 * Get the IRadio HAL Version
7704 */
7705 @Override
7706 public int getRadioHalVersion() {
7707 Phone phone = getDefaultPhone();
7708 if (phone == null) return -1;
7709 HalVersion hv = phone.getHalVersion();
7710 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7711 return hv.major * 100 + hv.minor;
7712 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007713
7714 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007715 * Get the current calling package name.
7716 * @return the current calling package name
7717 */
7718 @Override
7719 public String getCurrentPackageName() {
7720 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7721 }
7722
7723 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007724 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7725 * corresponding network requests on a subId.
7726 *
7727 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007728 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007729 * 2) APN is un-metered for this subscription, or
7730 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007731 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007732 *
7733 * @return whether data is allowed for a apn type.
7734 *
7735 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007736 */
7737 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007738 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007739 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7740 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007741
7742 // Now that all security checks passes, perform the operation as ourselves.
7743 final long identity = Binder.clearCallingIdentity();
7744 try {
7745 Phone phone = getPhone(subId);
7746 if (phone == null) return false;
7747
Jack Yu41407ee2019-05-13 16:54:09 -07007748 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007749 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7750 } finally {
7751 Binder.restoreCallingIdentity(identity);
7752 }
7753 }
7754
7755 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007756 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007757 enforceReadPrivilegedPermission("isApnMetered");
7758
7759 // Now that all security checks passes, perform the operation as ourselves.
7760 final long identity = Binder.clearCallingIdentity();
7761 try {
7762 Phone phone = getPhone(subId);
7763 if (phone == null) return true; // By default return true.
7764
Jack Yu41407ee2019-05-13 16:54:09 -07007765 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007766 } finally {
7767 Binder.restoreCallingIdentity(identity);
7768 }
7769 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007770
7771 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007772 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7773 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7774 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7775 if (iccRecords == null) {
7776 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7777 return false;
7778 }
7779 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7780 }
7781
7782 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007783 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007784 if (callingPackage == null) {
7785 callingPackage = getCurrentPackageName();
7786 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007787 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7788 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7789 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7790 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7791 }
7792 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7793 Intent intent = new Intent();
7794 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7795 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7796 // Bring up choose default SMS subscription dialog right now
7797 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7798 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7799 mApp.startActivity(intent);
7800 }
chen xud5ca2d52019-05-28 15:20:57 -07007801
7802 @Override
7803 public String getMmsUAProfUrl(int subId) {
7804 //TODO investigate if this API should require proper permission check in R b/133791609
7805 final long identity = Binder.clearCallingIdentity();
7806 try {
7807 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7808 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7809 } finally {
7810 Binder.restoreCallingIdentity(identity);
7811 }
7812 }
7813
7814 @Override
7815 public String getMmsUserAgent(int subId) {
7816 //TODO investigate if this API should require proper permission check in R b/133791609
7817 final long identity = Binder.clearCallingIdentity();
7818 try {
7819 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7820 .getString(com.android.internal.R.string.config_mms_user_agent);
7821 } finally {
7822 Binder.restoreCallingIdentity(identity);
7823 }
7824 }
Jack Yub07d4972019-05-28 16:12:25 -07007825
7826 @Override
7827 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7828 enforceModifyPermission();
7829
7830 // Now that all security checks passes, perform the operation as ourselves.
7831 final long identity = Binder.clearCallingIdentity();
7832 try {
7833 Phone phone = getPhone(subId);
7834 if (phone == null) return false;
7835
7836 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7837 } finally {
7838 Binder.restoreCallingIdentity(identity);
7839 }
7840 }
7841
7842 @Override
7843 public boolean isDataAllowedInVoiceCall(int subId) {
7844 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7845
7846 // Now that all security checks passes, perform the operation as ourselves.
7847 final long identity = Binder.clearCallingIdentity();
7848 try {
7849 Phone phone = getPhone(subId);
7850 if (phone == null) return false;
7851
7852 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7853 } finally {
7854 Binder.restoreCallingIdentity(identity);
7855 }
7856 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007857
changbettyd5c246e2019-12-24 15:40:37 +08007858 @Override
7859 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7860 enforceModifyPermission();
7861
7862 // Now that all security checks passes, perform the operation as ourselves.
7863 final long identity = Binder.clearCallingIdentity();
7864 try {
7865 Phone phone = getPhone(subId);
7866 if (phone == null) return false;
7867
7868 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
7871 }
7872 }
7873
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007874 /**
7875 * Updates whether conference event pacakge handling is enabled.
7876 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7877 * otherwise.
7878 */
7879 @Override
7880 public void setCepEnabled(boolean isCepEnabled) {
7881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7882
7883 final long identity = Binder.clearCallingIdentity();
7884 try {
7885 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7886 for (Phone phone : PhoneFactory.getPhones()) {
7887 Phone defaultPhone = phone.getImsPhone();
7888 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7889 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7890 ImsPhoneCallTracker imsPhoneCallTracker =
7891 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7892 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7893 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7894 + imsPhone.getMsisdn());
7895 }
7896 }
7897 } finally {
7898 Binder.restoreCallingIdentity(identity);
7899 }
7900 }
allenwtsu46dcc572020-01-08 18:24:03 +08007901
7902 /**
7903 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7904 *
7905 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7906 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7907 * before being read.
7908 */
7909 @Override
7910 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7911 isCompressed) {
7912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7913 mApp, subId, "notifyRcsAutoConfigurationReceived");
7914 try {
7915 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7916 if (configBinder == null) {
7917 Rlog.e(LOG_TAG, "null result for getImsConfig");
7918 } else {
7919 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7920 }
7921 } catch (RemoteException e) {
7922 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7923 }
7924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007925}