blob: dca4270d6b0f985d9f502db999c15b6e3662c1aa [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;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080070import android.telephony.CellIdentityCdma;
71import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070073import android.telephony.CellInfoGsm;
74import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070075import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070076import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070077import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080078import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070079import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070081import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080082import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080083import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070084import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080085import android.telephony.RadioAccessSpecifier;
Meng Wangebdba862020-01-08 18:00:39 -080086import com.android.telephony.Rlog;
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;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700178import java.io.FileDescriptor;
179import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800182import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800184import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100185import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700187import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190/**
191 * Implementation of the ITelephony interface.
192 */
Santos Cordon117fee72014-05-16 17:56:12 -0700193public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 private static final String LOG_TAG = "PhoneInterfaceManager";
195 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
196 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
199 // Message codes used with mMainThreadHandler
200 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700201 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
202 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203 private static final int CMD_OPEN_CHANNEL = 9;
204 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
205 private static final int CMD_CLOSE_CHANNEL = 11;
206 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800207 private static final int CMD_NV_READ_ITEM = 13;
208 private static final int EVENT_NV_READ_ITEM_DONE = 14;
209 private static final int CMD_NV_WRITE_ITEM = 15;
210 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
211 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
212 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700213 private static final int CMD_RESET_MODEM_CONFIG = 19;
214 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800215 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
216 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
217 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
218 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800219 private static final int CMD_SEND_ENVELOPE = 25;
220 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000221 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
222 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700223 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
224 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
225 private static final int CMD_EXCHANGE_SIM_IO = 31;
226 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800227 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
228 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700229 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
230 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700231 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
232 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700233 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
234 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
235 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700237 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
238 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
239 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
240 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700241 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
243 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244 private static final int CMD_SWITCH_SLOTS = 50;
245 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700246 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
247 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
248 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
249 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
250 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
251 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
252 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
253 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700254 private static final int CMD_GET_ALL_CELL_INFO = 60;
255 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
256 private static final int CMD_GET_CELL_LOCATION = 62;
257 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700258 private static final int CMD_MODEM_REBOOT = 64;
259 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700260 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
261 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800262 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
263 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700264 private static final int CMD_GET_MODEM_STATUS = 70;
265 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700266 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
267 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700268 private static final int CMD_ERASE_MODEM_CONFIG = 74;
269 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800271 // Parameters of select command.
272 private static final int SELECT_COMMAND = 0xA4;
273 private static final int SELECT_P1 = 0x04;
274 private static final int SELECT_P2 = 0;
275 private static final int SELECT_P3 = 0x10;
276
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 /** The singleton instance. */
278 private static PhoneInterfaceManager sInstance;
279
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800282 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700283 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private AppOpsManager mAppOps;
285 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800286 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800287 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700288 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289
Derek Tan97ebb422014-09-05 16:55:38 -0700290 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
291 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800292 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800293 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700294
Michelecea4cf22018-12-21 15:00:11 -0800295 // String to store multi SIM allowed
296 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
297
Derek Tan740e1672017-06-27 14:56:27 -0700298 // The AID of ISD-R.
299 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
300
yinxub1bed742017-04-17 11:45:04 -0700301 private NetworkScanRequestTracker mNetworkScanRequestTracker;
302
David Kelly5e06a7f2018-03-12 14:10:59 +0000303 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
304 private static final int MANUFACTURER_CODE_LENGTH = 8;
305
Derek Tan89e89d42014-07-08 17:00:10 -0700306 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700307 * Experiment flag to enable erase modem config on reset network, default value is false
308 */
309 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
310 "reset_network_erase_modem_config_enabled";
311
312 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700313 * A request object to use for transmitting data to an ICC.
314 */
315 private static final class IccAPDUArgument {
316 public int channel, cla, command, p1, p2, p3;
317 public String data;
318
319 public IccAPDUArgument(int channel, int cla, int command,
320 int p1, int p2, int p3, String data) {
321 this.channel = channel;
322 this.cla = cla;
323 this.command = command;
324 this.p1 = p1;
325 this.p2 = p2;
326 this.p3 = p3;
327 this.data = data;
328 }
329 }
330
331 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700332 * A request object to use for transmitting data to an ICC.
333 */
334 private static final class ManualNetworkSelectionArgument {
335 public OperatorInfo operatorInfo;
336 public boolean persistSelection;
337
338 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
339 this.operatorInfo = operatorInfo;
340 this.persistSelection = persistSelection;
341 }
342 }
343
344 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
346 * request after sending. The main thread will notify the request when it is complete.
347 */
348 private static final class MainThreadRequest {
349 /** The argument to use for the request */
350 public Object argument;
351 /** The result of the request that is run on the main thread */
352 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800353 // The subscriber id that this request applies to. Defaults to
354 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
355 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
Nathan Harold92bed182018-10-12 18:16:49 -0700357 // In cases where subId is unavailable, the caller needs to specify the phone.
358 public Phone phone;
359
vagdeviaf9a5b92018-08-15 16:01:53 -0700360 public WorkSource workSource;
361
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 public MainThreadRequest(Object argument) {
363 this.argument = argument;
364 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365
Nathan Harold92bed182018-10-12 18:16:49 -0700366 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
367 this.argument = argument;
368 if (phone != null) {
369 this.phone = phone;
370 }
371 this.workSource = workSource;
372 }
373
vagdeviaf9a5b92018-08-15 16:01:53 -0700374 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800375 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800376 if (subId != null) {
377 this.subId = subId;
378 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700379 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800383 private static final class IncomingThirdPartyCallArgs {
384 public final ComponentName component;
385 public final String callId;
386 public final String callerDisplayName;
387
388 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
389 String callerDisplayName) {
390 this.component = component;
391 this.callId = callId;
392 this.callerDisplayName = callerDisplayName;
393 }
394 }
395
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 /**
397 * A handler that processes messages on the main thread in the phone process. Since many
398 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
399 * inbound binder threads to the main thread in the phone process. The Binder thread
400 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
401 * on, which will be notified when the operation completes and will contain the result of the
402 * request.
403 *
404 * <p>If a MainThreadRequest object is provided in the msg.obj field,
405 * note that request.result must be set to something non-null for the calling thread to
406 * unblock.
407 */
408 private final class MainThreadHandler extends Handler {
409 @Override
410 public void handleMessage(Message msg) {
411 MainThreadRequest request;
412 Message onCompleted;
413 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800414 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800416 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
418 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700419 case CMD_HANDLE_USSD_REQUEST: {
420 request = (MainThreadRequest) msg.obj;
421 final Phone phone = getPhoneFromRequest(request);
422 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
423 String ussdRequest = ussdObject.first;
424 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 if (!isUssdApiAllowed(request.subId)) {
427 // Carrier does not support use of this API, return failure.
428 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
429 UssdResponse response = new UssdResponse(ussdRequest, null);
430 Bundle returnData = new Bundle();
431 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
432 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700433
Pengquan Menga1bb6272018-09-06 09:59:22 -0700434 request.result = true;
435 notifyRequester(request);
436 return;
437 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700438
Pengquan Menga1bb6272018-09-06 09:59:22 -0700439 try {
440 request.result = phone != null
441 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
442 } catch (CallStateException cse) {
443 request.result = false;
444 }
445 // Wake up the requesting thread
446 notifyRequester(request);
447 break;
pkanwar32d516d2016-10-14 19:37:38 -0700448 }
449
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700452 final Phone phone = getPhoneFromRequest(request);
453 request.result = phone != null ?
454 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
455 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700457 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800464 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700465 if (uiccCard == null) {
466 loge("iccTransmitApduLogicalChannel: No UICC");
467 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700468 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
471 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700472 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 iccArgument.channel, iccArgument.cla, iccArgument.command,
474 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700476 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 break;
478
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 ar = (AsyncResult) msg.obj;
481 request = (MainThreadRequest) ar.userObj;
482 if (ar.exception == null && ar.result != null) {
483 request.result = ar.result;
484 } else {
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
486 if (ar.result == null) {
487 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800488 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800490 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 } else {
492 loge("iccTransmitApduLogicalChannel: Unknown exception");
493 }
494 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 break;
497
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
499 request = (MainThreadRequest) msg.obj;
500 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 if (uiccCard == null) {
503 loge("iccTransmitApduBasicChannel: No UICC");
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 } else {
507 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
508 request);
509 uiccCard.iccTransmitApduBasicChannel(
510 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
511 iccArgument.p3, iccArgument.data, onCompleted);
512 }
513 break;
514
515 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
520 } else {
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
522 if (ar.result == null) {
523 loge("iccTransmitApduBasicChannel: Empty response");
524 } else if (ar.exception instanceof CommandException) {
525 loge("iccTransmitApduBasicChannel: CommandException: " +
526 ar.exception);
527 } else {
528 loge("iccTransmitApduBasicChannel: Unknown exception");
529 }
530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 break;
533
534 case CMD_EXCHANGE_SIM_IO:
535 request = (MainThreadRequest) msg.obj;
536 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 if (uiccCard == null) {
539 loge("iccExchangeSimIO: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 } else {
543 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
544 request);
545 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
546 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
547 iccArgument.data, onCompleted);
548 }
549 break;
550
551 case EVENT_EXCHANGE_SIM_IO_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
556 } else {
557 request.result = new IccIoResult(0x6f, 0, (byte[])null);
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
Derek Tan4d5e5c12014-02-04 11:54:58 -0800562 case CMD_SEND_ENVELOPE:
563 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("sendEnvelopeWithStatus: No UICC");
567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 } else {
570 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
571 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
572 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800573 break;
574
575 case EVENT_SEND_ENVELOPE_DONE:
576 ar = (AsyncResult) msg.obj;
577 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 if (ar.exception == null && ar.result != null) {
579 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700581 request.result = new IccIoResult(0x6F, 0, (byte[])null);
582 if (ar.result == null) {
583 loge("sendEnvelopeWithStatus: Empty response");
584 } else if (ar.exception instanceof CommandException) {
585 loge("sendEnvelopeWithStatus: CommandException: " +
586 ar.exception);
587 } else {
588 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
589 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800592 break;
593
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 case CMD_OPEN_CHANNEL:
595 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800596 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800597 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 if (uiccCard == null) {
599 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800600 request.result = new IccOpenLogicalChannelResponse(-1,
601 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 } else {
604 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800605 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
606 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 break;
609
610 case EVENT_OPEN_CHANNEL_DONE:
611 ar = (AsyncResult) msg.obj;
612 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 int[] result = (int[]) ar.result;
616 int channelId = result[0];
617 byte[] selectResponse = null;
618 if (result.length > 1) {
619 selectResponse = new byte[result.length - 1];
620 for (int i = 1; i < result.length; ++i) {
621 selectResponse[i - 1] = (byte) result[i];
622 }
623 }
624 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 if (ar.result == null) {
628 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 if (ar.exception != null) {
631 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
632 }
633
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700634 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700635 if (ar.exception instanceof CommandException) {
636 CommandException.Error error =
637 ((CommandException) (ar.exception)).getCommandError();
638 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700640 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700641 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 }
643 }
644 openChannelResp = new IccOpenLogicalChannelResponse(
645 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700647 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
651 case CMD_CLOSE_CHANNEL:
652 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800653 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 if (uiccCard == null) {
655 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900656 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 } else {
659 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
660 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
661 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 break;
663
664 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800665 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
666 break;
667
668 case CMD_NV_READ_ITEM:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800671 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
672 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800673 break;
674
675 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800678 if (ar.exception == null && ar.result != null) {
679 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800681 request.result = "";
682 if (ar.result == null) {
683 loge("nvReadItem: Empty response");
684 } else if (ar.exception instanceof CommandException) {
685 loge("nvReadItem: CommandException: " +
686 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800688 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 }
690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 break;
693
Jake Hambye994d462014-02-03 13:10:13 -0800694 case CMD_NV_WRITE_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
697 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800698 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700699 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
702 case EVENT_NV_WRITE_ITEM_DONE:
703 handleNullReturnEvent(msg, "nvWriteItem");
704 break;
705
706 case CMD_NV_WRITE_CDMA_PRL:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800709 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800710 break;
711
712 case EVENT_NV_WRITE_CDMA_PRL_DONE:
713 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
714 break;
715
chen xu6dac5ab2018-10-26 17:39:23 -0700716 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800717 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700718 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800719 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800720 break;
721
chen xu6dac5ab2018-10-26 17:39:23 -0700722 case EVENT_RESET_MODEM_CONFIG_DONE:
723 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 case CMD_GET_PREFERRED_NETWORK_TYPE:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700729 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
733 ar = (AsyncResult) msg.obj;
734 request = (MainThreadRequest) ar.userObj;
735 if (ar.exception == null && ar.result != null) {
736 request.result = ar.result; // Integer
737 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800738 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800739 if (ar.result == null) {
740 loge("getPreferredNetworkType: Empty response");
741 } else if (ar.exception instanceof CommandException) {
742 loge("getPreferredNetworkType: CommandException: " +
743 ar.exception);
744 } else {
745 loge("getPreferredNetworkType: Unknown exception");
746 }
747 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700748 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800749 break;
750
751 case CMD_SET_PREFERRED_NETWORK_TYPE:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
754 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
759 handleNullReturnEvent(msg, "setPreferredNetworkType");
760 break;
761
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000762 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
763 request = (MainThreadRequest)msg.obj;
764 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000766 break;
767
768 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
769 ar = (AsyncResult)msg.obj;
770 request = (MainThreadRequest)ar.userObj;
771 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700772 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000773 break;
774
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800775 case CMD_SET_VOICEMAIL_NUMBER:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
778 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800779 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
780 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800781 break;
782
783 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
784 handleNullReturnEvent(msg, "setVoicemailNumber");
785 break;
786
Stuart Scott54788802015-03-30 13:18:01 -0700787 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
790 request);
791 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
792 break;
793
794 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
795 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
796 break;
797
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 case CMD_PERFORM_NETWORK_SCAN:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
801 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
802 break;
803
804 case EVENT_PERFORM_NETWORK_SCAN_DONE:
805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 CellNetworkScanResult cellScanResult;
808 if (ar.exception == null && ar.result != null) {
809 cellScanResult = new CellNetworkScanResult(
810 CellNetworkScanResult.STATUS_SUCCESS,
811 (List<OperatorInfo>) ar.result);
812 } else {
813 if (ar.result == null) {
814 loge("getCellNetworkScanResults: Empty response");
815 }
816 if (ar.exception != null) {
817 loge("getCellNetworkScanResults: Exception: " + ar.exception);
818 }
819 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
820 if (ar.exception instanceof CommandException) {
821 CommandException.Error error =
822 ((CommandException) (ar.exception)).getCommandError();
823 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
824 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
825 } else if (error == CommandException.Error.GENERIC_FAILURE) {
826 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
827 }
828 }
829 cellScanResult = new CellNetworkScanResult(errorCode, null);
830 }
831 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700832 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 break;
834
835 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
836 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700837 ManualNetworkSelectionArgument selArg =
838 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700839 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
840 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700841 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
842 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700843 break;
844
845 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700846 ar = (AsyncResult) msg.obj;
847 request = (MainThreadRequest) ar.userObj;
848 if (ar.exception == null) {
849 request.result = true;
850 } else {
851 request.result = false;
852 loge("setNetworkSelectionModeManual " + ar.exception);
853 }
854 notifyRequester(request);
855 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700856 break;
857
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700858 case CMD_GET_MODEM_ACTIVITY_INFO:
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700861 if (defaultPhone != null) {
862 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
863 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700864 break;
865
866 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result;
871 } else {
872 if (ar.result == null) {
873 loge("queryModemActivityInfo: Empty response");
874 } else if (ar.exception instanceof CommandException) {
875 loge("queryModemActivityInfo: CommandException: " +
876 ar.exception);
877 } else {
878 loge("queryModemActivityInfo: Unknown exception");
879 }
880 }
Amit Mahajand4766222016-01-28 15:28:28 -0800881 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
882 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800883 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700885 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700886 break;
887
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 case CMD_SET_ALLOWED_CARRIERS:
889 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800890 CarrierRestrictionRules argument =
891 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800893 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 break;
895
896 case EVENT_SET_ALLOWED_CARRIERS_DONE:
897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result;
901 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800902 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
903 if (ar.exception instanceof CommandException) {
904 loge("setAllowedCarriers: CommandException: " + ar.exception);
905 CommandException.Error error =
906 ((CommandException) (ar.exception)).getCommandError();
907 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
908 request.result =
909 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
910 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 } else {
912 loge("setAllowedCarriers: Unknown exception");
913 }
914 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700915 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 break;
917
918 case CMD_GET_ALLOWED_CARRIERS:
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800921 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700922 break;
923
924 case EVENT_GET_ALLOWED_CARRIERS_DONE:
925 ar = (AsyncResult) msg.obj;
926 request = (MainThreadRequest) ar.userObj;
927 if (ar.exception == null && ar.result != null) {
928 request.result = ar.result;
929 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800930 request.result = new IllegalStateException(
931 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700932 if (ar.result == null) {
933 loge("getAllowedCarriers: Empty response");
934 } else if (ar.exception instanceof CommandException) {
935 loge("getAllowedCarriers: CommandException: " +
936 ar.exception);
937 } else {
938 loge("getAllowedCarriers: Unknown exception");
939 }
940 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700941 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700942 break;
943
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
945 ar = (AsyncResult) msg.obj;
946 request = (MainThreadRequest) ar.userObj;
947 if (ar.exception == null && ar.result != null) {
948 request.result = ar.result;
949 } else {
950 request.result = new IllegalArgumentException(
951 "Failed to retrieve Forbidden Plmns");
952 if (ar.result == null) {
953 loge("getForbiddenPlmns: Empty response");
954 } else {
955 loge("getForbiddenPlmns: Unknown exception");
956 }
957 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800959 break;
960
961 case CMD_GET_FORBIDDEN_PLMNS:
962 request = (MainThreadRequest) msg.obj;
963 uiccCard = getUiccCardFromRequest(request);
964 if (uiccCard == null) {
965 loge("getForbiddenPlmns() UiccCard is null");
966 request.result = new IllegalArgumentException(
967 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700968 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800969 break;
970 }
971 Integer appType = (Integer) request.argument;
972 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
973 if (uiccApp == null) {
974 loge("getForbiddenPlmns() no app with specified type -- "
975 + appType);
976 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700977 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800978 break;
979 } else {
980 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
981 + " specified type -- " + appType);
982 }
983 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
984 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
985 onCompleted);
986 break;
987
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000988 case CMD_SWITCH_SLOTS:
989 request = (MainThreadRequest) msg.obj;
990 int[] physicalSlots = (int[]) request.argument;
991 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
992 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
993 break;
994
995 case EVENT_SWITCH_SLOTS_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700999 notifyRequester(request);
1000 break;
1001 case CMD_GET_NETWORK_SELECTION_MODE:
1002 request = (MainThreadRequest) msg.obj;
1003 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1004 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1005 break;
1006
1007 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
1010 if (ar.exception != null) {
1011 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1012 } else {
1013 int mode = ((int[]) ar.result)[0];
1014 if (mode == 0) {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1016 } else {
1017 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1018 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001019 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001020 notifyRequester(request);
1021 break;
1022 case CMD_GET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1025 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1026 break;
1027 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception != null) {
1031 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1032 } else {
1033 request.result = ((int[]) ar.result)[0];
1034 }
1035 notifyRequester(request);
1036 break;
1037 case CMD_SET_CDMA_ROAMING_MODE:
1038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1040 int mode = (int) request.argument;
1041 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1042 break;
1043 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 request.result = ar.exception == null;
1047 notifyRequester(request);
1048 break;
1049 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1052 int subscriptionMode = (int) request.argument;
1053 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1054 break;
1055 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 request.result = ar.exception == null;
1059 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001060 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 case CMD_GET_ALL_CELL_INFO:
1062 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001064 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 case EVENT_GET_ALL_CELL_INFO_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001069 // If a timeout occurs, the response will be null
1070 request.result = (ar.exception == null && ar.result != null)
1071 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001072 synchronized (request) {
1073 request.notifyAll();
1074 }
1075 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 case CMD_REQUEST_CELL_INFO_UPDATE:
1077 request = (MainThreadRequest) msg.obj;
1078 request.phone.requestCellInfoUpdate(request.workSource,
1079 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1080 break;
1081 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
1084 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1085 try {
1086 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001088 cb.onError(
1089 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1090 ar.exception.getClass().getName(),
1091 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001094 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001095 } else {
1096 // use the result as returned
1097 cb.onCellInfo((List<CellInfo>) ar.result);
1098 }
1099 } catch (RemoteException re) {
1100 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1101 }
1102 break;
1103 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001104 request = (MainThreadRequest) msg.obj;
1105 WorkSource ws = (WorkSource) request.argument;
1106 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001107 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001109 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
1112 if (ar.exception == null) {
1113 request.result = ar.result;
1114 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001115 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001116 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001117 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001118 }
1119
1120 synchronized (request) {
1121 request.notifyAll();
1122 }
1123 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001124 case CMD_MODEM_REBOOT:
1125 request = (MainThreadRequest) msg.obj;
1126 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001127 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001128 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001129 case EVENT_CMD_MODEM_REBOOT_DONE:
1130 handleNullReturnEvent(msg, "rebootModem");
1131 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001132 case CMD_REQUEST_ENABLE_MODEM:
1133 request = (MainThreadRequest) msg.obj;
1134 boolean enable = (boolean) request.argument;
1135 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001136 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001137 PhoneConfigurationManager.getInstance()
1138 .enablePhone(request.phone, enable, onCompleted);
1139 break;
1140 case EVENT_ENABLE_MODEM_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001144 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001145 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001146 if ((boolean) request.result) {
1147 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1148 updateModemStateMetrics();
1149 } else {
1150 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1151 + ar.exception);
1152 }
1153 notifyRequester(request);
1154 break;
1155 case CMD_GET_MODEM_STATUS:
1156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1158 PhoneConfigurationManager.getInstance()
1159 .getPhoneStatusFromModem(request.phone, onCompleted);
1160 break;
1161 case EVENT_GET_MODEM_STATUS_DONE:
1162 ar = (AsyncResult) msg.obj;
1163 request = (MainThreadRequest) ar.userObj;
1164 int id = request.phone.getPhoneId();
1165 if (ar.exception == null && ar.result != null) {
1166 request.result = ar.result;
1167 //update the cache as modem status has changed
1168 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1169 (boolean) request.result);
1170 } else {
1171 // Return true if modem status cannot be retrieved. For most cases,
1172 // modem status is on. And for older version modems, GET_MODEM_STATUS
1173 // and disable modem are not supported. Modem is always on.
1174 // TODO: this should be fixed in R to support a third
1175 // status UNKNOWN b/131631629
1176 request.result = true;
1177 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1178 + ar.exception);
1179 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001180 notifyRequester(request);
1181 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001182 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1183 ar = (AsyncResult) msg.obj;
1184 request = (MainThreadRequest) ar.userObj;
1185 if (ar.exception == null && ar.result != null) {
1186 request.result = ar.result;
1187 } else {
1188 request.result = -1;
1189 loge("Failed to set Forbidden Plmns");
1190 if (ar.result == null) {
1191 loge("setForbidenPlmns: Empty response");
1192 } else if (ar.exception != null) {
1193 loge("setForbiddenPlmns: Exception: " + ar.exception);
1194 request.result = -1;
1195 } else {
1196 loge("setForbiddenPlmns: Unknown exception");
1197 }
1198 }
1199 notifyRequester(request);
1200 break;
1201 case CMD_SET_FORBIDDEN_PLMNS:
1202 request = (MainThreadRequest) msg.obj;
1203 uiccCard = getUiccCardFromRequest(request);
1204 if (uiccCard == null) {
1205 loge("setForbiddenPlmns: UiccCard is null");
1206 request.result = -1;
1207 notifyRequester(request);
1208 break;
1209 }
1210 Pair<Integer, List<String>> setFplmnsArgs =
1211 (Pair<Integer, List<String>>) request.argument;
1212 appType = setFplmnsArgs.first;
1213 List<String> fplmns = setFplmnsArgs.second;
1214 uiccApp = uiccCard.getApplicationByType(appType);
1215 if (uiccApp == null) {
1216 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1217 request.result = -1;
1218 loge("Failed to get UICC App");
1219 notifyRequester(request);
1220 } else {
1221 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1222 ((SIMRecords) uiccApp.getIccRecords())
1223 .setForbiddenPlmns(onCompleted, fplmns);
1224 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001225 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001226 case CMD_ERASE_MODEM_CONFIG:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1229 defaultPhone.eraseModemConfig(onCompleted);
1230 break;
1231 case EVENT_ERASE_MODEM_CONFIG_DONE:
1232 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001233 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 default:
1235 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1236 break;
1237 }
1238 }
Jake Hambye994d462014-02-03 13:10:13 -08001239
Pengquan Menga1bb6272018-09-06 09:59:22 -07001240 private void notifyRequester(MainThreadRequest request) {
1241 synchronized (request) {
1242 request.notifyAll();
1243 }
1244 }
1245
Jake Hambye994d462014-02-03 13:10:13 -08001246 private void handleNullReturnEvent(Message msg, String command) {
1247 AsyncResult ar = (AsyncResult) msg.obj;
1248 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null) {
1250 request.result = true;
1251 } else {
1252 request.result = false;
1253 if (ar.exception instanceof CommandException) {
1254 loge(command + ": CommandException: " + ar.exception);
1255 } else {
1256 loge(command + ": Unknown exception");
1257 }
1258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001259 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
1268 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(
1270 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001271 }
1272
1273 /**
1274 * Posts the specified command to be executed on the main thread,
1275 * waits for the request to complete, and returns the result.
1276 * @see #sendRequestAsync
1277 */
1278 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1279 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001280 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001288 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001289 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001290 }
1291
1292 /**
1293 * Posts the specified command to be executed on the main thread,
1294 * waits for the request to complete, and returns the result.
1295 * @see #sendRequestAsync
1296 */
Nathan Harold92bed182018-10-12 18:16:49 -07001297 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1298 return sendRequest(command, argument, subId, null, workSource);
1299 }
1300
1301 /**
1302 * Posts the specified command to be executed on the main thread,
1303 * waits for the request to complete, and returns the result.
1304 * @see #sendRequestAsync
1305 */
1306 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1307 return sendRequest(
1308 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1309 }
1310
1311 /**
1312 * Posts the specified command to be executed on the main thread,
1313 * waits for the request to complete, and returns the result.
1314 * @see #sendRequestAsync
1315 */
1316 private Object sendRequest(
1317 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1319 throw new RuntimeException("This method will deadlock if called from the main thread.");
1320 }
1321
Nathan Harold92bed182018-10-12 18:16:49 -07001322 MainThreadRequest request = null;
1323 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1324 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1325 } else if (phone != null) {
1326 request = new MainThreadRequest(argument, phone, workSource);
1327 } else {
1328 request = new MainThreadRequest(argument, subId, workSource);
1329 }
1330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 Message msg = mMainThreadHandler.obtainMessage(command, request);
1332 msg.sendToTarget();
1333
1334 // Wait for the request to complete
1335 synchronized (request) {
1336 while (request.result == null) {
1337 try {
1338 request.wait();
1339 } catch (InterruptedException e) {
1340 // Do nothing, go back and wait until the request is complete
1341 }
1342 }
1343 }
1344 return request.result;
1345 }
1346
1347 /**
1348 * Asynchronous ("fire and forget") version of sendRequest():
1349 * Posts the specified command to be executed on the main thread, and
1350 * returns immediately.
1351 * @see #sendRequest
1352 */
1353 private void sendRequestAsync(int command) {
1354 mMainThreadHandler.sendEmptyMessage(command);
1355 }
1356
1357 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001360 */
1361 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001362 sendRequestAsync(command, argument, null, null);
1363 }
1364
1365 /**
1366 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1367 * @see {@link #sendRequest(int,Object)}
1368 */
1369 private void sendRequestAsync(
1370 int command, Object argument, Phone phone, WorkSource workSource) {
1371 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001372 Message msg = mMainThreadHandler.obtainMessage(command, request);
1373 msg.sendToTarget();
1374 }
1375
1376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 * Initialize the singleton PhoneInterfaceManager instance.
1378 * This is only done once, at startup, from PhoneApp.onCreate().
1379 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 synchronized (PhoneInterfaceManager.class) {
1382 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 } else {
1385 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1386 }
1387 return sInstance;
1388 }
1389 }
1390
1391 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001392 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001395 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001396 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1398 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001399 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001400 mTelephonySharedPreferences =
1401 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001402 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001403 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 publish();
1406 }
1407
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001408 private Phone getDefaultPhone() {
1409 Phone thePhone = getPhone(getDefaultSubscription());
1410 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1411 }
1412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 private void publish() {
1414 if (DBG) log("publish: " + this);
1415
Peter Wangc035ce42020-01-08 21:00:22 -08001416 TelephonyFrameworkInitializer
1417 .getTelephonyServiceManager()
1418 .getTelephonyServiceRegisterer()
1419 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 }
1421
Stuart Scott584921c2015-01-15 17:10:34 -08001422 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001423 if (request.phone != null) {
1424 return request.phone;
1425 } else {
1426 return getPhoneFromSubId(request.subId);
1427 }
1428 }
1429
1430 private Phone getPhoneFromSubId(int subId) {
1431 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1432 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001433 }
1434
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001435 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1436 Phone phone = getPhoneFromRequest(request);
1437 return phone == null ? null :
1438 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1439 }
1440
Wink Saville36469e72014-06-11 15:17:00 -07001441 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001442 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001443 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445
Naina Nallurid63128d2019-09-17 14:10:30 -07001446 private void sendEraseModemConfig(Phone phone) {
1447 if (phone != null) {
1448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1449 mApp, phone.getSubId(), "eraseModemConfig");
1450 final long identity = Binder.clearCallingIdentity();
1451 try {
1452 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1453 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1454 } finally {
1455 Binder.restoreCallingIdentity(identity);
1456 }
1457 }
1458 }
1459
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001461 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001462 }
1463
Wink Savilleb564aae2014-10-23 10:18:09 -07001464 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 if (DBG) log("dial: " + number);
1466 // No permission check needed here: This is just a wrapper around the
1467 // ACTION_DIAL intent, which is available to any app since it puts up
1468 // the UI before it does anything.
1469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001470 final long identity = Binder.clearCallingIdentity();
1471 try {
1472 String url = createTelUrl(number);
1473 if (url == null) {
1474 return;
1475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001477 // PENDING: should we just silently fail if phone is offhook or ringing?
1478 PhoneConstants.State state = mCM.getState(subId);
1479 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1480 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1481 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1482 mApp.startActivity(intent);
1483 }
1484 } finally {
1485 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 }
1487 }
1488
1489 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001490 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001491 }
1492
Wink Savilleb564aae2014-10-23 10:18:09 -07001493 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 if (DBG) log("call: " + number);
1495
1496 // This is just a wrapper around the ACTION_CALL intent, but we still
1497 // need to do a permission check since we're calling startActivity()
1498 // from the context of the phone app.
1499 enforceCallPermission();
1500
Jordan Liu1617b712019-07-10 15:06:26 -07001501 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 != AppOpsManager.MODE_ALLOWED) {
1503 return;
1504 }
1505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001506 final long identity = Binder.clearCallingIdentity();
1507 try {
1508 String url = createTelUrl(number);
1509 if (url == null) {
1510 return;
1511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001513 boolean isValid = false;
1514 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1515 if (slist != null) {
1516 for (SubscriptionInfo subInfoRecord : slist) {
1517 if (subInfoRecord.getSubscriptionId() == subId) {
1518 isValid = true;
1519 break;
1520 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001521 }
Wink Saville08874612014-08-31 19:19:58 -07001522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523 if (!isValid) {
1524 return;
1525 }
Wink Saville08874612014-08-31 19:19:58 -07001526
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001527 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1528 intent.putExtra(SUBSCRIPTION_KEY, subId);
1529 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1530 mApp.startActivity(intent);
1531 } finally {
1532 Binder.restoreCallingIdentity(identity);
1533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 }
1535
Wink Savilleb564aae2014-10-23 10:18:09 -07001536 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001537 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001538 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1539 }
1540
Wink Savilleb564aae2014-10-23 10:18:09 -07001541 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001543 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1544 }
1545
Wink Savilleb564aae2014-10-23 10:18:09 -07001546 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001548
1549 final long identity = Binder.clearCallingIdentity();
1550 try {
1551 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1552 checkSimPin.start();
1553 return checkSimPin.unlockSim(null, pin);
1554 } finally {
1555 Binder.restoreCallingIdentity(identity);
1556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 }
1558
Wink Savilleb564aae2014-10-23 10:18:09 -07001559 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001561
1562 final long identity = Binder.clearCallingIdentity();
1563 try {
1564 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1565 checkSimPuk.start();
1566 return checkSimPuk.unlockSim(puk, pin);
1567 } finally {
1568 Binder.restoreCallingIdentity(identity);
1569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
1572 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001573 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 * a synchronous one.
1575 */
1576 private static class UnlockSim extends Thread {
1577
1578 private final IccCard mSimCard;
1579
1580 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001581 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1582 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583
1584 // For replies from SimCard interface
1585 private Handler mHandler;
1586
1587 // For async handler to identify request type
1588 private static final int SUPPLY_PIN_COMPLETE = 100;
1589
1590 public UnlockSim(IccCard simCard) {
1591 mSimCard = simCard;
1592 }
1593
1594 @Override
1595 public void run() {
1596 Looper.prepare();
1597 synchronized (UnlockSim.this) {
1598 mHandler = new Handler() {
1599 @Override
1600 public void handleMessage(Message msg) {
1601 AsyncResult ar = (AsyncResult) msg.obj;
1602 switch (msg.what) {
1603 case SUPPLY_PIN_COMPLETE:
1604 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1605 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001606 mRetryCount = msg.arg1;
1607 if (ar.exception != null) {
1608 if (ar.exception instanceof CommandException &&
1609 ((CommandException)(ar.exception)).getCommandError()
1610 == CommandException.Error.PASSWORD_INCORRECT) {
1611 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1612 } else {
1613 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1614 }
1615 } else {
1616 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 mDone = true;
1619 UnlockSim.this.notifyAll();
1620 }
1621 break;
1622 }
1623 }
1624 };
1625 UnlockSim.this.notifyAll();
1626 }
1627 Looper.loop();
1628 }
1629
1630 /*
1631 * Use PIN or PUK to unlock SIM card
1632 *
1633 * If PUK is null, unlock SIM card with PIN
1634 *
1635 * If PUK is not null, unlock SIM card with PUK and set PIN code
1636 */
Wink Saville9de0f752013-10-22 19:04:03 -07001637 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638
1639 while (mHandler == null) {
1640 try {
1641 wait();
1642 } catch (InterruptedException e) {
1643 Thread.currentThread().interrupt();
1644 }
1645 }
1646 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1647
1648 if (puk == null) {
1649 mSimCard.supplyPin(pin, callback);
1650 } else {
1651 mSimCard.supplyPuk(puk, pin, callback);
1652 }
1653
1654 while (!mDone) {
1655 try {
1656 Log.d(LOG_TAG, "wait for done");
1657 wait();
1658 } catch (InterruptedException e) {
1659 // Restore the interrupted status
1660 Thread.currentThread().interrupt();
1661 }
1662 }
1663 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001664 int[] resultArray = new int[2];
1665 resultArray[0] = mResult;
1666 resultArray[1] = mRetryCount;
1667 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 }
1669 }
1670
1671 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001672 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001673
1674 }
1675
Wink Savilleb564aae2014-10-23 10:18:09 -07001676 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001677 // No permission check needed here: this call is harmless, and it's
1678 // needed for the ServiceState.requestStateUpdate() call (which is
1679 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001680 final long identity = Binder.clearCallingIdentity();
1681 try {
1682 final Phone phone = getPhone(subId);
1683 if (phone != null) {
1684 phone.updateServiceLocation();
1685 }
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 }
1690
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001691 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001692 @Override
1693 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001694 return isRadioOnWithFeature(callingPackage, null);
1695 }
1696
1697
1698 @Override
1699 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1700 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1701 callingFeatureId);
1702 }
1703
1704 @Deprecated
1705 @Override
1706 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1707 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
1709
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001710 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001711 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1712 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001714 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001715 return false;
1716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 return isRadioOnForSubscriber(subId);
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
1723 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001724 }
1725
1726 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727 final long identity = Binder.clearCallingIdentity();
1728 try {
1729 final Phone phone = getPhone(subId);
1730 if (phone != null) {
1731 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1732 } else {
1733 return false;
1734 }
1735 } finally {
1736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
1739
1740 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001741 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 }
Wink Saville36469e72014-06-11 15:17:00 -07001743
Wink Savilleb564aae2014-10-23 10:18:09 -07001744 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746
1747 final long identity = Binder.clearCallingIdentity();
1748 try {
1749 final Phone phone = getPhone(subId);
1750 if (phone != null) {
1751 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1752 }
1753 } finally {
1754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001755 }
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
1758 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001759 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001760 }
1761
Wink Savilleb564aae2014-10-23 10:18:09 -07001762 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001764
1765 final long identity = Binder.clearCallingIdentity();
1766 try {
1767 final Phone phone = getPhone(subId);
1768 if (phone == null) {
1769 return false;
1770 }
1771 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1772 toggleRadioOnOffForSubscriber(subId);
1773 }
1774 return true;
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
Wink Saville36469e72014-06-11 15:17:00 -07001779
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001780 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001781 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001782 /*
1783 * If any of the Radios are available, it will need to be
1784 * shutdown. So return true if any Radio is available.
1785 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 final long identity = Binder.clearCallingIdentity();
1787 try {
1788 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1789 Phone phone = PhoneFactory.getPhone(i);
1790 if (phone != null && phone.isRadioAvailable()) return true;
1791 }
1792 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1793 return false;
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001797 }
1798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001800 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 enforceModifyPermission();
1802
1803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1806 logv("Shutting down Phone " + i);
1807 shutdownRadioUsingPhoneId(i);
1808 }
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 }
1812 }
1813
1814 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001815 Phone phone = PhoneFactory.getPhone(phoneId);
1816 if (phone != null && phone.isRadioAvailable()) {
1817 phone.shutdownRadio();
1818 }
1819 }
1820
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001823
1824 final long identity = Binder.clearCallingIdentity();
1825 try {
1826 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1827 if (defaultPhone != null) {
1828 defaultPhone.setRadioPower(turnOn);
1829 return true;
1830 } else {
1831 loge("There's no default phone.");
1832 return false;
1833 }
1834 } finally {
1835 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001836 }
Wink Saville36469e72014-06-11 15:17:00 -07001837 }
1838
Wink Savilleb564aae2014-10-23 10:18:09 -07001839 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001841
1842 final long identity = Binder.clearCallingIdentity();
1843 try {
1844 final Phone phone = getPhone(subId);
1845 if (phone != null) {
1846 phone.setRadioPower(turnOn);
1847 return true;
1848 } else {
1849 return false;
1850 }
1851 } finally {
1852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 }
1855
Wink Saville36469e72014-06-11 15:17:00 -07001856 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 public boolean enableDataConnectivity() {
1859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001860
1861 final long identity = Binder.clearCallingIdentity();
1862 try {
1863 int subId = mSubscriptionController.getDefaultDataSubId();
1864 final Phone phone = getPhone(subId);
1865 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001866 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001867 return true;
1868 } else {
1869 return false;
1870 }
1871 } finally {
1872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 }
1875
Wink Saville36469e72014-06-11 15:17:00 -07001876 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001877 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 public boolean disableDataConnectivity() {
1879 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880
1881 final long identity = Binder.clearCallingIdentity();
1882 try {
1883 int subId = mSubscriptionController.getDefaultDataSubId();
1884 final Phone phone = getPhone(subId);
1885 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001886 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001887 return true;
1888 } else {
1889 return false;
1890 }
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 }
1895
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001897 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898 final long identity = Binder.clearCallingIdentity();
1899 try {
1900 final Phone phone = getPhone(subId);
1901 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001902 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001903 } else {
1904 return false;
1905 }
1906 } finally {
1907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 }
1910
1911 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001912 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001913 }
1914
pkanwarae03a6b2016-11-06 20:37:09 -08001915 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001916 enforceCallPermission();
1917
1918 final long identity = Binder.clearCallingIdentity();
1919 try {
1920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1921 return;
1922 }
1923 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1924 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1925 } finally {
1926 Binder.restoreCallingIdentity(identity);
1927 }
pkanwar32d516d2016-10-14 19:37:38 -07001928 };
1929
Wink Savilleb564aae2014-10-23 10:18:09 -07001930 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001932
1933 final long identity = Binder.clearCallingIdentity();
1934 try {
1935 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1936 return false;
1937 }
1938 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001945 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001946 }
1947
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001948 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 Phone phone = PhoneFactory.getPhone(slotIndex);
1952 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1953 PhoneConstantConversions.convertCallState(phone.getState());
1954 } finally {
1955 Binder.restoreCallingIdentity(identity);
1956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 }
1958
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001960 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001961 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1962 }
1963
1964 @Override
1965 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 final long identity = Binder.clearCallingIdentity();
1967 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001968 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969 if (phone != null) {
1970 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1971 } else {
1972 return PhoneConstantConversions.convertDataState(
1973 PhoneConstants.DataState.DISCONNECTED);
1974 }
1975 } finally {
1976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979
Sanket Padawe356d7632015-06-22 14:03:32 -07001980 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001981 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001982 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1983 }
1984
1985 @Override
1986 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987 final long identity = Binder.clearCallingIdentity();
1988 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001989 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990 if (phone != null) {
1991 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1992 } else {
1993 return TelephonyManager.DATA_ACTIVITY_NONE;
1994 }
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 }
1999
2000 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002001 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002002 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002003 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002004
2005 LocationAccessPolicy.LocationPermissionResult locationResult =
2006 LocationAccessPolicy.checkLocationPermission(mApp,
2007 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2008 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002009 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002010 .setCallingPid(Binder.getCallingPid())
2011 .setCallingUid(Binder.getCallingUid())
2012 .setMethod("getCellLocation")
2013 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2014 .build());
2015 switch (locationResult) {
2016 case DENIED_HARD:
2017 throw new SecurityException("Not allowed to access cell location");
2018 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002019 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2020 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 }
2022
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002023 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024 final long identity = Binder.clearCallingIdentity();
2025 try {
2026 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002027 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002028 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002029 } finally {
2030 Binder.restoreCallingIdentity(identity);
2031 }
Svetoslav64fad262015-04-14 14:35:21 -07002032 }
2033
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002035 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2036 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002037 if (!TextUtils.isEmpty(callingPackage)) {
2038 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2040 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002041 return "";
2042 }
2043 }
2044
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002045 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2046 // registered cell info, so return a NULL country instead.
2047 final long identity = Binder.clearCallingIdentity();
2048 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002049 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2050 // Get default phone in this case.
2051 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2052 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002053 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002054 // Todo: fix this when we can get the actual cellular network info when the device
2055 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002056 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002057 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2058 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002059 return "";
2060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061 Phone phone = PhoneFactory.getPhone(phoneId);
2062 if (phone != null) {
2063 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002064 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002065 if (sst != null) {
2066 LocaleTracker lt = sst.getLocaleTracker();
2067 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002068 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2069 return lt.getCurrentCountry();
2070 } else if (emergencyNumberTracker != null) {
2071 return emergencyNumberTracker.getEmergencyCountryIso();
2072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002073 }
2074 }
2075 }
2076 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002077 } finally {
2078 Binder.restoreCallingIdentity(identity);
2079 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002080 }
2081
2082 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002084 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002085 }
2086
Sanket Padawe356d7632015-06-22 14:03:32 -07002087 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002088 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 mApp.enforceCallingOrSelfPermission(
2090 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002091
2092 final long identity = Binder.clearCallingIdentity();
2093 try {
2094 final Phone phone = getPhone(subId);
2095 if (phone != null) {
2096 phone.enableLocationUpdates();
2097 }
2098 } finally {
2099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 }
2102
2103 @Override
2104 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002105 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002106 }
2107
Sanket Padawe356d7632015-06-22 14:03:32 -07002108 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002109 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 mApp.enforceCallingOrSelfPermission(
2111 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112
2113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 final Phone phone = getPhone(subId);
2116 if (phone != null) {
2117 phone.disableLocationUpdates();
2118 }
2119 } finally {
2120 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002121 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 }
2123
Nathan Harold31d7ff32018-10-15 20:20:30 -07002124 /**
2125 * Returns the target SDK version number for a given package name.
2126 *
Nathan Haroldec184742019-07-10 17:04:16 -07002127 * This call MUST be invoked before clearing the calling UID.
2128 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002129 * @return target SDK if the package is found or INT_MAX.
2130 */
2131 private int getTargetSdk(String packageName) {
2132 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002133 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002134 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 if (ai != null) return ai.targetSdkVersion;
2136 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002137 loge("Failed to get package info for pkg="
2138 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002139 }
2140 return Integer.MAX_VALUE;
2141 }
2142
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 @Override
2144 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002145 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2146 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002147 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002148 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2149 throw new SecurityException(
2150 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2151 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002152
Jordan Liu1617b712019-07-10 15:06:26 -07002153 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2155 return null;
2156 }
Svetoslav64fad262015-04-14 14:35:21 -07002157
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002158 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002160 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002161 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162
Nathan Haroldf180aac2018-06-01 18:43:55 -07002163 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2164 for (CellInfo ci : info) {
2165 if (ci instanceof CellInfoGsm) {
2166 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2167 } else if (ci instanceof CellInfoWcdma) {
2168 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002171 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 }
2173
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002174 private List<CellInfo> getCachedCellInfo() {
2175 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2176 for (Phone phone : PhoneFactory.getPhones()) {
2177 List<CellInfo> info = phone.getAllCellInfo();
2178 if (info != null) cellInfos.addAll(info);
2179 }
2180 return cellInfos;
2181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182
2183 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002184 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002185 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002186 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002187
2188 LocationAccessPolicy.LocationPermissionResult locationResult =
2189 LocationAccessPolicy.checkLocationPermission(mApp,
2190 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2191 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002192 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002193 .setCallingPid(Binder.getCallingPid())
2194 .setCallingUid(Binder.getCallingUid())
2195 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002196 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002197 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2198 .build());
2199 switch (locationResult) {
2200 case DENIED_HARD:
2201 throw new SecurityException("Not allowed to access cell info");
2202 case DENIED_SOFT:
2203 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 }
2205
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002206 final int targetSdk = getTargetSdk(callingPackage);
2207 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2208 return getCachedCellInfo();
2209 }
2210
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002211 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002212 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002213 final long identity = Binder.clearCallingIdentity();
2214 try {
2215 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2216 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002217 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002218 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219 if (info != null) cellInfos.addAll(info);
2220 }
2221 return cellInfos;
2222 } finally {
2223 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 }
2225 }
2226
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002227 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002228 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2229 String callingFeatureId) {
2230 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2231 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002232 }
2233
2234 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002235 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2236 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002237 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002238 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002239 }
2240
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002241 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2242 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002243 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002244 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002245
2246 LocationAccessPolicy.LocationPermissionResult locationResult =
2247 LocationAccessPolicy.checkLocationPermission(mApp,
2248 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2249 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002250 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002251 .setCallingPid(Binder.getCallingPid())
2252 .setCallingUid(Binder.getCallingUid())
2253 .setMethod("requestCellInfoUpdate")
2254 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2255 .build());
2256 switch (locationResult) {
2257 case DENIED_HARD:
2258 throw new SecurityException("Not allowed to access cell info");
2259 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002260 try {
2261 cb.onCellInfo(new ArrayList<CellInfo>());
2262 } catch (RemoteException re) {
2263 // Drop without consequences
2264 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002265 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002266 }
2267
Nathan Harolda939a962019-05-09 10:13:47 -07002268
2269 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002270 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2271
2272 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2273 }
2274
2275 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002277 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002278 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279
2280 final long identity = Binder.clearCallingIdentity();
2281 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002282 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002283 } finally {
2284 Binder.restoreCallingIdentity(identity);
2285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 }
2287
Shishir Agrawala9f32182016-04-12 12:00:16 -07002288 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002289 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 Phone phone = PhoneFactory.getPhone(slotIndex);
2291 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002292 return null;
2293 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002294 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002295 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002296 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002297 return null;
2298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299
2300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 return phone.getImei();
2303 } finally {
2304 Binder.restoreCallingIdentity(identity);
2305 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002306 }
2307
2308 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002309 public String getTypeAllocationCodeForSlot(int slotIndex) {
2310 Phone phone = PhoneFactory.getPhone(slotIndex);
2311 String tac = null;
2312 if (phone != null) {
2313 String imei = phone.getImei();
2314 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2315 }
2316 return tac;
2317 }
2318
2319 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002320 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002321 Phone phone = PhoneFactory.getPhone(slotIndex);
2322 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002323 return null;
2324 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002325
Jeff Davidson913390f2018-02-23 17:11:49 -08002326 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002327 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002328 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002329 return null;
2330 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002331
2332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 return phone.getMeid();
2335 } finally {
2336 Binder.restoreCallingIdentity(identity);
2337 }
Jack Yu2af8d712017-03-15 17:14:14 -07002338 }
2339
2340 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002341 public String getManufacturerCodeForSlot(int slotIndex) {
2342 Phone phone = PhoneFactory.getPhone(slotIndex);
2343 String manufacturerCode = null;
2344 if (phone != null) {
2345 String meid = phone.getMeid();
2346 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2347 }
2348 return manufacturerCode;
2349 }
2350
2351 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002352 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2353 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002354 Phone phone = PhoneFactory.getPhone(slotIndex);
2355 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002356 return null;
2357 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002358 int subId = phone.getSubId();
2359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002360 mApp, subId, callingPackage, callingFeatureId,
2361 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002362 return null;
2363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002364
2365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 return phone.getDeviceSvn();
2368 } finally {
2369 Binder.restoreCallingIdentity(identity);
2370 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002371 }
2372
fionaxu43304da2017-11-27 22:51:16 -08002373 @Override
2374 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375 final long identity = Binder.clearCallingIdentity();
2376 try {
2377 final Phone phone = getPhone(subId);
2378 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
2381 }
fionaxu43304da2017-11-27 22:51:16 -08002382 }
2383
2384 @Override
2385 public String getSubscriptionCarrierName(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 ? null : phone.getCarrierName();
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
2392 }
fionaxu43304da2017-11-27 22:51:16 -08002393 }
2394
calvinpanffe225e2018-11-01 19:43:06 +08002395 @Override
chen xu0026ca62019-03-06 15:28:50 -08002396 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 final Phone phone = getPhone(subId);
2400 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002401 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002402 } finally {
2403 Binder.restoreCallingIdentity(identity);
2404 }
2405 }
2406
2407 @Override
chen xu0026ca62019-03-06 15:28:50 -08002408 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002412 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
2416 }
2417
chen xu651eec72018-11-11 19:03:44 -08002418 @Override
chen xu864e11c2018-12-06 22:10:03 -08002419 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2420 if (!isSubscriptionMccMnc) {
2421 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2422 }
chen xu651eec72018-11-11 19:03:44 -08002423 final Phone phone = PhoneFactory.getPhone(slotIndex);
2424 if (phone == null) {
2425 return TelephonyManager.UNKNOWN_CARRIER_ID;
2426 }
2427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2430 } finally {
2431 Binder.restoreCallingIdentity(identity);
2432 }
2433 }
2434
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 //
2436 // Internal helper methods.
2437 //
2438
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002439 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2441 *
2442 * @throws SecurityException if the caller does not have the required permission
2443 */
2444 private void enforceModifyPermission() {
2445 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2446 }
2447
Shuo Qian3b6ee772019-11-13 17:43:31 -08002448 private void enforceActiveEmergencySessionPermission() {
2449 mApp.enforceCallingOrSelfPermission(
2450 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2451 }
2452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 /**
2454 * Make sure the caller has the CALL_PHONE permission.
2455 *
2456 * @throws SecurityException if the caller does not have the required permission
2457 */
2458 private void enforceCallPermission() {
2459 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2460 }
2461
paulhu5a773602019-08-23 19:17:33 +08002462 private void enforceSettingsPermission() {
2463 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002464 }
2465
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 private String createTelUrl(String number) {
2467 if (TextUtils.isEmpty(number)) {
2468 return null;
2469 }
2470
Jake Hambye994d462014-02-03 13:10:13 -08002471 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 }
2473
Ihab Awadf9e92732013-12-05 18:02:52 -08002474 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2476 }
2477
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002478 private static void logv(String msg) {
2479 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2480 }
2481
Ihab Awadf9e92732013-12-05 18:02:52 -08002482 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2484 }
2485
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002486 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002488 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002489 }
2490
Sanket Padawe356d7632015-06-22 14:03:32 -07002491 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002492 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493 final long identity = Binder.clearCallingIdentity();
2494 try {
2495 final Phone phone = PhoneFactory.getPhone(slotIndex);
2496 if (phone == null) {
2497 return PhoneConstants.PHONE_TYPE_NONE;
2498 } else {
2499 return phone.getPhoneType();
2500 }
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
2505
2506 /**
2507 * Returns the CDMA ERI icon index to display
2508 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002509 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002510 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2511 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2512 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002513 }
2514
Sanket Padawe356d7632015-06-22 14:03:32 -07002515 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002516 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2517 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002519 mApp, subId, callingPackage, callingFeatureId,
2520 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002521 return -1;
2522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523
2524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 final Phone phone = getPhone(subId);
2527 if (phone != null) {
2528 return phone.getCdmaEriIconIndex();
2529 } else {
2530 return -1;
2531 }
2532 } finally {
2533 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 }
2536
2537 /**
2538 * Returns the CDMA ERI icon mode,
2539 * 0 - ON
2540 * 1 - FLASHING
2541 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002542 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002543 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2544 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2545 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002546 }
2547
Sanket Padawe356d7632015-06-22 14:03:32 -07002548 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002549 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2550 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002552 mApp, subId, callingPackage, callingFeatureId,
2553 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002554 return -1;
2555 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 final Phone phone = getPhone(subId);
2560 if (phone != null) {
2561 return phone.getCdmaEriIconMode();
2562 } else {
2563 return -1;
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
2570 /**
2571 * Returns the CDMA ERI text,
2572 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002573 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002574 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2575 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2576 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002577 }
2578
Sanket Padawe356d7632015-06-22 14:03:32 -07002579 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002580 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2581 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002583 mApp, subId, callingPackage, callingFeatureId,
2584 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002585 return null;
2586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587
2588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 final Phone phone = getPhone(subId);
2591 if (phone != null) {
2592 return phone.getCdmaEriText();
2593 } else {
2594 return null;
2595 }
2596 } finally {
2597 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 }
2600
2601 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002602 * Returns the CDMA MDN.
2603 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002605 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2607 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608
2609 final long identity = Binder.clearCallingIdentity();
2610 try {
2611 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002612 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 return phone.getLine1Number();
2614 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002615 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 return null;
2617 }
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002620 }
2621 }
2622
2623 /**
2624 * Returns the CDMA MIN.
2625 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002626 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002627 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2629 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630
2631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 final Phone phone = getPhone(subId);
2634 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2635 return phone.getCdmaMin();
2636 } else {
2637 return null;
2638 }
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002641 }
2642 }
2643
Hall Liud892bec2018-11-30 14:51:45 -08002644 @Override
2645 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2646 INumberVerificationCallback callback, String callingPackage) {
2647 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2648 != PERMISSION_GRANTED) {
2649 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2650 }
2651 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2652
2653 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2654 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2655 throw new SecurityException("Calling package must be configured in the device config");
2656 }
2657
2658 if (range == null) {
2659 throw new NullPointerException("Range must be non-null");
2660 }
2661
2662 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002663 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002664
2665 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2666 }
2667
Junda Liuca05d5d2014-08-14 22:36:34 -07002668 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002669 * Returns true if CDMA provisioning needs to run.
2670 */
2671 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 final long identity = Binder.clearCallingIdentity();
2673 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002674 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675 } finally {
2676 Binder.restoreCallingIdentity(identity);
2677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
2679
2680 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002681 * Sets the voice mail number of a given subId.
2682 */
2683 @Override
2684 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002685 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2686 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2691 new Pair<String, String>(alphaTag, number), new Integer(subId));
2692 return success;
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
2695 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002696 }
2697
Ta-wei Yen87c49842016-05-13 21:19:52 -07002698 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002699 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2700 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002701 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2702 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002703 if (!TextUtils.equals(callingPackage, systemDialer)) {
2704 throw new SecurityException("caller must be system dialer");
2705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706
2707 final long identity = Binder.clearCallingIdentity();
2708 try {
2709 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2710 if (phoneAccountHandle == null) {
2711 return null;
2712 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002713 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 } finally {
2715 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002716 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002717 }
2718
2719 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002720 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2721 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002724 mApp, subId, callingPackage, callingFeatureId,
2725 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002726 return null;
2727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002728
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002729 final long identity = Binder.clearCallingIdentity();
2730 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002731 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002732 } finally {
2733 Binder.restoreCallingIdentity(identity);
2734 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002735 }
2736
2737 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002738 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2739 VisualVoicemailSmsFilterSettings settings) {
2740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741
2742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002745 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 } finally {
2747 Binder.restoreCallingIdentity(identity);
2748 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002749 }
2750
2751 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002752 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754
2755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002758 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 } finally {
2760 Binder.restoreCallingIdentity(identity);
2761 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002762 }
2763
2764 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002765 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2766 String callingPackage, int subId) {
2767 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768
2769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002772 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002776 }
2777
2778 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002779 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002780 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002785 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002789 }
2790
2791 @Override
2792 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2793 String number, int port, String text, PendingIntent sentIntent) {
2794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002795 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002796 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002797 SmsController smsController = PhoneFactory.getSmsController();
2798 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2799 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002800 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002801
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002802 /**
fionaxu0152e512016-11-14 13:36:14 -08002803 * Sets the voice activation state of a given subId.
2804 */
2805 @Override
2806 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2808 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 final Phone phone = getPhone(subId);
2813 if (phone != null) {
2814 phone.setVoiceActivationState(activationState);
2815 } else {
2816 loge("setVoiceActivationState fails with invalid subId: " + subId);
2817 }
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002820 }
2821 }
2822
2823 /**
2824 * Sets the data activation state of a given subId.
2825 */
2826 @Override
2827 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2829 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830
2831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 final Phone phone = getPhone(subId);
2834 if (phone != null) {
2835 phone.setDataActivationState(activationState);
2836 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002837 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 }
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002841 }
2842 }
2843
2844 /**
2845 * Returns the voice activation state of a given subId.
2846 */
2847 @Override
2848 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002849 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850
fionaxu0152e512016-11-14 13:36:14 -08002851 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 if (phone != null) {
2855 return phone.getVoiceActivationState();
2856 } else {
2857 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2858 }
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002861 }
2862 }
2863
2864 /**
2865 * Returns the data activation state of a given subId.
2866 */
2867 @Override
2868 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002869 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870
fionaxu0152e512016-11-14 13:36:14 -08002871 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 final long identity = Binder.clearCallingIdentity();
2873 try {
2874 if (phone != null) {
2875 return phone.getDataActivationState();
2876 } else {
2877 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2878 }
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002881 }
2882 }
2883
2884 /**
Wink Saville36469e72014-06-11 15:17:00 -07002885 * Returns the unread count of voicemails for a subId
2886 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002887 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002888 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2889 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002891 mApp, subId, callingPackage, callingFeatureId,
2892 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002893 return 0;
2894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895 final long identity = Binder.clearCallingIdentity();
2896 try {
2897 final Phone phone = getPhone(subId);
2898 if (phone != null) {
2899 return phone.getVoiceMessageCount();
2900 } else {
2901 return 0;
2902 }
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 }
2907
2908 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002909 * returns true, if the device is in a state where both voice and data
2910 * are supported simultaneously. This can change based on location or network condition.
2911 */
2912 @Override
2913 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914 final long identity = Binder.clearCallingIdentity();
2915 try {
2916 final Phone phone = getPhone(subId);
2917 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
2920 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002921 }
2922
2923 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002924 * Send the dialer code if called from the current default dialer or the caller has
2925 * carrier privilege.
2926 * @param inputCode The dialer code to send
2927 */
2928 @Override
2929 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002930 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002931 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002932 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2933 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002934 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002935 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002936 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002941 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
fionaxu235cc5e2017-03-06 22:25:57 -08002945 }
2946
Pengquan Menga1bb6272018-09-06 09:59:22 -07002947 @Override
2948 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002949 if (!isActiveSubscription(subId)) {
2950 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2951 }
2952
Pengquan Menga1bb6272018-09-06 09:59:22 -07002953 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2954 }
2955
Brad Ebinger35c841c2018-10-01 10:40:55 -07002956 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002957 public boolean isInEmergencySmsMode() {
2958 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 for (Phone phone : PhoneFactory.getPhones()) {
2962 if (phone.isInEmergencySmsMode()) {
2963 return true;
2964 }
2965 }
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 return false;
2970 }
2971
2972 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002973 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2974 throws RemoteException {
2975 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002976 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2977 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2978 "IMS not available on device.");
2979 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 final long token = Binder.clearCallingIdentity();
2981 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002983 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002984 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002985 } catch (ImsException e) {
2986 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 } finally {
2988 Binder.restoreCallingIdentity(token);
2989 }
2990 }
2991
2992 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002993 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2994 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002995 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2996 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2997 }
Meng Wangafbc5852019-09-19 17:37:13 -07002998 final long token = Binder.clearCallingIdentity();
2999 try {
3000 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3001 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3002 .removeRegistrationCallbackForSubscription(c, subId);
3003 } catch (ImsException e) {
3004 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3005 + "is inactive, ignoring unregister.");
3006 // If the subscription is no longer active, just return, since the callback
3007 // will already have been removed internally.
3008 } finally {
3009 Binder.restoreCallingIdentity(token);
3010 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003011 }
3012
Brad Ebingera34a6c22019-10-22 17:36:18 -07003013 /**
3014 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3015 */
3016 @Override
3017 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3018 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3019 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3020 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3021 "IMS not available on device.");
3022 }
3023 final long token = Binder.clearCallingIdentity();
3024 try {
3025 Phone phone = getPhone(subId);
3026 if (phone == null) {
3027 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3028 + subId + "'");
3029 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3030 }
3031 phone.getImsRegistrationState(regState -> {
3032 try {
3033 consumer.accept((regState == null)
3034 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3035 } catch (RemoteException e) {
3036 // Ignore if the remote process is no longer available to call back.
3037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3038 }
3039 });
3040 } finally {
3041 Binder.restoreCallingIdentity(token);
3042 }
3043 }
3044
3045 /**
3046 * Get the transport type for the IMS service registration state.
3047 */
3048 @Override
3049 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3050 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3051 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3052 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3053 "IMS not available on device.");
3054 }
3055 final long token = Binder.clearCallingIdentity();
3056 try {
3057 Phone phone = getPhone(subId);
3058 if (phone == null) {
3059 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3060 + subId + "'");
3061 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3062 }
3063 phone.getImsRegistrationTech(regTech -> {
3064 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3065 int regTechConverted = (regTech == null)
3066 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3067 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3068 regTechConverted);
3069 try {
3070 consumer.accept(regTechConverted);
3071 } catch (RemoteException e) {
3072 // Ignore if the remote process is no longer available to call back.
3073 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3074 }
3075 });
3076 } finally {
3077 Binder.restoreCallingIdentity(token);
3078 }
3079 }
3080
Brad Ebinger35c841c2018-10-01 10:40:55 -07003081 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003082 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3083 throws RemoteException {
3084 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003085 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3086 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3087 "IMS not available on device.");
3088 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3090 final long token = Binder.clearCallingIdentity();
3091 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003092 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003093 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003094 } catch (ImsException e) {
3095 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003096 } finally {
3097 Binder.restoreCallingIdentity(token);
3098 }
3099 }
3100
3101 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003102 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3103 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003104 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3105 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3106 }
Meng Wangafbc5852019-09-19 17:37:13 -07003107
3108 final long token = Binder.clearCallingIdentity();
3109 try {
3110 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3111 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003112 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003113 } catch (ImsException e) {
3114 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3115 + "is inactive, ignoring unregister.");
3116 // If the subscription is no longer active, just return, since the callback
3117 // will already have been removed internally.
3118 } finally {
3119 Binder.restoreCallingIdentity(token);
3120 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003121 }
3122
3123 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003124 public boolean isCapable(int subId, int capability, int regTech) {
3125 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3127 final long token = Binder.clearCallingIdentity();
3128 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003129 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003130 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003131 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3133 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003134 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003135 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3136 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003137 } finally {
3138 Binder.restoreCallingIdentity(token);
3139 }
3140 }
3141
3142 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003143 public boolean isAvailable(int subId, int capability, int regTech) {
3144 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 final long token = Binder.clearCallingIdentity();
3146 try {
3147 Phone phone = getPhone(subId);
3148 if (phone == null) return false;
3149 return phone.isImsCapabilityAvailable(capability, regTech);
3150 } finally {
3151 Binder.restoreCallingIdentity(token);
3152 }
3153 }
3154
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003155 /**
3156 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3157 * subscription.
3158 * @param subId The subscription to use to check the configuration.
3159 * @param callback The callback that will be used to send the result.
3160 * @param capability The MmTelFeature capability that will be used to send the result.
3161 * @param transportType The transport type of the MmTelFeature capability.
3162 */
3163 @Override
3164 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3165 int transportType) {
3166 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3167 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3168 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3169 "IMS not available on device.");
3170 }
3171 final long token = Binder.clearCallingIdentity();
3172 try {
3173 int slotId = getSlotIndex(subId);
3174 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3175 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3176 + subId + "'");
3177 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3178 }
3179 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3180 transportType, aBoolean -> {
3181 try {
3182 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3183 } catch (RemoteException e) {
3184 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3185 + "running. Ignore");
3186 }
3187 });
3188 } finally {
3189 Binder.restoreCallingIdentity(token);
3190 }
3191 }
3192
Brad Ebinger35c841c2018-10-01 10:40:55 -07003193 @Override
3194 public boolean isAdvancedCallingSettingEnabled(int subId) {
3195 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3197 final long token = Binder.clearCallingIdentity();
3198 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003199 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003200 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003201 } catch (ImsException e) {
3202 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003203 } finally {
3204 Binder.restoreCallingIdentity(token);
3205 }
3206 }
3207
3208 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003209 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003211 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003215 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003217 } catch (ImsException e) {
3218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
3222 }
3223
3224 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003225 public boolean isVtSettingEnabled(int subId) {
3226 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003230 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3231 } catch (ImsException e) {
3232 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
3236 }
3237
3238 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003239 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003241 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003245 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003246 } catch (ImsException e) {
3247 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 } finally {
3249 Binder.restoreCallingIdentity(identity);
3250 }
3251 }
3252
3253 @Override
3254 public boolean isVoWiFiSettingEnabled(int subId) {
3255 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003259 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003261 } catch (ImsException e) {
3262 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003263 } finally {
3264 Binder.restoreCallingIdentity(identity);
3265 }
3266 }
3267
3268 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003269 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003271 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 final long identity = Binder.clearCallingIdentity();
3273 try {
3274 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003275 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003276 } catch (ImsException e) {
3277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
3281 }
3282
3283 @Override
3284 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3285 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3286 final long identity = Binder.clearCallingIdentity();
3287 try {
3288 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003289 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003291 } catch (ImsException e) {
3292 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003293 } finally {
3294 Binder.restoreCallingIdentity(identity);
3295 }
3296 }
3297
3298 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003299 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003301 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 final long identity = Binder.clearCallingIdentity();
3303 try {
3304 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003305 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003307 } catch (ImsException e) {
3308 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
3312 }
3313
3314 @Override
3315 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3317 "setVoWiFiNonPersistent");
3318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003321 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003322 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003323 } catch (ImsException e) {
3324 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
3328 }
3329
3330 @Override
3331 public int getVoWiFiModeSetting(int subId) {
3332 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003336 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003337 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003338 } catch (ImsException e) {
3339 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
3343 }
3344
3345 @Override
3346 public void setVoWiFiModeSetting(int subId, int mode) {
3347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3348 "setVoWiFiModeSetting");
3349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003352 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003354 } catch (ImsException e) {
3355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003356 } finally {
3357 Binder.restoreCallingIdentity(identity);
3358 }
3359 }
3360
3361 @Override
3362 public int getVoWiFiRoamingModeSetting(int subId) {
3363 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3364 final long identity = Binder.clearCallingIdentity();
3365 try {
3366 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003367 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003368 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003369 } catch (ImsException e) {
3370 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003371 } finally {
3372 Binder.restoreCallingIdentity(identity);
3373 }
3374 }
3375
3376 @Override
3377 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3379 "setVoWiFiRoamingModeSetting");
3380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003383 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003385 } catch (ImsException e) {
3386 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003387 } finally {
3388 Binder.restoreCallingIdentity(identity);
3389 }
3390 }
3391
3392 @Override
3393 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3395 "setRttCapabilityEnabled");
3396 final long identity = Binder.clearCallingIdentity();
3397 try {
3398 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003399 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3400 } catch (ImsException e) {
3401 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003402 } finally {
3403 Binder.restoreCallingIdentity(identity);
3404 }
3405 }
3406
3407 @Override
3408 public boolean isTtyOverVolteEnabled(int subId) {
3409 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003413 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003415 } catch (ImsException e) {
3416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
3420 }
3421
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003422 @Override
3423 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3424 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003428 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003429 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003430 } catch (ImsException e) {
3431 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
3435 }
3436
3437 @Override
3438 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3439 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3440 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003441 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3442 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3443 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003444 try {
3445 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003446 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003447 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003448 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003449 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3450 + "is inactive, ignoring unregister.");
3451 // If the subscription is no longer active, just return, since the callback will already
3452 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
3456 }
3457
allenwtsu99c623b2020-01-03 18:24:23 +08003458
3459 private void checkModifyPhoneStatePermission(int subId, String message) {
3460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3461 message);
3462 }
3463
3464 private boolean isImsProvisioningRequired(int subId, int capability,
3465 boolean isMmtelCapability) {
3466 Phone phone = getPhone(subId);
3467 if (phone == null) {
3468 loge("phone instance null for subid " + subId);
3469 return false;
3470 }
3471 if (isMmtelCapability) {
3472 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3473 return false;
3474 }
3475 } else {
3476 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3477 return false;
3478 }
3479 }
3480 return true;
3481 }
3482
3483 @Override
3484 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3485 boolean isProvisioned) {
3486 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3487
3488 final long identity = Binder.clearCallingIdentity();
3489 try {
3490 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3491 if (!isImsProvisioningRequired(subId, capability, false)) {
3492 return;
3493 }
3494
3495 // this capability requires provisioning, route to the correct API.
3496 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3497 switch (capability) {
3498 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3499 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3500 ims.setEabProvisioned(isProvisioned);
3501 break;
3502 default: {
3503 throw new IllegalArgumentException("Tried to set provisioning for "
3504 + "rcs capability '" + capability + "', which does not require "
3505 + "provisioning.");
3506 }
3507 }
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
3510 }
3511
3512 }
3513
3514
3515 @Override
3516 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3517 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3521 if (!isImsProvisioningRequired(subId, capability, false)) {
3522 return true;
3523 }
3524
3525 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3526 switch (capability) {
3527 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3528 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3529 return ims.isEabProvisionedOnDevice();
3530
3531 default: {
3532 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3533 + "capability '" + capability + "', which does not require "
3534 + "provisioning.");
3535 }
3536 }
3537
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
3541 }
3542
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003543 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003544 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3545 boolean isProvisioned) {
3546 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3547 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3548 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3549 }
allenwtsu99c623b2020-01-03 18:24:23 +08003550 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003554 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003555 return;
3556 }
3557
3558 // this capability requires provisioning, route to the correct API.
3559 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3560 switch (capability) {
3561 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3562 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3563 ims.setVolteProvisioned(isProvisioned);
3564 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3565 ims.setWfcProvisioned(isProvisioned);
3566 }
3567 break;
3568 }
3569 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3570 // There is currently no difference in VT provisioning type.
3571 ims.setVtProvisioned(isProvisioned);
3572 break;
3573 }
3574 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3575 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3576 // change the capability of the feature instead if needed.
3577 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3578 == isProvisioned) {
3579 // No change in provisioning.
3580 return;
3581 }
3582 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3583 try {
3584 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003585 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003586 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3587 + ", Exception" + e.getMessage());
3588 }
3589 break;
3590 }
3591 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003592 throw new IllegalArgumentException("Tried to set provisioning for "
3593 + "MmTel capability '" + capability + "', which does not require "
3594 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003595 }
3596 }
3597
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
3600 }
3601 }
3602
3603 @Override
3604 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3605 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3606 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3607 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3608 }
3609 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3610 final long identity = Binder.clearCallingIdentity();
3611 try {
3612 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003613 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003614 return true;
3615 }
3616
3617 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3618 switch (capability) {
3619 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3620 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3621 return ims.isVolteProvisionedOnDevice();
3622 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3623 return ims.isWfcProvisionedOnDevice();
3624 }
3625 // This should never happen, since we are checking tech above to make sure it
3626 // is either LTE or IWLAN.
3627 throw new IllegalArgumentException("Invalid radio technology for voice "
3628 + "capability.");
3629 }
3630 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3631 // There is currently no difference in VT provisioning type.
3632 return ims.isVtProvisionedOnDevice();
3633 }
3634 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3635 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3636 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3637 }
3638 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003639 throw new IllegalArgumentException(
3640 "Tried to get provisioning for MmTel capability '" + capability
3641 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003642 }
3643 }
3644
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
3648 }
3649
3650 @Override
3651 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3652 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3653 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3654 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3655 }
3656 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3657 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3658 return (provisionedBits & capability) > 0;
3659 }
3660
3661 @Override
3662 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3663 boolean isProvisioned) {
3664 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3665 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3666 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3667 }
3668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3669 "setProvisioningStatusForCapability");
3670 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3671 // If the current provisioning status for capability already matches isProvisioned,
3672 // do nothing.
3673 if (((provisionedBits & capability) > 0) == isProvisioned) {
3674 return;
3675 }
3676 if (isProvisioned) {
3677 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3678 } else {
3679 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3680 }
3681 }
3682
3683 /**
3684 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3685 * technology. The bitfield should mirror the bitfield defined by
3686 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3687 */
3688 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3689 String key = getMmTelProvisioningKey(subId, tech);
3690 // Default is no capabilities are provisioned.
3691 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3692 }
3693
3694 /**
3695 * Sets the MmTel capability provisioning bitfield (defined by
3696 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3697 * technology specified.
3698 *
3699 * Note: This is a synchronous command and should not be called on UI thread.
3700 */
3701 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3702 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3703 String key = getMmTelProvisioningKey(subId, tech);
3704 editor.putInt(key, newField);
3705 editor.commit();
3706 }
3707
3708 private static String getMmTelProvisioningKey(int subId, int tech) {
3709 // resulting key is provision_ims_mmtel_{subId}_{tech}
3710 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3711 }
3712
3713 /**
3714 * Query CarrierConfig to see if the specified capability requires provisioning for the
3715 * carrier associated with the subscription id.
3716 */
3717 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3718 int capability) {
3719 CarrierConfigManager configManager = new CarrierConfigManager(context);
3720 PersistableBundle c = configManager.getConfigForSubId(subId);
3721 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003722 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003723 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3724 false);
3725 boolean requireVoiceVtProvisioning = c.getBoolean(
3726 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3727
3728 // First check to make sure that the capability requires provisioning.
3729 switch (capability) {
3730 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3731 // intentional fallthrough
3732 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3733 if (requireVoiceVtProvisioning) {
3734 // Voice and Video requires provisioning
3735 return true;
3736 }
3737 break;
3738 }
3739 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3740 if (requireUtProvisioning) {
3741 // UT requires provisioning
3742 return true;
3743 }
3744 break;
3745 }
3746 }
3747 return false;
3748 }
3749
allenwtsu99c623b2020-01-03 18:24:23 +08003750 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3751 int capability) {
3752 CarrierConfigManager configManager = new CarrierConfigManager(context);
3753 PersistableBundle c = configManager.getConfigForSubId(subId);
3754
3755 boolean requireRcsProvisioning = c.getBoolean(
3756 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3757
3758 // First check to make sure that the capability requires provisioning.
3759 switch (capability) {
3760 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3761 // intentional fallthrough
3762 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3763 if (requireRcsProvisioning) {
3764 // OPTION or PRESENCE requires provisioning
3765 return true;
3766 }
3767 break;
3768 }
3769 }
3770 return false;
3771 }
3772
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003773 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003774 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3776 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3777 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003778 enforceReadPrivilegedPermission("getImsProvisioningInt");
3779 final long identity = Binder.clearCallingIdentity();
3780 try {
3781 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003782 int slotId = getSlotIndex(subId);
3783 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3784 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3785 + subId + "' for key:" + key);
3786 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3787 }
3788 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003789 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003790 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3791 + subId + "' for key:" + key);
3792 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003793 } finally {
3794 Binder.restoreCallingIdentity(identity);
3795 }
3796 }
3797
3798 @Override
3799 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003800 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3801 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3802 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003803 enforceReadPrivilegedPermission("getImsProvisioningString");
3804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003807 int slotId = getSlotIndex(subId);
3808 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3809 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3810 + subId + "' for key:" + key);
3811 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3812 }
3813 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003814 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003815 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3816 + subId + "' for key:" + key);
3817 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
3821 }
3822
3823 @Override
3824 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003825 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3826 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3827 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3829 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003830 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, "setImsProvisioningInt: called with an inactive subscription id '"
3836 + subId + "' for key:" + key);
3837 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3838 }
3839 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
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, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3842 + "' for key:" + key);
3843 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003844 } finally {
3845 Binder.restoreCallingIdentity(identity);
3846 }
3847 }
3848
3849 @Override
3850 public int setImsProvisioningString(int subId, int key, String 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 "setImsProvisioningString");
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, "setImsProvisioningString: 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, "setImsProvisioningString: 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
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003875 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003876 int slotId = SubscriptionManager.getSlotIndex(subId);
3877 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003878 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3879 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 }
3881 return slotId;
3882 }
3883
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003884 private int getSlotIndex(int subId) {
3885 int slotId = SubscriptionManager.getSlotIndex(subId);
3886 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3887 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3888 }
3889 return slotId;
3890 }
3891
Wink Saville36469e72014-06-11 15:17:00 -07003892 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003893 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003894 */
3895 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003896 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3897 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003898 final int targetSdk = getTargetSdk(callingPackage);
3899 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003900 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003901 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003902 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003903 mApp, subId, callingPackage, callingFeatureId,
3904 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003905 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3906 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 final Phone phone = getPhone(subId);
3911 if (phone != null) {
3912 return phone.getServiceState().getDataNetworkType();
3913 } else {
3914 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3915 }
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003919 }
3920
3921 /**
3922 * Returns the data network type
3923 */
3924 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003925 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3926 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3927 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003928 }
3929
3930 /**
3931 * Returns the data network type for a subId
3932 */
3933 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003934 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3935 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003937 mApp, subId, callingPackage, callingFeatureId,
3938 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003939 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3940 }
3941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 final Phone phone = getPhone(subId);
3945 if (phone != null) {
3946 return phone.getServiceState().getDataNetworkType();
3947 } else {
3948 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3949 }
3950 } finally {
3951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003953 }
3954
3955 /**
Wink Saville36469e72014-06-11 15:17:00 -07003956 * Returns the Voice network type for a subId
3957 */
3958 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003959 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3960 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003962 mApp, subId, callingPackage, callingFeatureId,
3963 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003964 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3965 }
3966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003967 final long identity = Binder.clearCallingIdentity();
3968 try {
3969 final Phone phone = getPhone(subId);
3970 if (phone != null) {
3971 return phone.getServiceState().getVoiceNetworkType();
3972 } else {
3973 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3974 }
3975 } finally {
3976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003978 }
3979
3980 /**
3981 * @return true if a ICC card is present
3982 */
3983 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003984 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003985 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3986 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003987 }
3988
3989 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003990 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003991 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003992 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003993 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 final Phone phone = PhoneFactory.getPhone(slotIndex);
3997 if (phone != null) {
3998 return phone.getIccCard().hasIccCard();
3999 } else {
4000 return false;
4001 }
4002 } finally {
4003 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004005 }
4006
4007 /**
4008 * Return if the current radio is LTE on CDMA. This
4009 * is a tri-state return value as for a period of time
4010 * the mode may be unknown.
4011 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004012 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004013 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004014 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004015 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004016 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004017 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4018 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4019 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004020 }
4021
Sanket Padawe356d7632015-06-22 14:03:32 -07004022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004023 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4024 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004026 mApp, subId, callingPackage, callingFeatureId,
4027 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004028 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4029 }
4030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031 final long identity = Binder.clearCallingIdentity();
4032 try {
4033 final Phone phone = getPhone(subId);
4034 if (phone == null) {
4035 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4036 } else {
4037 return phone.getLteOnCdmaMode();
4038 }
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004041 }
Wink Saville36469e72014-06-11 15:17:00 -07004042 }
4043
Wink Saville36469e72014-06-11 15:17:00 -07004044 /**
4045 * {@hide}
4046 * Returns Default subId, 0 in the case of single standby.
4047 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004048 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004049 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004050 }
4051
Shishir Agrawala9f32182016-04-12 12:00:16 -07004052 private int getSlotForDefaultSubscription() {
4053 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4054 }
4055
Wink Savilleb564aae2014-10-23 10:18:09 -07004056 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004057 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004058 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004059
Pengquan Menge92a50d2018-09-21 15:54:48 -07004060 private boolean isActiveSubscription(int subId) {
4061 return mSubscriptionController.isActiveSubId(subId);
4062 }
4063
Ihab Awadf2177b72013-11-25 13:33:23 -08004064 /**
4065 * @see android.telephony.TelephonyManager.WifiCallingChoices
4066 */
4067 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068 final long identity = Binder.clearCallingIdentity();
4069 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004070 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4072 getWhenToMakeWifiCallsDefaultPreference());
4073 } finally {
4074 Binder.restoreCallingIdentity(identity);
4075 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004076 }
4077
4078 /**
4079 * @see android.telephony.TelephonyManager.WifiCallingChoices
4080 */
4081 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004085 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004090 }
4091
Sailesh Nepald1e68152013-12-12 19:08:02 -08004092 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004093 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004094 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004095 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004096
Jordan Liu4c733742019-02-28 12:03:40 -08004097 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4098 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4099 if (phoneId == -1) {
4100 throw new IllegalArgumentException("Given slot index: " + slotIndex
4101 + " does not correspond to an active phone");
4102 }
4103 return PhoneFactory.getPhone(phoneId);
4104 }
4105
Shishir Agrawal566b7612013-10-28 14:41:00 -07004106 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004107 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4108 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4110 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004112 if (DBG) {
4113 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4114 }
4115 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4116 p2);
4117 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004118
Jordan Liu4c733742019-02-28 12:03:40 -08004119
4120 @Override
4121 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4122 int slotIndex, String callingPackage, String aid, int p2) {
4123 enforceModifyPermission();
4124 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4125 if (DBG) {
4126 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4127 }
4128 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4129 callingPackage, aid, p2);
4130 }
4131
4132 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4133 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 if (TextUtils.equals(ISDR_AID, aid)) {
4137 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004138 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4139 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 if (bestComponent == null
4141 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4142 loge("The calling package is not allowed to access ISD-R.");
4143 throw new SecurityException(
4144 "The calling package is not allowed to access ISD-R.");
4145 }
Derek Tan740e1672017-06-27 14:56:27 -07004146 }
Derek Tan740e1672017-06-27 14:56:27 -07004147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004149 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4150 null /* workSource */);
4151 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 return response;
4153 } finally {
4154 Binder.restoreCallingIdentity(identity);
4155 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004156 }
4157
4158 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004159 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4161 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004162 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4163 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4164 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004165
Jordan Liu4c733742019-02-28 12:03:40 -08004166 @Override
4167 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4168 enforceModifyPermission();
4169 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4170 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4171 channel);
4172 }
4173
4174 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004175 final long identity = Binder.clearCallingIdentity();
4176 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177 if (channel < 0) {
4178 return false;
4179 }
Jordan Liu4c733742019-02-28 12:03:40 -08004180 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4181 null /* workSource */);
4182 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 return success;
4184 } finally {
4185 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004186 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004187 }
4188
4189 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004190 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004191 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4193 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004194 if (DBG) {
4195 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4196 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4197 + p3 + " data=" + data);
4198 }
4199 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4200 command, p1, p2, p3, data);
4201 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004202
Jordan Liu4c733742019-02-28 12:03:40 -08004203 @Override
4204 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4205 int command, int p1, int p2, int p3, String data) {
4206 enforceModifyPermission();
4207 if (DBG) {
4208 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4209 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4210 + p3 + " data=" + data);
4211 }
4212 return iccTransmitApduLogicalChannelWithPermission(
4213 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4214 data);
4215 }
4216
4217 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4218 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219 final long identity = Binder.clearCallingIdentity();
4220 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004221 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004222 return "";
4223 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004225 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004226 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4227 null /* workSource */);
4228 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 // Append the returned status code to the end of the response payload.
4231 String s = Integer.toHexString(
4232 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4233 if (response.payload != null) {
4234 s = IccUtils.bytesToHexString(response.payload) + s;
4235 }
4236 return s;
4237 } finally {
4238 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004239 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004240 }
Jake Hambye994d462014-02-03 13:10:13 -08004241
Evan Charltonc66da362014-05-16 14:06:40 -07004242 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004243 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4244 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4246 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004248 if (DBG) {
4249 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4250 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4251 }
4252 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4253 cla, command, p1, p2, p3, data);
4254 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004255
Jordan Liu4c733742019-02-28 12:03:40 -08004256 @Override
4257 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4258 int command, int p1, int p2, int p3, String data) {
4259 enforceModifyPermission();
4260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4261 if (DBG) {
4262 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4263 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4264 + " data=" + data);
4265 }
4266
4267 return iccTransmitApduBasicChannelWithPermission(
4268 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4269 p2, p3, data);
4270 }
4271
4272 // open APDU basic channel assuming the caller has sufficient permissions
4273 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4274 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275 final long identity = Binder.clearCallingIdentity();
4276 try {
4277 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4278 && TextUtils.equals(ISDR_AID, data)) {
4279 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004280 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4281 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282 if (bestComponent == null
4283 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4284 loge("The calling package is not allowed to select ISD-R.");
4285 throw new SecurityException(
4286 "The calling package is not allowed to select ISD-R.");
4287 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004288 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004291 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4292 null /* workSource */);
4293 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295 // Append the returned status code to the end of the response payload.
4296 String s = Integer.toHexString(
4297 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4298 if (response.payload != null) {
4299 s = IccUtils.bytesToHexString(response.payload) + s;
4300 }
4301 return s;
4302 } finally {
4303 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004304 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004305 }
4306
4307 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004308 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004309 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4311 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 if (DBG) {
4316 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4317 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4318 }
4319
4320 IccIoResult response =
4321 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4322 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4323 subId);
4324
4325 if (DBG) {
4326 log("Exchange SIM_IO [R]" + response);
4327 }
4328
4329 byte[] result = null;
4330 int length = 2;
4331 if (response.payload != null) {
4332 length = 2 + response.payload.length;
4333 result = new byte[length];
4334 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4335 } else {
4336 result = new byte[length];
4337 }
4338
4339 result[length - 1] = (byte) response.sw2;
4340 result[length - 2] = (byte) response.sw1;
4341 return result;
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004344 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004345 }
4346
Nathan Haroldb3014052017-01-25 15:57:32 -08004347 /**
4348 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4349 * on a particular subscription
4350 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004351 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4352 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004353 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004354 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004355 return null;
4356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357
4358 final long identity = Binder.clearCallingIdentity();
4359 try {
4360 if (appType != TelephonyManager.APPTYPE_USIM
4361 && appType != TelephonyManager.APPTYPE_SIM) {
4362 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4363 return null;
4364 }
4365 Object response = sendRequest(
4366 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4367 if (response instanceof String[]) {
4368 return (String[]) response;
4369 }
yincheng zhao2737e882019-09-06 17:06:54 -07004370 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004372 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 } finally {
4374 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004375 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004376 }
4377
yincheng zhao2737e882019-09-06 17:06:54 -07004378 /**
4379 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4380 * subscription.
4381 *
4382 * @param subId the id of the subscription.
4383 * @param appType the uicc app type, must be USIM or SIM.
4384 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4385 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004386 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004387 * @return number of fplmns that is successfully written to the SIM.
4388 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004389 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4390 String callingFeatureId) {
4391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4392 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004393 if (DBG) logv("no permissions for setForbiddenplmns");
4394 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4395 }
4396 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4397 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4398 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4399 }
4400 if (fplmns == null) {
4401 throw new IllegalArgumentException("Fplmn List provided is null");
4402 }
4403 for (String fplmn : fplmns) {
4404 if (!CellIdentity.isValidPlmn(fplmn)) {
4405 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4406 }
4407 }
4408 final long identity = Binder.clearCallingIdentity();
4409 try {
4410 Object response = sendRequest(
4411 CMD_SET_FORBIDDEN_PLMNS,
4412 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4413 subId);
4414 return (int) response;
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
4418 }
4419
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004420 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004421 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4423 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004425 final long identity = Binder.clearCallingIdentity();
4426 try {
4427 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4428 if (response.payload == null) {
4429 return "";
4430 }
Evan Charltonc66da362014-05-16 14:06:40 -07004431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004432 // Append the returned status code to the end of the response payload.
4433 String s = Integer.toHexString(
4434 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4435 s = IccUtils.bytesToHexString(response.payload) + s;
4436 return s;
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
Evan Charltonc66da362014-05-16 14:06:40 -07004440 }
4441
Jake Hambye994d462014-02-03 13:10:13 -08004442 /**
4443 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4444 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4445 *
4446 * @param itemID the ID of the item to read
4447 * @return the NV item as a String, or null on error.
4448 */
4449 @Override
4450 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004451 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4453 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004454
4455 final long identity = Binder.clearCallingIdentity();
4456 try {
4457 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004458 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004459 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4460 return value;
4461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
Jake Hambye994d462014-02-03 13:10:13 -08004464 }
4465
4466 /**
4467 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4468 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4469 *
4470 * @param itemID the ID of the item to read
4471 * @param itemValue the value to write, as a String
4472 * @return true on success; false on any failure
4473 */
4474 @Override
4475 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004476 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4478 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479
4480 final long identity = Binder.clearCallingIdentity();
4481 try {
4482 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4483 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004484 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4486 return success;
4487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
Jake Hambye994d462014-02-03 13:10:13 -08004490 }
4491
4492 /**
4493 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4494 * Used for device configuration by some CDMA operators.
4495 *
4496 * @param preferredRoamingList byte array containing the new PRL
4497 * @return true on success; false on any failure
4498 */
4499 @Override
4500 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4502 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503
4504 final long identity = Binder.clearCallingIdentity();
4505 try {
4506 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4507 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4508 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4509 return success;
4510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
Jake Hambye994d462014-02-03 13:10:13 -08004513 }
4514
4515 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004516 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004517 * Used for device configuration by some CDMA operators.
4518 *
chen xu6dac5ab2018-10-26 17:39:23 -07004519 * @param slotIndex - device slot.
4520 *
Jake Hambye994d462014-02-03 13:10:13 -08004521 * @return true on success; false on any failure
4522 */
4523 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004524 public boolean resetModemConfig(int slotIndex) {
4525 Phone phone = PhoneFactory.getPhone(slotIndex);
4526 if (phone != null) {
4527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4528 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529
chen xu6dac5ab2018-10-26 17:39:23 -07004530 final long identity = Binder.clearCallingIdentity();
4531 try {
4532 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4533 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4534 return success;
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 }
chen xu6dac5ab2018-10-26 17:39:23 -07004539 return false;
4540 }
4541
4542 /**
4543 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4544 *
4545 * @param slotIndex - device slot.
4546 *
4547 * @return true on success; false on any failure
4548 */
4549 @Override
4550 public boolean rebootModem(int slotIndex) {
4551 Phone phone = PhoneFactory.getPhone(slotIndex);
4552 if (phone != null) {
4553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4554 mApp, phone.getSubId(), "rebootModem");
4555
4556 final long identity = Binder.clearCallingIdentity();
4557 try {
4558 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4559 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4560 return success;
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
4564 }
4565 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004566 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004567
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004568 public String[] getPcscfAddress(String apnType, String callingPackage,
4569 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004570 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4572 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004573 return new String[0];
4574 }
4575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 final long identity = Binder.clearCallingIdentity();
4577 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004578 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
Wink Saville36469e72014-06-11 15:17:00 -07004582 }
4583
Brad Ebinger51f743a2017-01-23 13:50:20 -08004584 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004585 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4586 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004587 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004588 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004593 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004594 // may happen if the device does not support IMS.
4595 return;
4596 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004597 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004601 }
4602
4603 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004604 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4605 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004606 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004607 public void disableIms(int slotId) {
4608 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609
4610 final long identity = Binder.clearCallingIdentity();
4611 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004612 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004613 // may happen if the device does not support IMS.
4614 return;
4615 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004616 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004617 } finally {
4618 Binder.restoreCallingIdentity(identity);
4619 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004620 }
4621
4622 /**
4623 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4624 * feature or {@link null} if the service is not available. If the feature is available, the
4625 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4626 */
4627 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004628 IImsServiceFeatureCallback callback) {
4629 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630
4631 final long identity = Binder.clearCallingIdentity();
4632 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004633 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004634 // may happen if the device does not support IMS.
4635 return null;
4636 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004637 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004641 }
4642
4643 /**
4644 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4645 * feature during emergency calling or {@link null} if the service is not available. If the
4646 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4647 * listener for feature updates.
4648 */
4649 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4650 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651
4652 final long identity = Binder.clearCallingIdentity();
4653 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004654 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004655 // may happen if the device does not support IMS.
4656 return null;
4657 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004658 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004662 }
4663
Brad Ebinger5f64b052017-12-14 14:26:15 -08004664 /**
4665 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004666 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004667 */
4668 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4669 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670
4671 final long identity = Binder.clearCallingIdentity();
4672 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004673 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004674 // may happen if the device does not support IMS.
4675 return null;
4676 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004677 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004678 } finally {
4679 Binder.restoreCallingIdentity(identity);
4680 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004681 }
4682
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004683 /**
4684 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004685 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004686 */
4687 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004692 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004693 // may happen if the device does not support IMS.
4694 return null;
4695 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004696 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004700 }
4701
Brad Ebinger884c07b2018-02-15 16:17:40 -08004702 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004703 * Sets the ImsService Package Name that Telephony will bind to.
4704 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004705 * @param slotIndex the slot ID that the ImsService should bind for.
4706 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004707 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004708 * @param featureTypes An integer array of feature types associated with a packageName.
4709 * @param packageName The name of the package that the current configuration will be replaced
4710 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004711 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004712 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004713 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4714 int[] featureTypes, String packageName) {
4715 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4716 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4718 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004719 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004720
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721 final long identity = Binder.clearCallingIdentity();
4722 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004723 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004724 // may happen if the device does not support IMS.
4725 return false;
4726 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004727 Map<Integer, String> featureConfig = new HashMap<>();
4728 for (int featureType : featureTypes) {
4729 featureConfig.put(featureType, packageName);
4730 }
4731 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4732 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004736 }
4737
4738 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004739 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004740 *
4741 * @param slotId The slot that the ImsService is associated with.
4742 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4743 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004744 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004745 * @return the package name of the ImsService configuration.
4746 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004747 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4748 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004749 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004750 TelephonyPermissions
4751 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4752 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4753 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004755 final long identity = Binder.clearCallingIdentity();
4756 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004757 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004758 // may happen if the device does not support IMS.
4759 return "";
4760 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004761 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004762 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4763 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 } finally {
4765 Binder.restoreCallingIdentity(identity);
4766 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004767 }
4768
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004769 /**
4770 * Get the MmTelFeature state associated with the requested subscription id.
4771 * @param subId The subscription that the MmTelFeature is associated with.
4772 * @param callback A callback with an integer containing the
4773 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4774 */
4775 @Override
4776 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4777 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4778 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4779 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4780 "IMS not available on device.");
4781 }
4782 final long token = Binder.clearCallingIdentity();
4783 try {
4784 int slotId = getSlotIndex(subId);
4785 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4786 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4787 + subId + "'");
4788 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4789 }
4790 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4791 try {
4792 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4793 } catch (RemoteException e) {
4794 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4795 + "Ignore");
4796 }
4797 });
4798 } finally {
4799 Binder.restoreCallingIdentity(token);
4800 }
4801 }
4802
Wink Saville36469e72014-06-11 15:17:00 -07004803 public void setImsRegistrationState(boolean registered) {
4804 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805
4806 final long identity = Binder.clearCallingIdentity();
4807 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004808 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 } finally {
4810 Binder.restoreCallingIdentity(identity);
4811 }
Wink Saville36469e72014-06-11 15:17:00 -07004812 }
4813
4814 /**
Stuart Scott54788802015-03-30 13:18:01 -07004815 * Set the network selection mode to automatic.
4816 *
4817 */
4818 @Override
4819 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4821 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822
Pengquan Menge92a50d2018-09-21 15:54:48 -07004823 if (!isActiveSubscription(subId)) {
4824 return;
4825 }
4826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827 final long identity = Binder.clearCallingIdentity();
4828 try {
4829 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4830 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
Stuart Scott54788802015-03-30 13:18:01 -07004834 }
4835
Pengquan Mengea84e042018-09-20 14:57:26 -07004836 /**
4837 * Ask the radio to connect to the input network and change selection mode to manual.
4838 *
4839 * @param subId the id of the subscription.
4840 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4841 * the operator to attach to.
4842 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4843 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4844 * normal network selection next time.
4845 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004846 */
4847 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004848 public boolean setNetworkSelectionModeManual(
4849 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4851 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004852
4853 if (!isActiveSubscription(subId)) {
4854 return false;
4855 }
4856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 final long identity = Binder.clearCallingIdentity();
4858 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004859 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004861 if (DBG) {
4862 log("setNetworkSelectionModeManual: subId: " + subId
4863 + " operator: " + operatorInfo);
4864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004869 }
4870
4871 /**
4872 * Scans for available networks.
4873 */
4874 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004875 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4876 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4878 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004879 LocationAccessPolicy.LocationPermissionResult locationResult =
4880 LocationAccessPolicy.checkLocationPermission(mApp,
4881 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4882 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004883 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004884 .setCallingPid(Binder.getCallingPid())
4885 .setCallingUid(Binder.getCallingUid())
4886 .setMethod("getCellNetworkScanResults")
4887 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4888 .build());
4889 switch (locationResult) {
4890 case DENIED_HARD:
4891 throw new SecurityException("Not allowed to access scan results -- location");
4892 case DENIED_SOFT:
4893 return null;
4894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895
Pengquan Menga1bb6272018-09-06 09:59:22 -07004896 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 try {
4898 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004899 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004904 }
4905
4906 /**
yinxub1bed742017-04-17 11:45:04 -07004907 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004908 *
yinxub1bed742017-04-17 11:45:04 -07004909 * @param subId id of the subscription
4910 * @param request contains the radio access networks with bands/channels to scan
4911 * @param messenger callback messenger for scan results or errors
4912 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004913 * @return the id of the requested scan which can be used to stop the scan.
4914 */
4915 @Override
4916 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004917 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4919 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004920 LocationAccessPolicy.LocationPermissionResult locationResult =
4921 LocationAccessPolicy.checkLocationPermission(mApp,
4922 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4923 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004924 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004925 .setCallingPid(Binder.getCallingPid())
4926 .setCallingUid(Binder.getCallingUid())
4927 .setMethod("requestNetworkScan")
4928 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4929 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004930 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004931 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004932 if (e != null) {
4933 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4934 throw e;
4935 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004936 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004937 return TelephonyScanManager.INVALID_SCAN_ID;
4938 }
4939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 }
Hall Liu912dfd32019-04-25 14:02:26 -07004941 int callingUid = Binder.getCallingUid();
4942 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004943 final long identity = Binder.clearCallingIdentity();
4944 try {
4945 return mNetworkScanRequestTracker.startNetworkScan(
4946 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004947 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
yinxu504e1392017-04-12 16:03:22 -07004951 }
4952
Hall Liub2ac8ef2019-02-28 15:56:23 -08004953 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004954 NetworkScanRequest request, int subId) {
4955 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4956 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4957 boolean hasNetworkScanPermission =
4958 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4959 == PERMISSION_GRANTED;
4960
4961 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4962 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4963 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004964 }
4965
4966 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4967 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004968 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4969 return new SecurityException("Specific channels must not be"
4970 + " scanned without location access.");
4971 }
4972 }
4973 }
4974
Hall Liub2ac8ef2019-02-28 15:56:23 -08004975 return null;
4976 }
4977
yinxu504e1392017-04-12 16:03:22 -07004978 /**
4979 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004980 *
4981 * @param subId id of the subscription
4982 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004983 */
4984 @Override
4985 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4987 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988
Hall Liu912dfd32019-04-25 14:02:26 -07004989 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 final long identity = Binder.clearCallingIdentity();
4991 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004992 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
yinxu504e1392017-04-12 16:03:22 -07004996 }
4997
4998 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004999 * Get the calculated preferred network type.
5000 * Used for debugging incorrect network type.
5001 *
5002 * @return the preferred network type, defined in RILConstants.java.
5003 */
5004 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005005 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005006 final Phone defaultPhone = getDefaultPhone();
5007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005008 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005009 return RILConstants.PREFERRED_NETWORK_MODE;
5010 }
5011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 final long identity = Binder.clearCallingIdentity();
5013 try {
5014 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005015 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 } finally {
5017 Binder.restoreCallingIdentity(identity);
5018 }
Junda Liu84d15a22014-07-02 11:21:04 -07005019 }
5020
5021 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005022 * Get the preferred network type.
5023 * Used for device configuration by some CDMA operators.
5024 *
5025 * @return the preferred network type, defined in RILConstants.java.
5026 */
5027 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005028 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005029 TelephonyPermissions
5030 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5031 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032
5033 final long identity = Binder.clearCallingIdentity();
5034 try {
5035 if (DBG) log("getPreferredNetworkType");
5036 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5037 int networkType = (result != null ? result[0] : -1);
5038 if (DBG) log("getPreferredNetworkType: " + networkType);
5039 return networkType;
5040 } finally {
5041 Binder.restoreCallingIdentity(identity);
5042 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005043 }
5044
5045 /**
5046 * Set the preferred network type.
5047 * Used for device configuration by some CDMA operators.
5048 *
5049 * @param networkType the preferred network type, defined in RILConstants.java.
5050 * @return true on success; false on any failure.
5051 */
5052 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005053 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5055 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056
5057 final long identity = Binder.clearCallingIdentity();
5058 try {
5059 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
5060 Boolean success = (Boolean) sendRequest(
5061 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5062 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5063 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005064 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5066 }
5067 return success;
5068 } finally {
5069 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005070 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005071 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005072
5073 /**
Miaoa84611c2019-03-15 09:21:10 +08005074 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005075 *
Miaoa84611c2019-03-15 09:21:10 +08005076 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005077 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005078 * @hide
5079 */
5080 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005081 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005082 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005084 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 try {
Miaoa84611c2019-03-15 09:21:10 +08005086 if (phone != null) {
5087 return phone.hasMatchedTetherApnSetting();
5088 } else {
5089 return false;
5090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 } finally {
5092 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005093 }
Junda Liu475951f2014-11-07 16:45:03 -08005094 }
5095
5096 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005097 * Set mobile data enabled
5098 * Used by the user through settings etc to turn on/off mobile data
5099 *
5100 * @param enable {@code true} turn turn data on, else {@code false}
5101 */
5102 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005103 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5105 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106
5107 final long identity = Binder.clearCallingIdentity();
5108 try {
5109 int phoneId = mSubscriptionController.getPhoneId(subId);
5110 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5111 Phone phone = PhoneFactory.getPhone(phoneId);
5112 if (phone != null) {
5113 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005114 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005116 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 }
5118 } finally {
5119 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005120 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005121 }
5122
5123 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005124 * Get the user enabled state of Mobile Data.
5125 *
5126 * TODO: remove and use isUserDataEnabled.
5127 * This can't be removed now because some vendor codes
5128 * calls through ITelephony directly while they should
5129 * use TelephonyManager.
5130 *
5131 * @return true on enabled
5132 */
5133 @Override
5134 public boolean getDataEnabled(int subId) {
5135 return isUserDataEnabled(subId);
5136 }
5137
5138 /**
5139 * Get whether mobile data is enabled per user setting.
5140 *
5141 * There are other factors deciding whether mobile data is actually enabled, but they are
5142 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005143 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005144 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005145 *
5146 * @return {@code true} if data is enabled else {@code false}
5147 */
5148 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005149 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005150 try {
5151 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5152 null);
5153 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5155 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157
5158 final long identity = Binder.clearCallingIdentity();
5159 try {
5160 int phoneId = mSubscriptionController.getPhoneId(subId);
5161 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5162 Phone phone = PhoneFactory.getPhone(phoneId);
5163 if (phone != null) {
5164 boolean retVal = phone.isUserDataEnabled();
5165 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5166 return retVal;
5167 } else {
5168 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5169 return false;
5170 }
5171 } finally {
5172 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005173 }
5174 }
5175
5176 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005177 * Checks if the device is capable of mobile data by considering whether whether the
5178 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5179 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005180 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005181 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005182 */
5183 @Override
5184 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005185 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186
5187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 int phoneId = mSubscriptionController.getPhoneId(subId);
5190 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5191 Phone phone = PhoneFactory.getPhone(phoneId);
5192 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005193 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5195 return retVal;
5196 } else {
5197 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5198 return false;
5199 }
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005202 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005203 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005204
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005205 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5206 Phone phone) {
5207 //load access rules from carrier configs, and check those as well: b/139133814
5208 SubscriptionController subController = SubscriptionController.getInstance();
5209 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5210 || subController == null) return privilegeFromSim;
5211
5212 int uid = Binder.getCallingUid();
5213 PackageManager pkgMgr = phone.getContext().getPackageManager();
5214 String[] packages = pkgMgr.getPackagesForUid(uid);
5215
5216 final long identity = Binder.clearCallingIdentity();
5217 try {
5218 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5219 SubscriptionManager subManager = (SubscriptionManager)
5220 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5221 for (String pkg : packages) {
5222 if (subManager.canManageSubscription(subInfo, pkg)) {
5223 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5224 }
5225 }
5226 return privilegeFromSim;
5227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
5230 }
5231
5232 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5233 String pkgName) {
5234 //load access rules from carrier configs, and check those as well: b/139133814
5235 SubscriptionController subController = SubscriptionController.getInstance();
5236 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5237 || subController == null) return privilegeFromSim;
5238
5239 final long identity = Binder.clearCallingIdentity();
5240 try {
5241 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5242 SubscriptionManager subManager = (SubscriptionManager)
5243 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5244 return subManager.canManageSubscription(subInfo, pkgName)
5245 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5246 } finally {
5247 Binder.restoreCallingIdentity(identity);
5248 }
5249 }
5250
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005251 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005252 public int getCarrierPrivilegeStatus(int subId) {
5253 final Phone phone = getPhone(subId);
5254 if (phone == null) {
5255 loge("getCarrierPrivilegeStatus: Invalid subId");
5256 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5257 }
5258 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005259 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005260 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005261 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5262 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005263
5264 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5265 card.getCarrierPrivilegeStatusForCurrentTransaction(
5266 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005267 }
Junda Liu29340342014-07-10 15:23:27 -07005268
5269 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005270 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005271 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005272 final Phone phone = getPhone(subId);
5273 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005274 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005275 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5276 }
5277 UiccProfile profile =
5278 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5279 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005280 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005281 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5282 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005283 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005284 profile.getCarrierPrivilegeStatusForUid(
5285 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005286 }
5287
5288 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005289 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5290 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005291 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005292 }
5293
5294 int phoneId = SubscriptionManager.getPhoneId(subId);
5295 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005296 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005297 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005298 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5299 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005300 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5301 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5302 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005303 }
5304
5305 @Override
5306 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005307 if (TextUtils.isEmpty(pkgName))
5308 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005309 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5310 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5311 UiccCard card = UiccController.getInstance().getUiccCard(i);
5312 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005313 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005314 continue;
5315 }
5316
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005317 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5318 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5319 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005320 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5321 break;
5322 }
5323 }
5324
5325 return result;
Junda Liu29340342014-07-10 15:23:27 -07005326 }
Derek Tan89e89d42014-07-08 17:00:10 -07005327
5328 @Override
Junda Liue64de782015-04-16 17:19:16 -07005329 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5330 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5331 loge("phoneId " + phoneId + " is not valid.");
5332 return null;
5333 }
5334 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005335 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005336 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005337 return null ;
5338 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005339 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005340 }
5341
Amith Yamasani6e118872016-02-19 12:53:51 -08005342 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005343 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005344 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005345 List<String> privilegedPackages = new ArrayList<>();
5346 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005347 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5348 // has UICC in that slot.
5349 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005350 if (card.hasCarrierPrivilegeRules()) {
5351 if (packages == null) {
5352 // Only check packages in user 0 for now
5353 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005354 PackageManager.MATCH_DISABLED_COMPONENTS
5355 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005356 | PackageManager.GET_SIGNING_CERTIFICATES,
5357 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005358 }
5359 for (int p = packages.size() - 1; p >= 0; p--) {
5360 PackageInfo pkgInfo = packages.get(p);
5361 if (pkgInfo != null && pkgInfo.packageName != null
5362 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005363 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005364 privilegedPackages.add(pkgInfo.packageName);
5365 }
5366 }
5367 }
5368 }
5369 return privilegedPackages;
5370 }
5371
chen xuf7e9fe82019-05-09 19:31:02 -07005372 @Override
5373 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005374 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5375
5376 final long identity = Binder.clearCallingIdentity();
5377
chen xuf7e9fe82019-05-09 19:31:02 -07005378 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005379 try {
5380 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5381 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5382 }
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005385 }
5386 return privilegedPackages;
5387 }
5388
Wink Savilleb564aae2014-10-23 10:18:09 -07005389 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005390 final Phone phone = getPhone(subId);
5391 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005392 if (card == null) {
5393 loge("getIccId: No UICC");
5394 return null;
5395 }
5396 String iccId = card.getIccId();
5397 if (TextUtils.isEmpty(iccId)) {
5398 loge("getIccId: ICC ID is null or empty.");
5399 return null;
5400 }
5401 return iccId;
5402 }
5403
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005404 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005405 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5406 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005407 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005408 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 final String iccId = getIccId(subId);
5413 final Phone phone = getPhone(subId);
5414 if (phone == null) {
5415 return false;
5416 }
5417 final String subscriberId = phone.getSubscriberId();
5418
5419 if (DBG_MERGE) {
5420 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5421 + subscriberId + " to " + number);
5422 }
5423
5424 if (TextUtils.isEmpty(iccId)) {
5425 return false;
5426 }
5427
5428 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5429
5430 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5431 if (alphaTag == null) {
5432 editor.remove(alphaTagPrefKey);
5433 } else {
5434 editor.putString(alphaTagPrefKey, alphaTag);
5435 }
5436
5437 // Record both the line number and IMSI for this ICCID, since we need to
5438 // track all merged IMSIs based on line number
5439 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5440 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5441 if (number == null) {
5442 editor.remove(numberPrefKey);
5443 editor.remove(subscriberPrefKey);
5444 } else {
5445 editor.putString(numberPrefKey, number);
5446 editor.putString(subscriberPrefKey, subscriberId);
5447 }
5448
5449 editor.commit();
5450 return true;
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005453 }
Derek Tan7226c842014-07-02 17:42:23 -07005454 }
5455
5456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005457 public String getLine1NumberForDisplay(int subId, String callingPackage,
5458 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005459 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005461 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005462 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005463 return null;
5464 }
Derek Tan97ebb422014-09-05 16:55:38 -07005465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 String iccId = getIccId(subId);
5469 if (iccId != null) {
5470 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5471 if (DBG_MERGE) {
5472 log("getLine1NumberForDisplay returning "
5473 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5474 }
5475 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5478 return null;
5479 } finally {
5480 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005481 }
Derek Tan7226c842014-07-02 17:42:23 -07005482 }
5483
5484 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005485 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5486 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005488 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005489 return null;
5490 }
Derek Tan97ebb422014-09-05 16:55:38 -07005491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 String iccId = getIccId(subId);
5495 if (iccId != null) {
5496 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5497 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5498 }
5499 return null;
5500 } finally {
5501 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005502 }
Derek Tan7226c842014-07-02 17:42:23 -07005503 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005504
5505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005506 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5507 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005508 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5509 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005511 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005512 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005513 return null;
5514 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005515
Jordan Liub49b04b2019-05-06 14:45:15 -07005516 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5517 // the process, where TelephonyManager was instantiated.
5518 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005519 final long identity = Binder.clearCallingIdentity();
5520 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005521 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 final TelephonyManager tele = TelephonyManager.from(context);
5523 final SubscriptionManager sub = SubscriptionManager.from(context);
5524
5525 // Figure out what subscribers are currently active
5526 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527
Jordan Liub49b04b2019-05-06 14:45:15 -07005528 // Only consider subs which match the current subId
5529 // This logic can be simplified. See b/131189269 for progress.
5530 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005531 activeSubscriberIds.add(tele.getSubscriberId(subId));
5532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533
5534 // First pass, find a number override for an active subscriber
5535 String mergeNumber = null;
5536 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5537 for (String key : prefs.keySet()) {
5538 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5539 final String subscriberId = (String) prefs.get(key);
5540 if (activeSubscriberIds.contains(subscriberId)) {
5541 final String iccId = key.substring(
5542 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5543 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5544 mergeNumber = (String) prefs.get(numberKey);
5545 if (DBG_MERGE) {
5546 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5547 + " for active subscriber " + subscriberId);
5548 }
5549 if (!TextUtils.isEmpty(mergeNumber)) {
5550 break;
5551 }
5552 }
5553 }
5554 }
5555
5556 // Shortcut when no active merged subscribers
5557 if (TextUtils.isEmpty(mergeNumber)) {
5558 return null;
5559 }
5560
5561 // Second pass, find all subscribers under that line override
5562 final ArraySet<String> result = new ArraySet<>();
5563 for (String key : prefs.keySet()) {
5564 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5565 final String number = (String) prefs.get(key);
5566 if (mergeNumber.equals(number)) {
5567 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5568 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5569 final String subscriberId = (String) prefs.get(subscriberKey);
5570 if (!TextUtils.isEmpty(subscriberId)) {
5571 result.add(subscriberId);
5572 }
5573 }
5574 }
5575 }
5576
5577 final String[] resultArray = result.toArray(new String[result.size()]);
5578 Arrays.sort(resultArray);
5579 if (DBG_MERGE) {
5580 Slog.d(LOG_TAG,
5581 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5582 }
5583 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005584 } finally {
5585 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005586 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005587 }
5588
5589 @Override
zoey chen38003472019-12-13 17:16:31 +08005590 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5591 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005592
5593 final long identity = Binder.clearCallingIdentity();
5594 try {
5595 final TelephonyManager telephonyManager = mApp.getSystemService(
5596 TelephonyManager.class);
5597 String subscriberId = telephonyManager.getSubscriberId(subId);
5598 if (subscriberId == null) {
5599 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005600 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005601 + subId);
5602 }
5603 return null;
5604 }
5605
5606 final SubscriptionInfo info = SubscriptionController.getInstance()
5607 .getSubscriptionInfo(subId);
5608 final ParcelUuid groupUuid = info.getGroupUuid();
5609 // If it doesn't belong to any group, return just subscriberId of itself.
5610 if (groupUuid == null) {
5611 return new String[]{subscriberId};
5612 }
5613
5614 // Get all subscriberIds from the group.
5615 final List<String> mergedSubscriberIds = new ArrayList<>();
5616 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005617 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5618 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005619 for (SubscriptionInfo subInfo : groupInfos) {
5620 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5621 if (subscriberId != null) {
5622 mergedSubscriberIds.add(subscriberId);
5623 }
5624 }
5625
5626 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629
5630 }
5631 }
5632
5633 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005634 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005635 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005636 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637
5638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 final Phone phone = getPhone(subId);
5641 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005645 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005646
5647 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005648 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005649 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5650 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005651 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5652 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653
5654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 final Phone phone = getPhone(subId);
5657 if (phone == null) {
5658 return false;
5659 }
5660 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5661 cdmaNonRoamingList);
5662 } finally {
5663 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005664 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005665 }
5666
5667 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005668 @Deprecated
5669 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5670 enforceModifyPermission();
5671
5672 int returnValue = 0;
5673 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005674 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005675 if(result.exception == null) {
5676 if (result.result != null) {
5677 byte[] responseData = (byte[])(result.result);
5678 if(responseData.length > oemResp.length) {
5679 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5680 responseData.length + "bytes. Buffer Size is " +
5681 oemResp.length + "bytes.");
5682 }
5683 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5684 returnValue = responseData.length;
5685 }
5686 } else {
5687 CommandException ex = (CommandException) result.exception;
5688 returnValue = ex.getCommandError().ordinal();
5689 if(returnValue > 0) returnValue *= -1;
5690 }
5691 } catch (RuntimeException e) {
5692 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5693 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5694 if(returnValue > 0) returnValue *= -1;
5695 }
5696
5697 return returnValue;
5698 }
5699
5700 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005701 public void setRadioCapability(RadioAccessFamily[] rafs) {
5702 try {
5703 ProxyController.getInstance().setRadioCapability(rafs);
5704 } catch (RuntimeException e) {
5705 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5706 }
5707 }
5708
5709 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005710 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005711 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005712 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005713 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005714 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 final long identity = Binder.clearCallingIdentity();
5717 try {
chen xub97461a2018-10-26 14:17:57 -07005718 TelephonyPermissions
5719 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5720 mApp, phone.getSubId(), "getRadioAccessFamily");
5721 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
chen xub97461a2018-10-26 14:17:57 -07005725 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005726 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005727
5728 @Override
5729 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005730 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005735 ImsManager.getInstance(defaultPhone.getContext(),
5736 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005740 }
5741
5742 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005743 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005744 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5746 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005747 return false;
5748 }
Svet Ganovb320e182015-04-16 12:30:10 -07005749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 final long identity = Binder.clearCallingIdentity();
5751 try {
5752 // Check the user preference and the system-level IMS setting. Even if the user has
5753 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5754 // In the long run, we may instead need to check if there exists a connection service
5755 // which can support video calling.
5756 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005757 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758 return imsManager.isVtEnabledByPlatform()
5759 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5760 && imsManager.isVtEnabledByUser();
5761 } finally {
5762 Binder.restoreCallingIdentity(identity);
5763 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005764 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005765
Andrew Leea1239f22015-03-02 17:44:07 -08005766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005767 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5768 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005770 mApp, subId, callingPackage, callingFeatureId,
5771 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 return false;
5773 }
5774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 CarrierConfigManager configManager =
5778 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005779 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
Andrew Leea1239f22015-03-02 17:44:07 -08005784 }
5785
5786 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005787 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005789 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 return false;
5791 }
5792
5793 final long identity = Binder.clearCallingIdentity();
5794 try {
5795 CarrierConfigManager configManager =
5796 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005797 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
5801 }
Andrew Leea1239f22015-03-02 17:44:07 -08005802 }
5803
Andrew Lee9431b832015-03-09 18:46:45 -07005804 @Override
5805 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005806 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005807 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005808 }
5809
5810 @Override
5811 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 final long identity = Binder.clearCallingIdentity();
5813 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005814 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
Andrew Lee9431b832015-03-09 18:46:45 -07005818 }
5819
Hall Liuf6668912018-10-31 17:05:23 -07005820 /**
5821 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5822 * support for the feature and device firmware support.
5823 *
5824 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5825 */
5826 @Override
5827 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005829 final Phone phone = getPhone(subscriptionId);
5830 if (phone == null) {
5831 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5832 return false;
5833 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005835 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5837 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005838 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 return isCarrierSupported && isDeviceSupported;
5840 } finally {
5841 Binder.restoreCallingIdentity(identity);
5842 }
Hall Liu98187582018-01-22 19:15:32 -08005843 }
5844
Hall Liuf6668912018-10-31 17:05:23 -07005845 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005846 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5847 * RTT setting, will return true if the device and carrier both support RTT.
5848 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005849 */
5850 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 final long identity = Binder.clearCallingIdentity();
5852 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005853 boolean isRttSupported = isRttSupported(subscriptionId);
5854 boolean isUserRttSettingOn = Settings.Secure.getInt(
5855 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5856 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5857 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5858 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005862 }
5863
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005864 @Deprecated
5865 @Override
5866 public String getDeviceId(String callingPackage) {
5867 return getDeviceIdWithFeature(callingPackage, null);
5868 }
5869
Sanket Padawe7310cc72015-01-14 09:53:20 -08005870 /**
5871 * Returns the unique device ID of phone, for example, the IMEI for
5872 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5873 *
5874 * <p>Requires Permission:
5875 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5876 */
5877 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005878 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005879 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005880 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005881 return null;
5882 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005883 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005884 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005885 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005886 return null;
5887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888
5889 final long identity = Binder.clearCallingIdentity();
5890 try {
5891 return phone.getDeviceId();
5892 } finally {
5893 Binder.restoreCallingIdentity(identity);
5894 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005895 }
5896
Ping Sunc67b7c22016-03-02 19:16:45 +08005897 /**
5898 * {@hide}
5899 * Returns the IMS Registration Status on a particular subid
5900 *
5901 * @param subId
5902 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005903 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005904 Phone phone = getPhone(subId);
5905 if (phone != null) {
5906 return phone.isImsRegistered();
5907 } else {
5908 return false;
5909 }
5910 }
5911
Santos Cordon7a1885b2015-02-03 11:15:19 -08005912 @Override
5913 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5917 } finally {
5918 Binder.restoreCallingIdentity(identity);
5919 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005920 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005921
Tyler Gunnf70ed162019-04-03 15:28:53 -07005922 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005923 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005924 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005926 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005927 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5928 }
5929 final long identity = Binder.clearCallingIdentity();
5930 try {
5931 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
5935 }
5936
5937 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005938 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5939 final long identity = Binder.clearCallingIdentity();
5940 try {
5941 Phone phone = getPhone(subscriptionId);
5942 if (phone == null) {
5943 return null;
5944 }
5945 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5946 } finally {
5947 Binder.restoreCallingIdentity(identity);
5948 }
5949 }
5950
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005951 /**
5952 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005953 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005954 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 final long identity = Binder.clearCallingIdentity();
5956 try {
5957 Phone phone = getPhone(subId);
5958 if (phone != null) {
5959 return phone.isWifiCallingEnabled();
5960 } else {
5961 return false;
5962 }
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005965 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005966 }
5967
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005968 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005969 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005970 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005971 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 final long identity = Binder.clearCallingIdentity();
5973 try {
5974 Phone phone = getPhone(subId);
5975 if (phone != null) {
5976 return phone.isVideoEnabled();
5977 } else {
5978 return false;
5979 }
5980 } finally {
5981 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005982 }
5983 }
5984
5985 /**
5986 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5987 * defined in {@link ImsRegistrationImplBase}.
5988 */
5989 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 final long identity = Binder.clearCallingIdentity();
5991 try {
5992 Phone phone = getPhone(subId);
5993 if (phone != null) {
5994 return phone.getImsRegistrationTech();
5995 } else {
5996 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5997 }
5998 } finally {
5999 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006000 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006001 }
6002
Stuart Scott8eef64f2015-04-08 15:13:54 -07006003 @Override
6004 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006005 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006006 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6007 return;
6008 }
6009
Svet Ganovcc087f82015-05-12 20:35:54 -07006010 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006011
Svet Ganovcc087f82015-05-12 20:35:54 -07006012 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006013 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6014 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006015 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006016 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006017 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006018 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6019 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006020 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006021 // There has been issues when Sms raw table somehow stores orphan
6022 // fragments. They lead to garbled message when new fragments come
6023 // in and combined with those stale ones. In case this happens again,
6024 // user can reset all network settings which will clean up this table.
6025 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006026 // Clean up IMS settings as well here.
6027 int slotId = getSlotIndex(subId);
6028 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6029 ImsManager.getInstance(mApp, slotId).factoryReset();
6030 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006031
6032 // Erase modem config if erase modem on network setting is enabled.
6033 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6034 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6035 if (configValue != null && Boolean.parseBoolean(configValue)) {
6036 sendEraseModemConfig(getDefaultPhone());
6037 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006038 } finally {
6039 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006040 }
6041 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006042
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006043 private void cleanUpSmsRawTable(Context context) {
6044 ContentResolver resolver = context.getContentResolver();
6045 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6046 resolver.delete(uri, null, null);
6047 }
6048
Narayan Kamath1c496c22015-04-16 14:40:19 +01006049 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006050 public String getSimLocaleForSubscriber(int subId) {
6051 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6052 final Phone phone = getPhone(subId);
6053 if (phone == null) {
6054 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006055 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 final long identity = Binder.clearCallingIdentity();
6058 try {
chen xu5d3637b2019-01-21 23:31:38 -08006059 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006060 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006061 if (info == null) {
6062 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6063 return null;
6064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 // Try and fetch the locale from the carrier properties or from the SIM language
6066 // preferences (EF-PL and EF-LI)...
6067 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006069 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6070 if (localeFromDefaultSim != null) {
6071 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6072 if (DBG) log("Using locale from subId: " + subId + " locale: "
6073 + localeFromDefaultSim);
6074 return localeFromDefaultSim.toLanguageTag();
6075 } else {
6076 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 }
6078 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 // The SIM language preferences only store a language (e.g. fr = French), not an
6081 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6082 // the SIM and carrier preferences does not include a country we add the country
6083 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006084 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006086 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 return mccLocale.toLanguageTag();
6088 }
6089
6090 if (DBG) log("No locale found - returning null");
6091 return null;
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
6094 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006095 }
6096
6097 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006098 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6099 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006100 }
6101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 /**
6103 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6104 */
6105 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006106 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6107 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006108 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006109
Chenjie Yu1ba97252018-01-11 18:16:20 -08006110 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006111 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006112
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006113 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006114 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6115 * representing the state of the modem.
6116 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006117 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6118 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006119 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006120 */
6121 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006122 public void requestModemActivityInfo(ResultReceiver result) {
6123 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006124 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125
6126 final long identity = Binder.clearCallingIdentity();
6127 try {
6128 ModemActivityInfo ret = null;
6129 synchronized (mLastModemActivityInfo) {
6130 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6131 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006132 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006133 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006135 int[] txTimeMs = info.getTransmitTimeMillis();
6136 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006138 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 }
6140 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006141 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6142 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 mLastModemActivityInfo.setIdleTimeMillis(
6144 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006145 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6146 mLastModemActivityInfo.setReceiveTimeMillis(
6147 info.getReceiveTimeMillis() + mLastModemActivityInfo
6148 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006149 }
Chen Xud78231e2019-09-10 18:49:52 -07006150
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6152 mLastModemActivityInfo.getSleepTimeMillis(),
6153 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006154 mLastModemActivityInfo.getTransmitTimeMillis(),
6155 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 Bundle bundle = new Bundle();
6158 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6159 result.send(0, bundle);
6160 } finally {
6161 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006162 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006163 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006164
Siddharth Rayb8114062018-06-17 15:02:38 -07006165 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6166 // less than total activity duration.
6167 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6168 if (info == null) {
6169 return false;
6170 }
6171 int activityDurationMs =
6172 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6173 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006174 int[] txTimeMs = info.getTransmitTimeMillis();
6175 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6176 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006177 }
6178 return (info.isValid()
6179 && (info.getSleepTimeMillis() <= activityDurationMs)
6180 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006181 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006182 && (totalTxTimeMs <= activityDurationMs));
6183 }
6184
Jack Yu85bd38a2015-11-09 11:34:32 -08006185 /**
6186 * {@hide}
6187 * Returns the service state information on specified subscription.
6188 */
6189 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006190 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6191 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006193 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006194 return null;
6195 }
6196
Hall Liuf19c44f2018-11-27 14:38:17 -08006197 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6198 LocationAccessPolicy.checkLocationPermission(mApp,
6199 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6200 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006201 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006202 .setCallingPid(Binder.getCallingPid())
6203 .setCallingUid(Binder.getCallingUid())
6204 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006205 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006206 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6207 .build());
6208
6209 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6210 LocationAccessPolicy.checkLocationPermission(mApp,
6211 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6212 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006213 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006214 .setCallingPid(Binder.getCallingPid())
6215 .setCallingUid(Binder.getCallingUid())
6216 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006217 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006218 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6219 .build());
6220 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6221 boolean hasFinePermission =
6222 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6223 boolean hasCoarsePermission =
6224 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 final long identity = Binder.clearCallingIdentity();
6227 try {
6228 final Phone phone = getPhone(subId);
6229 if (phone == null) {
6230 return null;
6231 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006232
Hall Liuf19c44f2018-11-27 14:38:17 -08006233 ServiceState ss = phone.getServiceState();
6234
6235 // Scrub out the location info in ServiceState depending on what level of access
6236 // the caller has.
6237 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006238 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6239 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 } finally {
6241 Binder.restoreCallingIdentity(identity);
6242 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006243 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006244
6245 /**
6246 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6247 *
6248 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6249 * voicemail ringtone.
6250 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6251 * PhoneAccount.
6252 */
6253 @Override
6254 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 final long identity = Binder.clearCallingIdentity();
6256 try {
6257 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6258 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006259 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6263 } finally {
6264 Binder.restoreCallingIdentity(identity);
6265 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006266 }
6267
6268 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006269 * Sets the per-account voicemail ringtone.
6270 *
6271 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6272 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6273 *
6274 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6275 * voicemail ringtone.
6276 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6277 * PhoneAccount.
6278 */
6279 @Override
6280 public void setVoicemailRingtoneUri(String callingPackage,
6281 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006282 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006283 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006284 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6285 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6287 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6288 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290
6291 final long identity = Binder.clearCallingIdentity();
6292 try {
6293 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6294 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006295 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296 }
6297 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6298 } finally {
6299 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006300 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006301 }
6302
6303 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006304 * Returns whether vibration is set for voicemail notification in Phone settings.
6305 *
6306 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6307 * voicemail vibration setting.
6308 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6309 */
6310 @Override
6311 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 final long identity = Binder.clearCallingIdentity();
6313 try {
6314 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6315 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006316 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6320 } finally {
6321 Binder.restoreCallingIdentity(identity);
6322 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006323 }
6324
Youhan Wange64578a2016-05-02 15:32:42 -07006325 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006326 * Sets the per-account voicemail vibration.
6327 *
6328 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6329 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6330 *
6331 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6332 * voicemail vibration setting.
6333 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6334 * specific PhoneAccount.
6335 */
6336 @Override
6337 public void setVoicemailVibrationEnabled(String callingPackage,
6338 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006339 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006340 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006341 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6342 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6344 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6345 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006346 }
6347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 final long identity = Binder.clearCallingIdentity();
6349 try {
6350 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6351 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006352 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 }
6354 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6355 } finally {
6356 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006357 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006358 }
6359
6360 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006361 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6362 *
6363 * @throws SecurityException if the caller does not have the required permission
6364 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006365 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006366 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006367 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006368 }
6369
6370 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006371 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6372 * permission.
6373 *
6374 * @throws SecurityException if the caller does not have the required permission
6375 */
6376 private void enforceSendSmsPermission() {
6377 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6378 }
6379
6380 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006381 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006382 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006383 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006384 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006385 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 final long identity = Binder.clearCallingIdentity();
6387 try {
6388 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006389 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 if (componentName == null) {
6391 throw new SecurityException(
6392 "Caller not current active visual voicemail package[null]");
6393 }
6394 String vvmPackage = componentName.getPackageName();
6395 if (!callingPackage.equals(vvmPackage)) {
6396 throw new SecurityException("Caller not current active visual voicemail package["
6397 + vvmPackage + "]");
6398 }
6399 } finally {
6400 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006401 }
6402 }
6403
6404 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006405 * Return the application ID for the app type.
6406 *
6407 * @param subId the subscription ID that this request applies to.
6408 * @param appType the uicc app type.
6409 * @return Application ID for specificied app type, or null if no uicc.
6410 */
6411 @Override
6412 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006413 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006414 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415
6416 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006417 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418 if (phone == null) {
6419 return null;
6420 }
6421 String aid = null;
6422 try {
6423 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6424 .getApplicationByType(appType).getAid();
6425 } catch (Exception e) {
6426 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6427 }
6428 return aid;
6429 } finally {
6430 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006431 }
Youhan Wange64578a2016-05-02 15:32:42 -07006432 }
6433
Youhan Wang4001d252016-05-11 10:29:41 -07006434 /**
6435 * Return the Electronic Serial Number.
6436 *
6437 * @param subId the subscription ID that this request applies to.
6438 * @return ESN or null if error.
6439 */
6440 @Override
6441 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006442 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006443 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444
6445 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006446 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 if (phone == null) {
6448 return null;
6449 }
6450 String esn = null;
6451 try {
6452 esn = phone.getEsn();
6453 } catch (Exception e) {
6454 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6455 }
6456 return esn;
6457 } finally {
6458 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006459 }
Youhan Wang4001d252016-05-11 10:29:41 -07006460 }
6461
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006462 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006463 * Return the Preferred Roaming List Version.
6464 *
6465 * @param subId the subscription ID that this request applies to.
6466 * @return PRLVersion or null if error.
6467 */
6468 @Override
6469 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006470 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006471 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472
6473 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006474 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475 if (phone == null) {
6476 return null;
6477 }
6478 String cdmaPrlVersion = null;
6479 try {
6480 cdmaPrlVersion = phone.getCdmaPrlVersion();
6481 } catch (Exception e) {
6482 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6483 }
6484 return cdmaPrlVersion;
6485 } finally {
6486 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006487 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006488 }
6489
6490 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006491 * Get snapshot of Telephony histograms
6492 * @return List of Telephony histograms
6493 * @hide
6494 */
6495 @Override
6496 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6498 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499
6500 final long identity = Binder.clearCallingIdentity();
6501 try {
6502 return RIL.getTelephonyRILTimingHistograms();
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006506 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006507
6508 /**
6509 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006510 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6511 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006512 * Require system privileges. In the future we may add this to carrier APIs.
6513 *
Michele Berionne482f8202018-11-27 18:57:59 -08006514 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006515 */
6516 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006517 @TelephonyManager.SetCarrierRestrictionResult
6518 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006519 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006521
Michele Berionne482f8202018-11-27 18:57:59 -08006522 if (carrierRestrictionRules == null) {
6523 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006524 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 final long identity = Binder.clearCallingIdentity();
6527 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006528 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006529 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 } finally {
6531 Binder.restoreCallingIdentity(identity);
6532 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006533 }
6534
6535 /**
6536 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006537 * Get the allowed carrier list and the excluded carrier list, including the priority between
6538 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006539 * Require system privileges. In the future we may add this to carrier APIs.
6540 *
Michele Berionne482f8202018-11-27 18:57:59 -08006541 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006542 */
6543 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006544 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006545 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006546 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547
6548 final long identity = Binder.clearCallingIdentity();
6549 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006550 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6551 if (response instanceof CarrierRestrictionRules) {
6552 return (CarrierRestrictionRules) response;
6553 }
6554 // Response is an Exception of some kind,
6555 // which is signalled to the user as a NULL retval
6556 return null;
6557 } catch (Exception e) {
6558 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6559 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006563 }
6564
fionaxu59545b42016-05-25 15:53:37 -07006565 /**
6566 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6567 * @param subId the subscription ID that this action applies to.
6568 * @param enabled control enable or disable metered apns.
6569 * {@hide}
6570 */
6571 @Override
6572 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6573 enforceModifyPermission();
6574 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006575
6576 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006577 if (phone == null) {
6578 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6579 return;
6580 }
6581 try {
6582 phone.carrierActionSetMeteredApnsEnabled(enabled);
6583 } catch (Exception e) {
6584 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006585 } finally {
6586 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006587 }
6588 }
6589
6590 /**
6591 * Action set from carrier signalling broadcast receivers to enable/disable radio
6592 * @param subId the subscription ID that this action applies to.
6593 * @param enabled control enable or disable radio.
6594 * {@hide}
6595 */
6596 @Override
6597 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6598 enforceModifyPermission();
6599 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600
6601 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006602 if (phone == null) {
6603 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6604 return;
6605 }
6606 try {
6607 phone.carrierActionSetRadioEnabled(enabled);
6608 } catch (Exception e) {
6609 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 } finally {
6611 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006612 }
6613 }
6614
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006615 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006616 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6617 * network status based on which carrier apps could apply actions accordingly,
6618 * enable/disable default url handler for example.
6619 *
6620 * @param subId the subscription ID that this action applies to.
6621 * @param report control start/stop reporting the default network status.
6622 * {@hide}
6623 */
6624 @Override
6625 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6626 enforceModifyPermission();
6627 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628
6629 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006630 if (phone == null) {
6631 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6632 return;
6633 }
6634 try {
6635 phone.carrierActionReportDefaultNetworkStatus(report);
6636 } catch (Exception e) {
6637 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638 } finally {
6639 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006640 }
6641 }
6642
6643 /**
fionaxud9622282017-07-17 17:51:30 -07006644 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6645 * @param subId the subscription ID that this action applies to.
6646 * {@hide}
6647 */
6648 @Override
6649 public void carrierActionResetAll(int subId) {
6650 enforceModifyPermission();
6651 final Phone phone = getPhone(subId);
6652 if (phone == null) {
6653 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6654 return;
6655 }
6656 try {
6657 phone.carrierActionResetAll();
6658 } catch (Exception e) {
6659 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6660 }
6661 }
6662
6663 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006664 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6665 * bug report is being generated.
6666 */
6667 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006668 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006669 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6670 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006671 writer.println("Permission Denial: can't dump Phone from pid="
6672 + Binder.getCallingPid()
6673 + ", uid=" + Binder.getCallingUid()
6674 + "without permission "
6675 + android.Manifest.permission.DUMP);
6676 return;
6677 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006678 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006679 }
Jack Yueb89b242016-06-22 13:27:47 -07006680
Brad Ebingerdac2f002018-04-03 15:17:52 -07006681 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006682 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6683 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6684 @NonNull String[] args) {
6685 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6686 this, in.getFileDescriptor(), out.getFileDescriptor(),
6687 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006688 }
6689
Jack Yueb89b242016-06-22 13:27:47 -07006690 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006691 * Get aggregated video call data usage since boot.
6692 *
6693 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6694 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006695 * {@hide}
6696 */
6697 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006698 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006699 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6700 null);
6701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 final long identity = Binder.clearCallingIdentity();
6703 try {
6704 // NetworkStatsService keeps tracking the active network interface and identity. It
6705 // records the delta with the corresponding network identity.
6706 // We just return the total video call data usage snapshot since boot.
6707 Phone phone = getPhone(subId);
6708 if (phone != null) {
6709 return phone.getVtDataUsage(perUidStats);
6710 }
6711 return null;
6712 } finally {
6713 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006714 }
Jack Yueb89b242016-06-22 13:27:47 -07006715 }
Jack Yu75ab2952016-07-08 14:29:33 -07006716
6717 /**
6718 * Policy control of data connection. Usually used when data limit is passed.
6719 * @param enabled True if enabling the data, otherwise disabling.
6720 * @param subId Subscription index
6721 * {@hide}
6722 */
6723 @Override
6724 public void setPolicyDataEnabled(boolean enabled, int subId) {
6725 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726
6727 final long identity = Binder.clearCallingIdentity();
6728 try {
6729 Phone phone = getPhone(subId);
6730 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006731 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 }
6733 } finally {
6734 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006735 }
6736 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006737
6738 /**
6739 * Get Client request stats
6740 * @return List of Client Request Stats
6741 * @hide
6742 */
6743 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006744 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6745 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006746 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006747 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006748 return null;
6749 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006750 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 final long identity = Binder.clearCallingIdentity();
6753 try {
6754 if (phone != null) {
6755 return phone.getClientRequestStats();
6756 }
6757
6758 return null;
6759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006762 }
6763
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006764 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006765 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006766 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006767 }
Jack Yueb4124c2017-02-16 15:32:43 -08006768
6769 /**
Grace Chen70990072017-03-24 17:21:30 -07006770 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006771 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006772 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006773 * @param state State of SIM (power down, power up, pass through)
6774 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6775 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6776 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006777 *
6778 **/
6779 @Override
Grace Chen70990072017-03-24 17:21:30 -07006780 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006781 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006782 Phone phone = PhoneFactory.getPhone(slotIndex);
6783
vagdeviaf9a5b92018-08-15 16:01:53 -07006784 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 final long identity = Binder.clearCallingIdentity();
6787 try {
6788 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006789 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 }
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006793 }
6794 }
Shuo Qiandd210312017-04-12 22:11:33 +00006795
Tyler Gunn65d45c22017-06-05 11:22:26 -07006796 private boolean isUssdApiAllowed(int subId) {
6797 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006798 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006799 if (configManager == null) {
6800 return false;
6801 }
6802 PersistableBundle pb = configManager.getConfigForSubId(subId);
6803 if (pb == null) {
6804 return false;
6805 }
6806 return pb.getBoolean(
6807 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6808 }
6809
Shuo Qiandd210312017-04-12 22:11:33 +00006810 /**
6811 * Check if phone is in emergency callback mode
6812 * @return true if phone is in emergency callback mode
6813 * @param subId sub id
6814 */
goneil9c5f4872017-12-05 14:07:56 -08006815 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006816 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006817 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006818 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819
6820 final long identity = Binder.clearCallingIdentity();
6821 try {
6822 if (phone != null) {
6823 return phone.isInEcm();
6824 } else {
6825 return false;
6826 }
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006829 }
6830 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006831
6832 /**
6833 * Get the current signal strength information for the given subscription.
6834 * Because this information is not updated when the device is in a low power state
6835 * it should not be relied-upon to be current.
6836 * @param subId Subscription index
6837 * @return the most recent cached signal strength info from the modem
6838 */
6839 @Override
6840 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 final long identity = Binder.clearCallingIdentity();
6842 try {
6843 Phone p = getPhone(subId);
6844 if (p == null) {
6845 return null;
6846 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006848 return p.getSignalStrength();
6849 } finally {
6850 Binder.restoreCallingIdentity(identity);
6851 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006852 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006853
Pengquan Meng77b7f132018-08-22 14:49:57 -07006854 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006855 * Get the current modem radio state for the given slot.
6856 * @param slotIndex slot index.
6857 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006858 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006859 * @return the current radio power state from the modem
6860 */
6861 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006862 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006863 Phone phone = PhoneFactory.getPhone(slotIndex);
6864 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6866 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006867 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6868 }
6869
6870 final long identity = Binder.clearCallingIdentity();
6871 try {
6872 return phone.getRadioPowerState();
6873 } finally {
6874 Binder.restoreCallingIdentity(identity);
6875 }
6876 }
6877 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6878 }
6879
6880 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006881 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6882 *
6883 * <p>Requires one of the following permissions:
6884 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6885 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6886 * privileges.
6887 *
6888 * @param subId subscription id
6889 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6890 * {@code false}.
6891 */
6892 @Override
6893 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006894 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6895 null /* message */);
6896
Pengquan Menga1bb6272018-09-06 09:59:22 -07006897 boolean isEnabled = false;
6898 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006899 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006900 Phone phone = getPhone(subId);
6901 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006902 } catch (Exception e) {
6903 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6904 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006905 } finally {
6906 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006907 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006908 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006909 }
6910
6911
6912 /**
6913 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6914 *
6915 * <p> Requires permission:
6916 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6917 * privileges.
6918 *
6919 * @param subId subscription id
6920 * @param isEnabled {@code true} means enable, {@code false} means disable.
6921 */
6922 @Override
6923 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6925 mApp, subId, "setDataRoamingEnabled");
6926
Pengquan Menga1bb6272018-09-06 09:59:22 -07006927 final long identity = Binder.clearCallingIdentity();
6928 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006929 Phone phone = getPhone(subId);
6930 if (phone != null) {
6931 phone.setDataRoamingEnabled(isEnabled);
6932 }
6933 } finally {
6934 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006935 }
6936 }
6937
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006938 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006939 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006940 TelephonyPermissions
6941 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006942 mApp, subId, "isManualNetworkSelectionAllowed");
6943
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006944 boolean isAllowed = true;
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006947 Phone phone = getPhone(subId);
6948 if (phone != null) {
6949 isAllowed = phone.isCspPlmnEnabled();
6950 }
6951 } finally {
6952 Binder.restoreCallingIdentity(identity);
6953 }
6954 return isAllowed;
6955 }
6956
6957 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006958 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006959 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006960 try {
6961 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006962 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006963 } catch (SecurityException e) {
6964 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6965 // has carrier privileges on an active UICC
6966 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6967 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006968 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006969 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006970 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006971
6972 final long identity = Binder.clearCallingIdentity();
6973 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006974 UiccController uiccController = UiccController.getInstance();
6975 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006976 if (hasReadPermission) {
6977 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006978 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006979
6980 // Remove private info if the caller doesn't have access
6981 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6982 for (UiccCardInfo cardInfo : cardInfos) {
6983 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6984 // is available
6985 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6986 if (card == null || card.getUiccProfile() == null) {
6987 // assume no access if the card or profile is unavailable
6988 filteredInfos.add(cardInfo.getUnprivileged());
6989 continue;
6990 }
6991 UiccProfile profile = card.getUiccProfile();
6992 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6993 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6994 filteredInfos.add(cardInfo);
6995 } else {
6996 filteredInfos.add(cardInfo.getUnprivileged());
6997 }
6998 }
6999 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007000 } finally {
7001 Binder.restoreCallingIdentity(identity);
7002 }
7003 }
7004
7005 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007006 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007007 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009 final long identity = Binder.clearCallingIdentity();
7010 try {
7011 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7012 if (slots == null) {
7013 Rlog.i(LOG_TAG, "slots is null.");
7014 return null;
7015 }
7016
7017 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7018 for (int i = 0; i < slots.length; i++) {
7019 UiccSlot slot = slots[i];
7020 if (slot == null) {
7021 continue;
7022 }
7023
Jordan Liu7be7e652019-05-06 18:55:02 +00007024 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 UiccCard card = slot.getUiccCard();
7026 if (card != null) {
7027 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007028 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007029 cardId = slot.getEid();
7030 if (TextUtils.isEmpty(cardId)) {
7031 cardId = slot.getIccId();
7032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 }
7034
Jordan Liu857451f2019-05-09 16:35:35 -07007035 if (cardId != null) {
7036 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7037 // if cardId is an EID, it's all digits so this is fine
7038 cardId = IccUtils.stripTrailingFs(cardId);
7039 }
7040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 int cardState = 0;
7042 switch (slot.getCardState()) {
7043 case CARDSTATE_ABSENT:
7044 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7045 break;
7046 case CARDSTATE_PRESENT:
7047 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7048 break;
7049 case CARDSTATE_ERROR:
7050 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7051 break;
7052 case CARDSTATE_RESTRICTED:
7053 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7054 break;
7055 default:
7056 break;
7057
7058 }
7059
7060 infos[i] = new UiccSlotInfo(
7061 slot.isActive(),
7062 slot.isEuicc(),
7063 cardId,
7064 cardState,
7065 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007066 slot.isExtendedApduSupported(),
7067 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068 }
7069 return infos;
7070 } finally {
7071 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007072 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007073 }
7074
7075 @Override
7076 public boolean switchSlots(int[] physicalSlots) {
7077 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078
7079 final long identity = Binder.clearCallingIdentity();
7080 try {
7081 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
7084 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007085 }
Jack Yu4c988042018-02-27 15:30:01 -08007086
7087 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007088 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 return UiccController.getInstance().getCardIdForDefaultEuicc();
7092 } finally {
7093 Binder.restoreCallingIdentity(identity);
7094 }
7095 }
7096
7097 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007098 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7099 enforceModifyPermission();
7100 final Phone phone = getPhone(subId);
7101 if (phone == null) {
7102 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7103 return;
7104 }
7105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 phone.setRadioIndicationUpdateMode(filters, mode);
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
7111 }
Jack Yu4c988042018-02-27 15:30:01 -08007112 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007113
7114 /**
goneil47ffb6e2018-04-06 15:40:58 -07007115 * A test API to reload the UICC profile.
7116 *
7117 * <p>Requires that the calling app has permission
7118 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7119 * @hide
7120 */
7121 @Override
7122 public void refreshUiccProfile(int subId) {
7123 enforceModifyPermission();
7124
7125 final long identity = Binder.clearCallingIdentity();
7126 try {
7127 Phone phone = getPhone(subId);
7128 if (phone == null) {
7129 return;
7130 }
7131 UiccCard uiccCard = phone.getUiccCard();
7132 if (uiccCard == null) {
7133 return;
7134 }
7135 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7136 if (uiccProfile == null) {
7137 return;
7138 }
7139 uiccProfile.refresh();
7140 } finally {
7141 Binder.restoreCallingIdentity(identity);
7142 }
7143 }
7144
7145 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007146 * Returns false if the mobile data is disabled by default, otherwise return true.
7147 */
7148 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007149 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007150 }
7151
7152 /**
7153 * Returns true if the data roaming is enabled by default, i.e the system property
7154 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7155 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7156 */
7157 private boolean getDefaultDataRoamingEnabled(int subId) {
7158 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007159 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007160 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007161 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7162 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7163 return isDataRoamingEnabled;
7164 }
7165
7166 /**
7167 * Returns the default network type for the given {@code subId}, if the default network type is
7168 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7169 */
7170 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007171 List<Integer> list = TelephonyProperties.default_network();
7172 int phoneId = mSubscriptionController.getPhoneId(subId);
7173 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7174 return list.get(phoneId);
7175 }
7176 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007177 }
fionaxua13278b2018-03-21 00:08:13 -07007178
7179 @Override
7180 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007181 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183
7184 final long identity = Binder.clearCallingIdentity();
7185 try {
7186 final Phone phone = getPhone(subId);
7187 if (phone == null) {
7188 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7189 return;
7190 }
chen xueaba88a2019-03-15 13:15:10 -07007191 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7192 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193 } finally {
7194 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007195 }
fionaxua13278b2018-03-21 00:08:13 -07007196 }
7197
7198 @Override
7199 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007200 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201
7202 final long identity = Binder.clearCallingIdentity();
7203 try {
7204 final Phone phone = getPhone(subId);
7205 if (phone == null) {
7206 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7207 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7208 }
7209 return phone.getCarrierIdListVersion();
7210 } finally {
7211 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007212 }
fionaxua13278b2018-03-21 00:08:13 -07007213 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007214
7215 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007216 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7217 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007219 mApp, subId, callingPackage, callingFeatureId,
7220 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007221 return -1;
7222 }
7223
7224 final long identity = Binder.clearCallingIdentity();
7225 try {
7226 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7227 } finally {
7228 Binder.restoreCallingIdentity(identity);
7229 }
7230 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007231
7232 @Override
7233 public int getCdmaRoamingMode(int subId) {
7234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7235 mApp, subId, "getCdmaRoamingMode");
7236
7237 final long identity = Binder.clearCallingIdentity();
7238 try {
7239 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
7243 }
7244
7245 @Override
7246 public boolean setCdmaRoamingMode(int subId, int mode) {
7247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7248 mApp, subId, "setCdmaRoamingMode");
7249
7250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
7255 }
7256 }
7257
7258 @Override
7259 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7261 mApp, subId, "setCdmaSubscriptionMode");
7262
7263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7266 } finally {
7267 Binder.restoreCallingIdentity(identity);
7268 }
7269 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007270
sqianc5eccab2018-10-19 18:46:41 -07007271 @Override
sqian8c685422019-02-22 15:55:18 -08007272 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007273 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007275 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7276 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007277 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7278 }
7279 final long identity = Binder.clearCallingIdentity();
7280 try {
sqian854d44b2018-12-12 16:48:18 -08007281 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7282 for (Phone phone: PhoneFactory.getPhones()) {
7283 if (phone.getEmergencyNumberTracker() != null
7284 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7285 emergencyNumberListInternal.put(
7286 phone.getSubId(),
7287 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7288 }
sqian11b7a0e2018-12-05 18:48:28 -08007289 }
sqian854d44b2018-12-12 16:48:18 -08007290 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
sqianc5eccab2018-10-19 18:46:41 -07007294 }
7295
7296 @Override
sqian8c685422019-02-22 15:55:18 -08007297 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007298 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007299 if (!exactMatch) {
7300 TelephonyPermissions
7301 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007302 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007303 }
7304 final long identity = Binder.clearCallingIdentity();
7305 try {
sqian854d44b2018-12-12 16:48:18 -08007306 for (Phone phone: PhoneFactory.getPhones()) {
7307 if (phone.getEmergencyNumberTracker() != null
7308 && phone.getEmergencyNumberTracker() != null) {
7309 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7310 number, exactMatch)) {
7311 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007312 }
7313 }
sqian11b7a0e2018-12-05 18:48:28 -08007314 }
7315 return false;
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
7318 }
7319 }
7320
sqianf4ca7ed2019-01-15 18:32:07 -08007321 /**
7322 * Update emergency number list for test mode.
7323 */
7324 @Override
7325 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7326 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7327 "updateEmergencyNumberListTestMode");
7328
7329 final long identity = Binder.clearCallingIdentity();
7330 try {
7331 for (Phone phone: PhoneFactory.getPhones()) {
7332 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7333 if (tracker != null) {
7334 tracker.executeEmergencyNumberTestModeCommand(action, num);
7335 }
7336 }
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
7340 }
7341
7342 /**
7343 * Get the full emergency number list for test mode.
7344 */
7345 @Override
7346 public List<String> getEmergencyNumberListTestMode() {
7347 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7348 "getEmergencyNumberListTestMode");
7349
7350 final long identity = Binder.clearCallingIdentity();
7351 try {
7352 Set<String> emergencyNumbers = new HashSet<>();
7353 for (Phone phone: PhoneFactory.getPhones()) {
7354 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7355 if (tracker != null) {
7356 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7357 emergencyNumbers.add(num.getNumber());
7358 }
7359 }
7360 }
7361 return new ArrayList<>(emergencyNumbers);
7362 } finally {
7363 Binder.restoreCallingIdentity(identity);
7364 }
7365 }
7366
chen xud6b45bd2018-10-30 22:27:10 -07007367 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007368 public int getEmergencyNumberDbVersion(int subId) {
7369 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7370
7371 final long identity = Binder.clearCallingIdentity();
7372 try {
7373 final Phone phone = getPhone(subId);
7374 if (phone == null) {
7375 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7376 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7377 }
7378 return phone.getEmergencyNumberDbVersion();
7379 } finally {
7380 Binder.restoreCallingIdentity(identity);
7381 }
7382 }
7383
7384 @Override
7385 public void notifyOtaEmergencyNumberDbInstalled() {
7386 enforceModifyPermission();
7387
7388 final long identity = Binder.clearCallingIdentity();
7389 try {
7390 for (Phone phone: PhoneFactory.getPhones()) {
7391 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7392 if (tracker != null) {
7393 tracker.updateOtaEmergencyNumberDatabase();
7394 }
7395 }
7396 } finally {
7397 Binder.restoreCallingIdentity(identity);
7398 }
7399 }
7400
7401 @Override
7402 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7403 enforceActiveEmergencySessionPermission();
7404
7405 final long identity = Binder.clearCallingIdentity();
7406 try {
7407 for (Phone phone: PhoneFactory.getPhones()) {
7408 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7409 if (tracker != null) {
7410 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7411 }
7412 }
7413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
7416 }
7417
7418 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007419 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7420 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7421 Phone phone = getPhone(subId);
7422 if (phone == null) {
7423 return null;
7424 }
7425 final long identity = Binder.clearCallingIdentity();
7426 try {
7427 UiccProfile profile = UiccController.getInstance()
7428 .getUiccProfileForPhone(phone.getPhoneId());
7429 if (profile != null) {
7430 return profile.getCertsFromCarrierPrivilegeAccessRules();
7431 }
7432 } finally {
7433 Binder.restoreCallingIdentity(identity);
7434 }
7435 return null;
7436 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007437
7438 /**
7439 * Enable or disable a modem stack.
7440 */
7441 @Override
7442 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7443 enforceModifyPermission();
7444
7445 final long identity = Binder.clearCallingIdentity();
7446 try {
7447 Phone phone = PhoneFactory.getPhone(slotIndex);
7448 if (phone == null) {
7449 return false;
7450 } else {
7451 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7452 }
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
7455 }
7456 }
Michelecea4cf22018-12-21 15:00:11 -08007457
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007458 /**
7459 * Whether a modem stack is enabled or not.
7460 */
7461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007462 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7463 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007464 Phone phone = PhoneFactory.getPhone(slotIndex);
7465 if (phone == null) return false;
7466
7467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007468 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7469 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007470 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7471 }
7472
7473 final long identity = Binder.clearCallingIdentity();
7474 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007475 try {
7476 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7477 } catch (NoSuchElementException ex) {
7478 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7479 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007480 } finally {
7481 Binder.restoreCallingIdentity(identity);
7482 }
7483 }
7484
Michelecea4cf22018-12-21 15:00:11 -08007485 @Override
Michele0ea7d782019-03-19 14:58:42 -07007486 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007487 enforceModifyPermission();
7488
7489 final long identity = Binder.clearCallingIdentity();
7490 try {
7491 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007492 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007493 .commit();
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
7497 }
7498
7499 @Override
Michele0ea7d782019-03-19 14:58:42 -07007500 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007501 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007503 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7504 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007505 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007506 }
Michelecea4cf22018-12-21 15:00:11 -08007507
7508 final long identity = Binder.clearCallingIdentity();
7509 try {
Michele0ea7d782019-03-19 14:58:42 -07007510 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007511 } finally {
7512 Binder.restoreCallingIdentity(identity);
7513 }
7514 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007515
Michele0ea7d782019-03-19 14:58:42 -07007516 @TelephonyManager.IsMultiSimSupportedResult
7517 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007518 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7519 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7520 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007521 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7522 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007523 }
7524 // Check if the hardware supports multisim functionality. If usage of multisim is not
7525 // supported by the modem, indicate that it is restricted.
7526 PhoneCapability staticCapability =
7527 mPhoneConfigurationManager.getStaticPhoneCapability();
7528 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007529 loge("isMultiSimSupportedInternal: no static configuration available");
7530 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007531 }
7532 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007533 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7534 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007535 }
7536 // Check if support of multiple SIMs is restricted by carrier
7537 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007538 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007539 }
7540
Michele0ea7d782019-03-19 14:58:42 -07007541 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007542 }
7543
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007544 /**
7545 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007546 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7547 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7548 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007549 * @param numOfSims number of active sims we want to switch to
7550 */
7551 @Override
7552 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007553 if (numOfSims == 1) {
7554 enforceModifyPermission();
7555 } else {
7556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7557 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7558 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007559 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007560
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007561 try {
Michele30b57b22019-03-01 12:01:14 -08007562 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007563 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007564 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7565 return;
7566 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007567 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
7571 }
7572
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007573 @Override
7574 public boolean isApplicationOnUicc(int subId, int appType) {
7575 enforceReadPrivilegedPermission("isApplicationOnUicc");
7576 Phone phone = getPhone(subId);
7577 if (phone == null) {
7578 return false;
7579 }
7580 final long identity = Binder.clearCallingIdentity();
7581 try {
7582 UiccCard uiccCard = phone.getUiccCard();
7583 if (uiccCard == null) {
7584 return false;
7585 }
7586 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7587 if (uiccProfile == null) {
7588 return false;
7589 }
7590 if (TelephonyManager.APPTYPE_SIM <= appType
7591 && appType <= TelephonyManager.APPTYPE_ISIM) {
7592 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7593 }
7594 return false;
7595 } finally {
7596 Binder.restoreCallingIdentity(identity);
7597 }
7598 }
7599
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007600 /**
chen xub4baa772019-04-03 10:23:41 -07007601 * Get whether making changes to modem configurations will trigger reboot.
7602 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007603 */
7604 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007605 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7606 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007608 mApp, subId, callingPackage, callingFeatureId,
7609 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007610 return false;
7611 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007612 final long identity = Binder.clearCallingIdentity();
7613 try {
7614 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7615 } finally {
7616 Binder.restoreCallingIdentity(identity);
7617 }
7618 }
7619
Nathan Harold29f5f052019-02-15 13:41:57 -08007620 private void updateModemStateMetrics() {
7621 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7622 // TODO: check the state for each modem if the api is ready.
7623 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7624 }
7625
Pengquan Meng3889a572019-01-23 11:16:29 -08007626 @Override
7627 public int[] getSlotsMapping() {
7628 enforceReadPrivilegedPermission("getSlotsMapping");
7629
7630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7633 // All logical slots should have a mapping to a physical slot.
7634 int[] logicalSlotsMapping = new int[phoneCount];
7635 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7636 for (int i = 0; i < slotInfos.length; i++) {
7637 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7638 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7639 }
7640 }
7641 return logicalSlotsMapping;
7642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
7645 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007646
7647 /**
7648 * Get the IRadio HAL Version
7649 */
7650 @Override
7651 public int getRadioHalVersion() {
7652 Phone phone = getDefaultPhone();
7653 if (phone == null) return -1;
7654 HalVersion hv = phone.getHalVersion();
7655 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7656 return hv.major * 100 + hv.minor;
7657 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007658
7659 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007660 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7661 * corresponding network requests on a subId.
7662 *
7663 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007664 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007665 * 2) APN is un-metered for this subscription, or
7666 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007667 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007668 *
7669 * @return whether data is allowed for a apn type.
7670 *
7671 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007672 */
7673 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007674 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007675 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7676 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007677
7678 // Now that all security checks passes, perform the operation as ourselves.
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 Phone phone = getPhone(subId);
7682 if (phone == null) return false;
7683
Jack Yu41407ee2019-05-13 16:54:09 -07007684 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007685 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
7689 }
7690
7691 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007692 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007693 enforceReadPrivilegedPermission("isApnMetered");
7694
7695 // Now that all security checks passes, perform the operation as ourselves.
7696 final long identity = Binder.clearCallingIdentity();
7697 try {
7698 Phone phone = getPhone(subId);
7699 if (phone == null) return true; // By default return true.
7700
Jack Yu41407ee2019-05-13 16:54:09 -07007701 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
7705 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007706
7707 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007708 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7709 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7710 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7711 if (iccRecords == null) {
7712 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7713 return false;
7714 }
7715 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7716 }
7717
7718 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007719 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7720 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7721 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7722 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7723 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7724 }
7725 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7726 Intent intent = new Intent();
7727 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7728 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7729 // Bring up choose default SMS subscription dialog right now
7730 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7731 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7732 mApp.startActivity(intent);
7733 }
chen xud5ca2d52019-05-28 15:20:57 -07007734
7735 @Override
7736 public String getMmsUAProfUrl(int subId) {
7737 //TODO investigate if this API should require proper permission check in R b/133791609
7738 final long identity = Binder.clearCallingIdentity();
7739 try {
7740 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7741 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
7744 }
7745 }
7746
7747 @Override
7748 public String getMmsUserAgent(int subId) {
7749 //TODO investigate if this API should require proper permission check in R b/133791609
7750 final long identity = Binder.clearCallingIdentity();
7751 try {
7752 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7753 .getString(com.android.internal.R.string.config_mms_user_agent);
7754 } finally {
7755 Binder.restoreCallingIdentity(identity);
7756 }
7757 }
Jack Yub07d4972019-05-28 16:12:25 -07007758
7759 @Override
7760 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7761 enforceModifyPermission();
7762
7763 // Now that all security checks passes, perform the operation as ourselves.
7764 final long identity = Binder.clearCallingIdentity();
7765 try {
7766 Phone phone = getPhone(subId);
7767 if (phone == null) return false;
7768
7769 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7770 } finally {
7771 Binder.restoreCallingIdentity(identity);
7772 }
7773 }
7774
7775 @Override
7776 public boolean isDataAllowedInVoiceCall(int subId) {
7777 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7778
7779 // Now that all security checks passes, perform the operation as ourselves.
7780 final long identity = Binder.clearCallingIdentity();
7781 try {
7782 Phone phone = getPhone(subId);
7783 if (phone == null) return false;
7784
7785 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
7789 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007790
changbettyd5c246e2019-12-24 15:40:37 +08007791 @Override
7792 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7793 enforceModifyPermission();
7794
7795 // Now that all security checks passes, perform the operation as ourselves.
7796 final long identity = Binder.clearCallingIdentity();
7797 try {
7798 Phone phone = getPhone(subId);
7799 if (phone == null) return false;
7800
7801 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
7805 }
7806
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007807 /**
7808 * Updates whether conference event pacakge handling is enabled.
7809 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7810 * otherwise.
7811 */
7812 @Override
7813 public void setCepEnabled(boolean isCepEnabled) {
7814 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7815
7816 final long identity = Binder.clearCallingIdentity();
7817 try {
7818 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7819 for (Phone phone : PhoneFactory.getPhones()) {
7820 Phone defaultPhone = phone.getImsPhone();
7821 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7822 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7823 ImsPhoneCallTracker imsPhoneCallTracker =
7824 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7825 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7826 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7827 + imsPhone.getMsisdn());
7828 }
7829 }
7830 } finally {
7831 Binder.restoreCallingIdentity(identity);
7832 }
7833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007834}