blob: ae6ec1a9a980e0292a483fddb6c8349d934d953f [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080087import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080088import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080090import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070091import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080094import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000095import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070096import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800112import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800160import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800168import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700169import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800170import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800173import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700175import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800176import com.android.telephony.Rlog;
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
Peter Wang44b186e2020-01-13 23:33:09 -08001460 private boolean isImsAvailableOnDevice() {
1461 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1462 if (pm == null) {
1463 // For some reason package manger is not available.. This will fail internally anyway,
1464 // so do not throw error and allow.
1465 return true;
1466 }
1467 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1468 }
1469
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001471 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001472 }
1473
Wink Savilleb564aae2014-10-23 10:18:09 -07001474 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 if (DBG) log("dial: " + number);
1476 // No permission check needed here: This is just a wrapper around the
1477 // ACTION_DIAL intent, which is available to any app since it puts up
1478 // the UI before it does anything.
1479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001480 final long identity = Binder.clearCallingIdentity();
1481 try {
1482 String url = createTelUrl(number);
1483 if (url == null) {
1484 return;
1485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001487 // PENDING: should we just silently fail if phone is offhook or ringing?
1488 PhoneConstants.State state = mCM.getState(subId);
1489 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1490 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1491 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1492 mApp.startActivity(intent);
1493 }
1494 } finally {
1495 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 }
1497 }
1498
1499 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001500 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001501 }
1502
Wink Savilleb564aae2014-10-23 10:18:09 -07001503 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 if (DBG) log("call: " + number);
1505
1506 // This is just a wrapper around the ACTION_CALL intent, but we still
1507 // need to do a permission check since we're calling startActivity()
1508 // from the context of the phone app.
1509 enforceCallPermission();
1510
Jordan Liu1617b712019-07-10 15:06:26 -07001511 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 != AppOpsManager.MODE_ALLOWED) {
1513 return;
1514 }
1515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001516 final long identity = Binder.clearCallingIdentity();
1517 try {
1518 String url = createTelUrl(number);
1519 if (url == null) {
1520 return;
1521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523 boolean isValid = false;
1524 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1525 if (slist != null) {
1526 for (SubscriptionInfo subInfoRecord : slist) {
1527 if (subInfoRecord.getSubscriptionId() == subId) {
1528 isValid = true;
1529 break;
1530 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001531 }
Wink Saville08874612014-08-31 19:19:58 -07001532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001533 if (!isValid) {
1534 return;
1535 }
Wink Saville08874612014-08-31 19:19:58 -07001536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001537 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1538 intent.putExtra(SUBSCRIPTION_KEY, subId);
1539 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1540 mApp.startActivity(intent);
1541 } finally {
1542 Binder.restoreCallingIdentity(identity);
1543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 }
1545
Wink Savilleb564aae2014-10-23 10:18:09 -07001546 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001547 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001548 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1549 }
1550
Wink Savilleb564aae2014-10-23 10:18:09 -07001551 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001552 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001553 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1554 }
1555
Wink Savilleb564aae2014-10-23 10:18:09 -07001556 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558
1559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1562 checkSimPin.start();
1563 return checkSimPin.unlockSim(null, pin);
1564 } finally {
1565 Binder.restoreCallingIdentity(identity);
1566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
1568
Wink Savilleb564aae2014-10-23 10:18:09 -07001569 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001571
1572 final long identity = Binder.clearCallingIdentity();
1573 try {
1574 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1575 checkSimPuk.start();
1576 return checkSimPuk.unlockSim(puk, pin);
1577 } finally {
1578 Binder.restoreCallingIdentity(identity);
1579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 }
1581
1582 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001583 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 * a synchronous one.
1585 */
1586 private static class UnlockSim extends Thread {
1587
1588 private final IccCard mSimCard;
1589
1590 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001591 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1592 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593
1594 // For replies from SimCard interface
1595 private Handler mHandler;
1596
1597 // For async handler to identify request type
1598 private static final int SUPPLY_PIN_COMPLETE = 100;
1599
1600 public UnlockSim(IccCard simCard) {
1601 mSimCard = simCard;
1602 }
1603
1604 @Override
1605 public void run() {
1606 Looper.prepare();
1607 synchronized (UnlockSim.this) {
1608 mHandler = new Handler() {
1609 @Override
1610 public void handleMessage(Message msg) {
1611 AsyncResult ar = (AsyncResult) msg.obj;
1612 switch (msg.what) {
1613 case SUPPLY_PIN_COMPLETE:
1614 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1615 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001616 mRetryCount = msg.arg1;
1617 if (ar.exception != null) {
1618 if (ar.exception instanceof CommandException &&
1619 ((CommandException)(ar.exception)).getCommandError()
1620 == CommandException.Error.PASSWORD_INCORRECT) {
1621 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1622 } else {
1623 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1624 }
1625 } else {
1626 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 mDone = true;
1629 UnlockSim.this.notifyAll();
1630 }
1631 break;
1632 }
1633 }
1634 };
1635 UnlockSim.this.notifyAll();
1636 }
1637 Looper.loop();
1638 }
1639
1640 /*
1641 * Use PIN or PUK to unlock SIM card
1642 *
1643 * If PUK is null, unlock SIM card with PIN
1644 *
1645 * If PUK is not null, unlock SIM card with PUK and set PIN code
1646 */
Wink Saville9de0f752013-10-22 19:04:03 -07001647 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648
1649 while (mHandler == null) {
1650 try {
1651 wait();
1652 } catch (InterruptedException e) {
1653 Thread.currentThread().interrupt();
1654 }
1655 }
1656 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1657
1658 if (puk == null) {
1659 mSimCard.supplyPin(pin, callback);
1660 } else {
1661 mSimCard.supplyPuk(puk, pin, callback);
1662 }
1663
1664 while (!mDone) {
1665 try {
1666 Log.d(LOG_TAG, "wait for done");
1667 wait();
1668 } catch (InterruptedException e) {
1669 // Restore the interrupted status
1670 Thread.currentThread().interrupt();
1671 }
1672 }
1673 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001674 int[] resultArray = new int[2];
1675 resultArray[0] = mResult;
1676 resultArray[1] = mRetryCount;
1677 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 }
1679 }
1680
1681 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001682 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001683
1684 }
1685
Wink Savilleb564aae2014-10-23 10:18:09 -07001686 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 // No permission check needed here: this call is harmless, and it's
1688 // needed for the ServiceState.requestStateUpdate() call (which is
1689 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001690 final long identity = Binder.clearCallingIdentity();
1691 try {
1692 final Phone phone = getPhone(subId);
1693 if (phone != null) {
1694 phone.updateServiceLocation();
1695 }
1696 } finally {
1697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001701 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001702 @Override
1703 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001704 return isRadioOnWithFeature(callingPackage, null);
1705 }
1706
1707
1708 @Override
1709 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1710 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1711 callingFeatureId);
1712 }
1713
1714 @Deprecated
1715 @Override
1716 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1717 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001718 }
1719
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001720 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001721 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1722 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001724 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001725 return false;
1726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727
1728 final long identity = Binder.clearCallingIdentity();
1729 try {
1730 return isRadioOnForSubscriber(subId);
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
1733 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001734 }
1735
1736 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001737 final long identity = Binder.clearCallingIdentity();
1738 try {
1739 final Phone phone = getPhone(subId);
1740 if (phone != null) {
1741 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1742 } else {
1743 return false;
1744 }
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
1749
1750 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001751 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
Wink Saville36469e72014-06-11 15:17:00 -07001753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1762 }
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
1768 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001769 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001770 }
1771
Wink Savilleb564aae2014-10-23 10:18:09 -07001772 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001774
1775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 final Phone phone = getPhone(subId);
1778 if (phone == null) {
1779 return false;
1780 }
1781 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1782 toggleRadioOnOffForSubscriber(subId);
1783 }
1784 return true;
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
Wink Saville36469e72014-06-11 15:17:00 -07001789
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001790 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001791 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 /*
1793 * If any of the Radios are available, it will need to be
1794 * shutdown. So return true if any Radio is available.
1795 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1799 Phone phone = PhoneFactory.getPhone(i);
1800 if (phone != null && phone.isRadioAvailable()) return true;
1801 }
1802 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1803 return false;
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001806 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
1808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001809 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001810 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001811 enforceModifyPermission();
1812
1813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1816 logv("Shutting down Phone " + i);
1817 shutdownRadioUsingPhoneId(i);
1818 }
1819 } finally {
1820 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001821 }
1822 }
1823
1824 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001825 Phone phone = PhoneFactory.getPhone(phoneId);
1826 if (phone != null && phone.isRadioAvailable()) {
1827 phone.shutdownRadio();
1828 }
1829 }
1830
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1837 if (defaultPhone != null) {
1838 defaultPhone.setRadioPower(turnOn);
1839 return true;
1840 } else {
1841 loge("There's no default phone.");
1842 return false;
1843 }
1844 } finally {
1845 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001846 }
Wink Saville36469e72014-06-11 15:17:00 -07001847 }
1848
Wink Savilleb564aae2014-10-23 10:18:09 -07001849 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001851
1852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 final Phone phone = getPhone(subId);
1855 if (phone != null) {
1856 phone.setRadioPower(turnOn);
1857 return true;
1858 } else {
1859 return false;
1860 }
1861 } finally {
1862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 }
1865
Wink Saville36469e72014-06-11 15:17:00 -07001866 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001867 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 public boolean enableDataConnectivity() {
1869 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001870
1871 final long identity = Binder.clearCallingIdentity();
1872 try {
1873 int subId = mSubscriptionController.getDefaultDataSubId();
1874 final Phone phone = getPhone(subId);
1875 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001876 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001877 return true;
1878 } else {
1879 return false;
1880 }
1881 } finally {
1882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
Wink Saville36469e72014-06-11 15:17:00 -07001886 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001887 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 public boolean disableDataConnectivity() {
1889 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001890
1891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 int subId = mSubscriptionController.getDefaultDataSubId();
1894 final Phone phone = getPhone(subId);
1895 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001896 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001897 return true;
1898 } else {
1899 return false;
1900 }
1901 } finally {
1902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 }
1905
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001907 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001908 final long identity = Binder.clearCallingIdentity();
1909 try {
1910 final Phone phone = getPhone(subId);
1911 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001912 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001913 } else {
1914 return false;
1915 }
1916 } finally {
1917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 }
1920
1921 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001922 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001923 }
1924
pkanwarae03a6b2016-11-06 20:37:09 -08001925 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001926 enforceCallPermission();
1927
1928 final long identity = Binder.clearCallingIdentity();
1929 try {
1930 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1931 return;
1932 }
1933 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1934 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
1937 }
pkanwar32d516d2016-10-14 19:37:38 -07001938 };
1939
Wink Savilleb564aae2014-10-23 10:18:09 -07001940 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001942
1943 final long identity = Binder.clearCallingIdentity();
1944 try {
1945 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1946 return false;
1947 }
1948 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1949 } finally {
1950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001955 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001956 }
1957
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001958 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001959 final long identity = Binder.clearCallingIdentity();
1960 try {
1961 Phone phone = PhoneFactory.getPhone(slotIndex);
1962 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1963 PhoneConstantConversions.convertCallState(phone.getState());
1964 } finally {
1965 Binder.restoreCallingIdentity(identity);
1966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 }
1968
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001970 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001971 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1972 }
1973
1974 @Override
1975 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001976 final long identity = Binder.clearCallingIdentity();
1977 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001978 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001979 if (phone != null) {
1980 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1981 } else {
1982 return PhoneConstantConversions.convertDataState(
1983 PhoneConstants.DataState.DISCONNECTED);
1984 }
1985 } finally {
1986 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 }
1989
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001991 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001992 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1993 }
1994
1995 @Override
1996 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001997 final long identity = Binder.clearCallingIdentity();
1998 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001999 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 if (phone != null) {
2001 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2002 } else {
2003 return TelephonyManager.DATA_ACTIVITY_NONE;
2004 }
2005 } finally {
2006 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 }
2009
2010 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002011 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002012 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002013 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002014
2015 LocationAccessPolicy.LocationPermissionResult locationResult =
2016 LocationAccessPolicy.checkLocationPermission(mApp,
2017 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2018 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002019 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002020 .setCallingPid(Binder.getCallingPid())
2021 .setCallingUid(Binder.getCallingUid())
2022 .setMethod("getCellLocation")
2023 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2024 .build());
2025 switch (locationResult) {
2026 case DENIED_HARD:
2027 throw new SecurityException("Not allowed to access cell location");
2028 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002029 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2030 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002034 final long identity = Binder.clearCallingIdentity();
2035 try {
2036 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002037 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002038 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 } finally {
2040 Binder.restoreCallingIdentity(identity);
2041 }
Svetoslav64fad262015-04-14 14:35:21 -07002042 }
2043
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002045 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2046 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002047 if (!TextUtils.isEmpty(callingPackage)) {
2048 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2050 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002051 return "";
2052 }
2053 }
2054
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2056 // registered cell info, so return a NULL country instead.
2057 final long identity = Binder.clearCallingIdentity();
2058 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002059 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2060 // Get default phone in this case.
2061 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2062 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002063 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002064 // Todo: fix this when we can get the actual cellular network info when the device
2065 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002066 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002067 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2068 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002069 return "";
2070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071 Phone phone = PhoneFactory.getPhone(phoneId);
2072 if (phone != null) {
2073 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002074 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075 if (sst != null) {
2076 LocaleTracker lt = sst.getLocaleTracker();
2077 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002078 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2079 return lt.getCurrentCountry();
2080 } else if (emergencyNumberTracker != null) {
2081 return emergencyNumberTracker.getEmergencyCountryIso();
2082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002083 }
2084 }
2085 }
2086 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002087 } finally {
2088 Binder.restoreCallingIdentity(identity);
2089 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002090 }
2091
2092 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002094 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002095 }
2096
Sanket Padawe356d7632015-06-22 14:03:32 -07002097 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002098 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 mApp.enforceCallingOrSelfPermission(
2100 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002101
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 phone.enableLocationUpdates();
2107 }
2108 } finally {
2109 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 }
2112
2113 @Override
2114 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002115 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002116 }
2117
Sanket Padawe356d7632015-06-22 14:03:32 -07002118 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002119 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 mApp.enforceCallingOrSelfPermission(
2121 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002122
2123 final long identity = Binder.clearCallingIdentity();
2124 try {
2125 final Phone phone = getPhone(subId);
2126 if (phone != null) {
2127 phone.disableLocationUpdates();
2128 }
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
2133
Nathan Harold31d7ff32018-10-15 20:20:30 -07002134 /**
2135 * Returns the target SDK version number for a given package name.
2136 *
Nathan Haroldec184742019-07-10 17:04:16 -07002137 * This call MUST be invoked before clearing the calling UID.
2138 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002139 * @return target SDK if the package is found or INT_MAX.
2140 */
2141 private int getTargetSdk(String packageName) {
2142 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002143 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002144 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002145 if (ai != null) return ai.targetSdkVersion;
2146 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002147 loge("Failed to get package info for pkg="
2148 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002149 }
2150 return Integer.MAX_VALUE;
2151 }
2152
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 @Override
2154 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002155 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2156 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002157 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002158 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2159 throw new SecurityException(
2160 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2161 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002162
Jordan Liu1617b712019-07-10 15:06:26 -07002163 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2165 return null;
2166 }
Svetoslav64fad262015-04-14 14:35:21 -07002167
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002168 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002170 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002171 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172
Nathan Haroldf180aac2018-06-01 18:43:55 -07002173 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2174 for (CellInfo ci : info) {
2175 if (ci instanceof CellInfoGsm) {
2176 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2177 } else if (ci instanceof CellInfoWcdma) {
2178 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002181 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002184 private List<CellInfo> getCachedCellInfo() {
2185 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2186 for (Phone phone : PhoneFactory.getPhones()) {
2187 List<CellInfo> info = phone.getAllCellInfo();
2188 if (info != null) cellInfos.addAll(info);
2189 }
2190 return cellInfos;
2191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192
2193 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002194 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002195 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002196 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002197
2198 LocationAccessPolicy.LocationPermissionResult locationResult =
2199 LocationAccessPolicy.checkLocationPermission(mApp,
2200 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2201 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002202 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002203 .setCallingPid(Binder.getCallingPid())
2204 .setCallingUid(Binder.getCallingUid())
2205 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002206 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002207 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2208 .build());
2209 switch (locationResult) {
2210 case DENIED_HARD:
2211 throw new SecurityException("Not allowed to access cell info");
2212 case DENIED_SOFT:
2213 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 }
2215
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002216 final int targetSdk = getTargetSdk(callingPackage);
2217 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2218 return getCachedCellInfo();
2219 }
2220
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002221 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2226 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002227 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002228 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229 if (info != null) cellInfos.addAll(info);
2230 }
2231 return cellInfos;
2232 } finally {
2233 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235 }
2236
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002237 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002238 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2239 String callingFeatureId) {
2240 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2241 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002242 }
2243
2244 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002245 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2246 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002247 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002249 }
2250
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002251 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2252 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002253 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002254 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002255
2256 LocationAccessPolicy.LocationPermissionResult locationResult =
2257 LocationAccessPolicy.checkLocationPermission(mApp,
2258 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2259 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002260 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002261 .setCallingPid(Binder.getCallingPid())
2262 .setCallingUid(Binder.getCallingUid())
2263 .setMethod("requestCellInfoUpdate")
2264 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2265 .build());
2266 switch (locationResult) {
2267 case DENIED_HARD:
2268 throw new SecurityException("Not allowed to access cell info");
2269 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002270 try {
2271 cb.onCellInfo(new ArrayList<CellInfo>());
2272 } catch (RemoteException re) {
2273 // Drop without consequences
2274 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002275 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002276 }
2277
Nathan Harolda939a962019-05-09 10:13:47 -07002278
2279 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002280 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2281
2282 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2283 }
2284
2285 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002287 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002288 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289
2290 final long identity = Binder.clearCallingIdentity();
2291 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002292 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293 } finally {
2294 Binder.restoreCallingIdentity(identity);
2295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 }
2297
Shishir Agrawala9f32182016-04-12 12:00:16 -07002298 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002299 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002300 Phone phone = PhoneFactory.getPhone(slotIndex);
2301 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002302 return null;
2303 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002304 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002305 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002306 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002307 return null;
2308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002309
2310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 return phone.getImei();
2313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002316 }
2317
2318 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002319 public String getTypeAllocationCodeForSlot(int slotIndex) {
2320 Phone phone = PhoneFactory.getPhone(slotIndex);
2321 String tac = null;
2322 if (phone != null) {
2323 String imei = phone.getImei();
2324 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2325 }
2326 return tac;
2327 }
2328
2329 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002330 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002331 Phone phone = PhoneFactory.getPhone(slotIndex);
2332 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002333 return null;
2334 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002335
Jeff Davidson913390f2018-02-23 17:11:49 -08002336 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002337 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002338 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002339 return null;
2340 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341
2342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 return phone.getMeid();
2345 } finally {
2346 Binder.restoreCallingIdentity(identity);
2347 }
Jack Yu2af8d712017-03-15 17:14:14 -07002348 }
2349
2350 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002351 public String getManufacturerCodeForSlot(int slotIndex) {
2352 Phone phone = PhoneFactory.getPhone(slotIndex);
2353 String manufacturerCode = null;
2354 if (phone != null) {
2355 String meid = phone.getMeid();
2356 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2357 }
2358 return manufacturerCode;
2359 }
2360
2361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002362 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2363 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002364 Phone phone = PhoneFactory.getPhone(slotIndex);
2365 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002366 return null;
2367 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002368 int subId = phone.getSubId();
2369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002370 mApp, subId, callingPackage, callingFeatureId,
2371 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002372 return null;
2373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002374
2375 final long identity = Binder.clearCallingIdentity();
2376 try {
2377 return phone.getDeviceSvn();
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
2380 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002381 }
2382
fionaxu43304da2017-11-27 22:51:16 -08002383 @Override
2384 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002385 final long identity = Binder.clearCallingIdentity();
2386 try {
2387 final Phone phone = getPhone(subId);
2388 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2389 } finally {
2390 Binder.restoreCallingIdentity(identity);
2391 }
fionaxu43304da2017-11-27 22:51:16 -08002392 }
2393
2394 @Override
2395 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 final Phone phone = getPhone(subId);
2399 return phone == null ? null : phone.getCarrierName();
2400 } finally {
2401 Binder.restoreCallingIdentity(identity);
2402 }
fionaxu43304da2017-11-27 22:51:16 -08002403 }
2404
calvinpanffe225e2018-11-01 19:43:06 +08002405 @Override
chen xu0026ca62019-03-06 15:28:50 -08002406 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002407 final long identity = Binder.clearCallingIdentity();
2408 try {
2409 final Phone phone = getPhone(subId);
2410 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002411 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002412 } finally {
2413 Binder.restoreCallingIdentity(identity);
2414 }
2415 }
2416
2417 @Override
chen xu0026ca62019-03-06 15:28:50 -08002418 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002419 final long identity = Binder.clearCallingIdentity();
2420 try {
2421 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002422 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
2426 }
2427
chen xu651eec72018-11-11 19:03:44 -08002428 @Override
chen xu864e11c2018-12-06 22:10:03 -08002429 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2430 if (!isSubscriptionMccMnc) {
2431 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2432 }
chen xu651eec72018-11-11 19:03:44 -08002433 final Phone phone = PhoneFactory.getPhone(slotIndex);
2434 if (phone == null) {
2435 return TelephonyManager.UNKNOWN_CARRIER_ID;
2436 }
2437 final long identity = Binder.clearCallingIdentity();
2438 try {
2439 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
2442 }
2443 }
2444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 //
2446 // Internal helper methods.
2447 //
2448
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002449 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2451 *
2452 * @throws SecurityException if the caller does not have the required permission
2453 */
2454 private void enforceModifyPermission() {
2455 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2456 }
2457
Shuo Qian3b6ee772019-11-13 17:43:31 -08002458 private void enforceActiveEmergencySessionPermission() {
2459 mApp.enforceCallingOrSelfPermission(
2460 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2461 }
2462
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 /**
2464 * Make sure the caller has the CALL_PHONE permission.
2465 *
2466 * @throws SecurityException if the caller does not have the required permission
2467 */
2468 private void enforceCallPermission() {
2469 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2470 }
2471
paulhu5a773602019-08-23 19:17:33 +08002472 private void enforceSettingsPermission() {
2473 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002474 }
2475
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 private String createTelUrl(String number) {
2477 if (TextUtils.isEmpty(number)) {
2478 return null;
2479 }
2480
Jake Hambye994d462014-02-03 13:10:13 -08002481 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 }
2483
Ihab Awadf9e92732013-12-05 18:02:52 -08002484 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2486 }
2487
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002488 private static void logv(String msg) {
2489 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2490 }
2491
Ihab Awadf9e92732013-12-05 18:02:52 -08002492 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2494 }
2495
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002496 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002498 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002499 }
2500
Sanket Padawe356d7632015-06-22 14:03:32 -07002501 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002502 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 final Phone phone = PhoneFactory.getPhone(slotIndex);
2506 if (phone == null) {
2507 return PhoneConstants.PHONE_TYPE_NONE;
2508 } else {
2509 return phone.getPhoneType();
2510 }
2511 } finally {
2512 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 }
2515
2516 /**
2517 * Returns the CDMA ERI icon index to display
2518 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002519 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002520 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2521 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2522 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002523 }
2524
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002526 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2527 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 mApp, subId, callingPackage, callingFeatureId,
2530 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 return -1;
2532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533
2534 final long identity = Binder.clearCallingIdentity();
2535 try {
2536 final Phone phone = getPhone(subId);
2537 if (phone != null) {
2538 return phone.getCdmaEriIconIndex();
2539 } else {
2540 return -1;
2541 }
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546
2547 /**
2548 * Returns the CDMA ERI icon mode,
2549 * 0 - ON
2550 * 1 - FLASHING
2551 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002553 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2554 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2555 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002556 }
2557
Sanket Padawe356d7632015-06-22 14:03:32 -07002558 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002559 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2560 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002562 mApp, subId, callingPackage, callingFeatureId,
2563 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002564 return -1;
2565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566
2567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 final Phone phone = getPhone(subId);
2570 if (phone != null) {
2571 return phone.getCdmaEriIconMode();
2572 } else {
2573 return -1;
2574 }
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 }
2579
2580 /**
2581 * Returns the CDMA ERI text,
2582 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002583 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002584 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2585 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2586 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Sanket Padawe356d7632015-06-22 14:03:32 -07002589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002590 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2591 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 mApp, subId, callingPackage, callingFeatureId,
2594 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002595 return null;
2596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 final Phone phone = getPhone(subId);
2601 if (phone != null) {
2602 return phone.getCdmaEriText();
2603 } else {
2604 return null;
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 }
2610
2611 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002612 * Returns the CDMA MDN.
2613 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002614 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002615 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2617 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618
2619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002622 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 return phone.getLine1Number();
2624 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002625 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 return null;
2627 }
2628 } finally {
2629 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002630 }
2631 }
2632
2633 /**
2634 * Returns the CDMA MIN.
2635 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002636 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002637 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2639 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640
2641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 final Phone phone = getPhone(subId);
2644 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2645 return phone.getCdmaMin();
2646 } else {
2647 return null;
2648 }
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002651 }
2652 }
2653
Hall Liud892bec2018-11-30 14:51:45 -08002654 @Override
2655 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2656 INumberVerificationCallback callback, String callingPackage) {
2657 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2658 != PERMISSION_GRANTED) {
2659 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2660 }
2661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2662
2663 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2664 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2665 throw new SecurityException("Calling package must be configured in the device config");
2666 }
2667
2668 if (range == null) {
2669 throw new NullPointerException("Range must be non-null");
2670 }
2671
2672 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002673 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002674
2675 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2676 }
2677
Junda Liuca05d5d2014-08-14 22:36:34 -07002678 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 * Returns true if CDMA provisioning needs to run.
2680 */
2681 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 final long identity = Binder.clearCallingIdentity();
2683 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002684 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 } finally {
2686 Binder.restoreCallingIdentity(identity);
2687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 }
2689
2690 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002691 * Sets the voice mail number of a given subId.
2692 */
2693 @Override
2694 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002695 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2696 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2701 new Pair<String, String>(alphaTag, number), new Integer(subId));
2702 return success;
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002706 }
2707
Ta-wei Yen87c49842016-05-13 21:19:52 -07002708 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002709 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002711 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2712 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002713 if (!TextUtils.equals(callingPackage, systemDialer)) {
2714 throw new SecurityException("caller must be system dialer");
2715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716
2717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2720 if (phoneAccountHandle == null) {
2721 return null;
2722 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002723 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002726 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002727 }
2728
2729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002730 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2731 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002734 mApp, subId, callingPackage, callingFeatureId,
2735 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002736 return null;
2737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002739 final long identity = Binder.clearCallingIdentity();
2740 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002741 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002745 }
2746
2747 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002748 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2749 VisualVoicemailSmsFilterSettings settings) {
2750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751
2752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002755 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756 } finally {
2757 Binder.restoreCallingIdentity(identity);
2758 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002759 }
2760
2761 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002762 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002768 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002772 }
2773
2774 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002775 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2776 String callingPackage, int subId) {
2777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778
2779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002782 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 } finally {
2784 Binder.restoreCallingIdentity(identity);
2785 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002786 }
2787
2788 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002789 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002790 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791
2792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002795 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796 } finally {
2797 Binder.restoreCallingIdentity(identity);
2798 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002799 }
2800
2801 @Override
2802 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2803 String number, int port, String text, PendingIntent sentIntent) {
2804 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002805 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002806 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002807 SmsController smsController = PhoneFactory.getSmsController();
2808 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2809 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002810 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002811
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002812 /**
fionaxu0152e512016-11-14 13:36:14 -08002813 * Sets the voice activation state of a given subId.
2814 */
2815 @Override
2816 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2818 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 final Phone phone = getPhone(subId);
2823 if (phone != null) {
2824 phone.setVoiceActivationState(activationState);
2825 } else {
2826 loge("setVoiceActivationState fails with invalid subId: " + subId);
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002830 }
2831 }
2832
2833 /**
2834 * Sets the data activation state of a given subId.
2835 */
2836 @Override
2837 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2839 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 final Phone phone = getPhone(subId);
2844 if (phone != null) {
2845 phone.setDataActivationState(activationState);
2846 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002847 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 }
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002851 }
2852 }
2853
2854 /**
2855 * Returns the voice activation state of a given subId.
2856 */
2857 @Override
2858 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002859 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
fionaxu0152e512016-11-14 13:36:14 -08002861 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 if (phone != null) {
2865 return phone.getVoiceActivationState();
2866 } else {
2867 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002871 }
2872 }
2873
2874 /**
2875 * Returns the data activation state of a given subId.
2876 */
2877 @Override
2878 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002879 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
fionaxu0152e512016-11-14 13:36:14 -08002881 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 if (phone != null) {
2885 return phone.getDataActivationState();
2886 } else {
2887 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2888 }
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002891 }
2892 }
2893
2894 /**
Wink Saville36469e72014-06-11 15:17:00 -07002895 * Returns the unread count of voicemails for a subId
2896 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002898 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2899 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002901 mApp, subId, callingPackage, callingFeatureId,
2902 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002903 return 0;
2904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 final Phone phone = getPhone(subId);
2908 if (phone != null) {
2909 return phone.getVoiceMessageCount();
2910 } else {
2911 return 0;
2912 }
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 }
2917
2918 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002919 * returns true, if the device is in a state where both voice and data
2920 * are supported simultaneously. This can change based on location or network condition.
2921 */
2922 @Override
2923 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 final long identity = Binder.clearCallingIdentity();
2925 try {
2926 final Phone phone = getPhone(subId);
2927 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002931 }
2932
2933 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002934 * Send the dialer code if called from the current default dialer or the caller has
2935 * carrier privilege.
2936 * @param inputCode The dialer code to send
2937 */
2938 @Override
2939 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002940 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002941 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002942 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2943 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002944 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002945 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002946 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952 } finally {
2953 Binder.restoreCallingIdentity(identity);
2954 }
fionaxu235cc5e2017-03-06 22:25:57 -08002955 }
2956
Pengquan Menga1bb6272018-09-06 09:59:22 -07002957 @Override
2958 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002959 if (!isActiveSubscription(subId)) {
2960 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2961 }
2962
Pengquan Menga1bb6272018-09-06 09:59:22 -07002963 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2964 }
2965
Brad Ebinger35c841c2018-10-01 10:40:55 -07002966 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002967 public boolean isInEmergencySmsMode() {
2968 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 for (Phone phone : PhoneFactory.getPhones()) {
2972 if (phone.isInEmergencySmsMode()) {
2973 return true;
2974 }
2975 }
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
2979 return false;
2980 }
2981
2982 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002983 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2984 throws RemoteException {
2985 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002986 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2987 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2988 "IMS not available on device.");
2989 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 final long token = Binder.clearCallingIdentity();
2991 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002993 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002995 } catch (ImsException e) {
2996 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002997 } finally {
2998 Binder.restoreCallingIdentity(token);
2999 }
3000 }
3001
3002 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003003 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3004 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003005 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3006 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3007 }
Meng Wangafbc5852019-09-19 17:37:13 -07003008 final long token = Binder.clearCallingIdentity();
3009 try {
3010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3012 .removeRegistrationCallbackForSubscription(c, subId);
3013 } catch (ImsException e) {
3014 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3015 + "is inactive, ignoring unregister.");
3016 // If the subscription is no longer active, just return, since the callback
3017 // will already have been removed internally.
3018 } finally {
3019 Binder.restoreCallingIdentity(token);
3020 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003021 }
3022
Brad Ebingera34a6c22019-10-22 17:36:18 -07003023 /**
3024 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3025 */
3026 @Override
3027 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3028 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3029 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3030 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3031 "IMS not available on device.");
3032 }
3033 final long token = Binder.clearCallingIdentity();
3034 try {
3035 Phone phone = getPhone(subId);
3036 if (phone == null) {
3037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3038 + subId + "'");
3039 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3040 }
3041 phone.getImsRegistrationState(regState -> {
3042 try {
3043 consumer.accept((regState == null)
3044 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3045 } catch (RemoteException e) {
3046 // Ignore if the remote process is no longer available to call back.
3047 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3048 }
3049 });
3050 } finally {
3051 Binder.restoreCallingIdentity(token);
3052 }
3053 }
3054
3055 /**
3056 * Get the transport type for the IMS service registration state.
3057 */
3058 @Override
3059 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3060 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3061 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3062 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3063 "IMS not available on device.");
3064 }
3065 final long token = Binder.clearCallingIdentity();
3066 try {
3067 Phone phone = getPhone(subId);
3068 if (phone == null) {
3069 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3070 + subId + "'");
3071 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3072 }
3073 phone.getImsRegistrationTech(regTech -> {
3074 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3075 int regTechConverted = (regTech == null)
3076 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3077 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3078 regTechConverted);
3079 try {
3080 consumer.accept(regTechConverted);
3081 } catch (RemoteException e) {
3082 // Ignore if the remote process is no longer available to call back.
3083 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3084 }
3085 });
3086 } finally {
3087 Binder.restoreCallingIdentity(token);
3088 }
3089 }
3090
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003092 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3093 throws RemoteException {
3094 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003095 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3096 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3097 "IMS not available on device.");
3098 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3100 final long token = Binder.clearCallingIdentity();
3101 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003102 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003104 } catch (ImsException e) {
3105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 } finally {
3107 Binder.restoreCallingIdentity(token);
3108 }
3109 }
3110
3111 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003112 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3113 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3115 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3116 }
Meng Wangafbc5852019-09-19 17:37:13 -07003117
3118 final long token = Binder.clearCallingIdentity();
3119 try {
3120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3121 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003122 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003123 } catch (ImsException e) {
3124 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3125 + "is inactive, ignoring unregister.");
3126 // If the subscription is no longer active, just return, since the callback
3127 // will already have been removed internally.
3128 } finally {
3129 Binder.restoreCallingIdentity(token);
3130 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003131 }
3132
3133 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003134 public boolean isCapable(int subId, int capability, int regTech) {
3135 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3137 final long token = Binder.clearCallingIdentity();
3138 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003139 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003141 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3143 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003144 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003145 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3146 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003147 } finally {
3148 Binder.restoreCallingIdentity(token);
3149 }
3150 }
3151
3152 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003153 public boolean isAvailable(int subId, int capability, int regTech) {
3154 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003155 final long token = Binder.clearCallingIdentity();
3156 try {
3157 Phone phone = getPhone(subId);
3158 if (phone == null) return false;
3159 return phone.isImsCapabilityAvailable(capability, regTech);
3160 } finally {
3161 Binder.restoreCallingIdentity(token);
3162 }
3163 }
3164
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003165 /**
3166 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3167 * subscription.
3168 * @param subId The subscription to use to check the configuration.
3169 * @param callback The callback that will be used to send the result.
3170 * @param capability The MmTelFeature capability that will be used to send the result.
3171 * @param transportType The transport type of the MmTelFeature capability.
3172 */
3173 @Override
3174 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3175 int transportType) {
3176 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3177 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3178 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3179 "IMS not available on device.");
3180 }
3181 final long token = Binder.clearCallingIdentity();
3182 try {
3183 int slotId = getSlotIndex(subId);
3184 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3185 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3186 + subId + "'");
3187 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3188 }
3189 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3190 transportType, aBoolean -> {
3191 try {
3192 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3193 } catch (RemoteException e) {
3194 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3195 + "running. Ignore");
3196 }
3197 });
3198 } finally {
3199 Binder.restoreCallingIdentity(token);
3200 }
3201 }
3202
Brad Ebinger35c841c2018-10-01 10:40:55 -07003203 @Override
3204 public boolean isAdvancedCallingSettingEnabled(int subId) {
3205 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3207 final long token = Binder.clearCallingIdentity();
3208 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003211 } catch (ImsException e) {
3212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 } finally {
3214 Binder.restoreCallingIdentity(token);
3215 }
3216 }
3217
3218 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003219 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003221 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003225 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003227 } catch (ImsException e) {
3228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
3232 }
3233
3234 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003235 public boolean isVtSettingEnabled(int subId) {
3236 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003240 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3241 } catch (ImsException e) {
3242 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
3246 }
3247
3248 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003249 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003251 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003255 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003256 } catch (ImsException e) {
3257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
3261 }
3262
3263 @Override
3264 public boolean isVoWiFiSettingEnabled(int subId) {
3265 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003269 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003271 } catch (ImsException e) {
3272 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
3276 }
3277
3278 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003279 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003281 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003286 } catch (ImsException e) {
3287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
3294 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3295 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003299 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003300 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003301 } catch (ImsException e) {
3302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
3306 }
3307
3308 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003309 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003311 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003315 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003316 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003317 } catch (ImsException e) {
3318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
3322 }
3323
3324 @Override
3325 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3327 "setVoWiFiNonPersistent");
3328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003332 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003333 } catch (ImsException e) {
3334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
3340 @Override
3341 public int getVoWiFiModeSetting(int subId) {
3342 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003346 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003347 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003348 } catch (ImsException e) {
3349 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 } finally {
3351 Binder.restoreCallingIdentity(identity);
3352 }
3353 }
3354
3355 @Override
3356 public void setVoWiFiModeSetting(int subId, int mode) {
3357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3358 "setVoWiFiModeSetting");
3359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003362 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003364 } catch (ImsException e) {
3365 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
3369 }
3370
3371 @Override
3372 public int getVoWiFiRoamingModeSetting(int subId) {
3373 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003377 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003378 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003379 } catch (ImsException e) {
3380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
3384 }
3385
3386 @Override
3387 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3389 "setVoWiFiRoamingModeSetting");
3390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003395 } catch (ImsException e) {
3396 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
3400 }
3401
3402 @Override
3403 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3405 "setRttCapabilityEnabled");
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003409 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3410 } catch (ImsException e) {
3411 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 } finally {
3413 Binder.restoreCallingIdentity(identity);
3414 }
3415 }
3416
3417 @Override
3418 public boolean isTtyOverVolteEnabled(int subId) {
3419 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003425 } catch (ImsException e) {
3426 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003432 @Override
3433 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3434 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003437 if (!isImsAvailableOnDevice()) {
3438 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3439 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003440 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003441 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003442 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003443 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003444 } catch (ImsException e) {
3445 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003446 } finally {
3447 Binder.restoreCallingIdentity(identity);
3448 }
3449 }
3450
3451 @Override
3452 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3453 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3454 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003455 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3456 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3457 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003458 try {
3459 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003460 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003461 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003462 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003463 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3464 + "is inactive, ignoring unregister.");
3465 // If the subscription is no longer active, just return, since the callback will already
3466 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
3470 }
3471
allenwtsu99c623b2020-01-03 18:24:23 +08003472
3473 private void checkModifyPhoneStatePermission(int subId, String message) {
3474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3475 message);
3476 }
3477
3478 private boolean isImsProvisioningRequired(int subId, int capability,
3479 boolean isMmtelCapability) {
3480 Phone phone = getPhone(subId);
3481 if (phone == null) {
3482 loge("phone instance null for subid " + subId);
3483 return false;
3484 }
3485 if (isMmtelCapability) {
3486 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3487 return false;
3488 }
3489 } else {
3490 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3491 return false;
3492 }
3493 }
3494 return true;
3495 }
3496
3497 @Override
3498 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3499 boolean isProvisioned) {
3500 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3501
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3505 if (!isImsProvisioningRequired(subId, capability, false)) {
3506 return;
3507 }
3508
3509 // this capability requires provisioning, route to the correct API.
3510 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3511 switch (capability) {
3512 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3513 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3514 ims.setEabProvisioned(isProvisioned);
3515 break;
3516 default: {
3517 throw new IllegalArgumentException("Tried to set provisioning for "
3518 + "rcs capability '" + capability + "', which does not require "
3519 + "provisioning.");
3520 }
3521 }
3522 } finally {
3523 Binder.restoreCallingIdentity(identity);
3524 }
3525
3526 }
3527
3528
3529 @Override
3530 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3531 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3535 if (!isImsProvisioningRequired(subId, capability, false)) {
3536 return true;
3537 }
3538
3539 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3540 switch (capability) {
3541 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3542 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3543 return ims.isEabProvisionedOnDevice();
3544
3545 default: {
3546 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3547 + "capability '" + capability + "', which does not require "
3548 + "provisioning.");
3549 }
3550 }
3551
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
3555 }
3556
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003557 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003558 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3559 boolean isProvisioned) {
3560 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3561 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3562 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3563 }
allenwtsu99c623b2020-01-03 18:24:23 +08003564 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003568 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003569 return;
3570 }
3571
3572 // this capability requires provisioning, route to the correct API.
3573 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3574 switch (capability) {
3575 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3576 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3577 ims.setVolteProvisioned(isProvisioned);
3578 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3579 ims.setWfcProvisioned(isProvisioned);
3580 }
3581 break;
3582 }
3583 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3584 // There is currently no difference in VT provisioning type.
3585 ims.setVtProvisioned(isProvisioned);
3586 break;
3587 }
3588 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3589 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3590 // change the capability of the feature instead if needed.
3591 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3592 == isProvisioned) {
3593 // No change in provisioning.
3594 return;
3595 }
3596 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3597 try {
3598 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003599 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003600 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3601 + ", Exception" + e.getMessage());
3602 }
3603 break;
3604 }
3605 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003606 throw new IllegalArgumentException("Tried to set provisioning for "
3607 + "MmTel capability '" + capability + "', which does not require "
3608 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003609 }
3610 }
3611
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
3614 }
3615 }
3616
3617 @Override
3618 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3619 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3620 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3621 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3622 }
3623 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003627 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003628 return true;
3629 }
3630
3631 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3632 switch (capability) {
3633 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3634 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3635 return ims.isVolteProvisionedOnDevice();
3636 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3637 return ims.isWfcProvisionedOnDevice();
3638 }
3639 // This should never happen, since we are checking tech above to make sure it
3640 // is either LTE or IWLAN.
3641 throw new IllegalArgumentException("Invalid radio technology for voice "
3642 + "capability.");
3643 }
3644 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3645 // There is currently no difference in VT provisioning type.
3646 return ims.isVtProvisionedOnDevice();
3647 }
3648 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3649 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3650 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3651 }
3652 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003653 throw new IllegalArgumentException(
3654 "Tried to get provisioning for MmTel capability '" + capability
3655 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003656 }
3657 }
3658
3659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
3662 }
3663
3664 @Override
3665 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3666 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3667 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3668 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3669 }
3670 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3671 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3672 return (provisionedBits & capability) > 0;
3673 }
3674
3675 @Override
3676 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3677 boolean isProvisioned) {
3678 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3679 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3680 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3681 }
3682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3683 "setProvisioningStatusForCapability");
3684 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3685 // If the current provisioning status for capability already matches isProvisioned,
3686 // do nothing.
3687 if (((provisionedBits & capability) > 0) == isProvisioned) {
3688 return;
3689 }
3690 if (isProvisioned) {
3691 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3692 } else {
3693 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3694 }
3695 }
3696
3697 /**
3698 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3699 * technology. The bitfield should mirror the bitfield defined by
3700 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3701 */
3702 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3703 String key = getMmTelProvisioningKey(subId, tech);
3704 // Default is no capabilities are provisioned.
3705 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3706 }
3707
3708 /**
3709 * Sets the MmTel capability provisioning bitfield (defined by
3710 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3711 * technology specified.
3712 *
3713 * Note: This is a synchronous command and should not be called on UI thread.
3714 */
3715 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3716 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3717 String key = getMmTelProvisioningKey(subId, tech);
3718 editor.putInt(key, newField);
3719 editor.commit();
3720 }
3721
3722 private static String getMmTelProvisioningKey(int subId, int tech) {
3723 // resulting key is provision_ims_mmtel_{subId}_{tech}
3724 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3725 }
3726
3727 /**
3728 * Query CarrierConfig to see if the specified capability requires provisioning for the
3729 * carrier associated with the subscription id.
3730 */
3731 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3732 int capability) {
3733 CarrierConfigManager configManager = new CarrierConfigManager(context);
3734 PersistableBundle c = configManager.getConfigForSubId(subId);
3735 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003736 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003737 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3738 false);
3739 boolean requireVoiceVtProvisioning = c.getBoolean(
3740 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3741
3742 // First check to make sure that the capability requires provisioning.
3743 switch (capability) {
3744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3745 // intentional fallthrough
3746 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3747 if (requireVoiceVtProvisioning) {
3748 // Voice and Video requires provisioning
3749 return true;
3750 }
3751 break;
3752 }
3753 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3754 if (requireUtProvisioning) {
3755 // UT requires provisioning
3756 return true;
3757 }
3758 break;
3759 }
3760 }
3761 return false;
3762 }
3763
allenwtsu99c623b2020-01-03 18:24:23 +08003764 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3765 int capability) {
3766 CarrierConfigManager configManager = new CarrierConfigManager(context);
3767 PersistableBundle c = configManager.getConfigForSubId(subId);
3768
3769 boolean requireRcsProvisioning = c.getBoolean(
3770 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3771
3772 // First check to make sure that the capability requires provisioning.
3773 switch (capability) {
3774 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3775 // intentional fallthrough
3776 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3777 if (requireRcsProvisioning) {
3778 // OPTION or PRESENCE requires provisioning
3779 return true;
3780 }
3781 break;
3782 }
3783 }
3784 return false;
3785 }
3786
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003787 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003788 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3790 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3791 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003792 enforceReadPrivilegedPermission("getImsProvisioningInt");
3793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003796 int slotId = getSlotIndex(subId);
3797 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3798 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3799 + subId + "' for key:" + key);
3800 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3801 }
3802 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003803 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003804 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3805 + subId + "' for key:" + key);
3806 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003807 } finally {
3808 Binder.restoreCallingIdentity(identity);
3809 }
3810 }
3811
3812 @Override
3813 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003814 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3815 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3816 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003817 enforceReadPrivilegedPermission("getImsProvisioningString");
3818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003821 int slotId = getSlotIndex(subId);
3822 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3823 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3824 + subId + "' for key:" + key);
3825 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3826 }
3827 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003828 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003829 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3830 + subId + "' for key:" + key);
3831 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003832 } finally {
3833 Binder.restoreCallingIdentity(identity);
3834 }
3835 }
3836
3837 @Override
3838 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003839 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3840 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3841 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3843 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003847 int slotId = getSlotIndex(subId);
3848 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3849 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3850 + subId + "' for key:" + key);
3851 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3852 }
3853 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003854 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003855 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3856 + "' for key:" + key);
3857 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003858 } finally {
3859 Binder.restoreCallingIdentity(identity);
3860 }
3861 }
3862
3863 @Override
3864 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003865 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3866 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3867 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3869 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003873 int slotId = getSlotIndex(subId);
3874 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3875 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3876 + subId + "' for key:" + key);
3877 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3878 }
3879 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003880 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003881 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3882 + "' for key:" + key);
3883 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003884 } finally {
3885 Binder.restoreCallingIdentity(identity);
3886 }
3887 }
3888
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003889 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 int slotId = SubscriptionManager.getSlotIndex(subId);
3891 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003892 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3893 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 }
3895 return slotId;
3896 }
3897
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003898 private int getSlotIndex(int subId) {
3899 int slotId = SubscriptionManager.getSlotIndex(subId);
3900 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3901 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3902 }
3903 return slotId;
3904 }
3905
Wink Saville36469e72014-06-11 15:17:00 -07003906 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003907 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003908 */
3909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003910 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3911 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003912 final int targetSdk = getTargetSdk(callingPackage);
3913 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003914 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003915 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003916 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003917 mApp, subId, callingPackage, callingFeatureId,
3918 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003919 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3920 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 final Phone phone = getPhone(subId);
3925 if (phone != null) {
3926 return phone.getServiceState().getDataNetworkType();
3927 } else {
3928 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3929 }
3930 } finally {
3931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003933 }
3934
3935 /**
3936 * Returns the data network type
3937 */
3938 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003939 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3940 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3941 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003942 }
3943
3944 /**
3945 * Returns the data network type for a subId
3946 */
3947 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003948 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3949 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003950 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003951 mApp, subId, callingPackage, callingFeatureId,
3952 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003953 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3954 }
3955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 final Phone phone = getPhone(subId);
3959 if (phone != null) {
3960 return phone.getServiceState().getDataNetworkType();
3961 } else {
3962 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3963 }
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003967 }
3968
3969 /**
Wink Saville36469e72014-06-11 15:17:00 -07003970 * Returns the Voice network type for a subId
3971 */
3972 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003973 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3974 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003975 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003976 mApp, subId, callingPackage, callingFeatureId,
3977 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003978 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3979 }
3980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 final Phone phone = getPhone(subId);
3984 if (phone != null) {
3985 return phone.getServiceState().getVoiceNetworkType();
3986 } else {
3987 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3988 }
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003992 }
3993
3994 /**
3995 * @return true if a ICC card is present
3996 */
3997 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003998 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003999 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4000 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004001 }
4002
4003 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004004 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004005 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004006 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004007 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 final Phone phone = PhoneFactory.getPhone(slotIndex);
4011 if (phone != null) {
4012 return phone.getIccCard().hasIccCard();
4013 } else {
4014 return false;
4015 }
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004018 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004019 }
4020
4021 /**
4022 * Return if the current radio is LTE on CDMA. This
4023 * is a tri-state return value as for a period of time
4024 * the mode may be unknown.
4025 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004026 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004027 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004028 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004029 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004031 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4032 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4033 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004034 }
4035
Sanket Padawe356d7632015-06-22 14:03:32 -07004036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004037 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4038 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004040 mApp, subId, callingPackage, callingFeatureId,
4041 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004042 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4043 }
4044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 final Phone phone = getPhone(subId);
4048 if (phone == null) {
4049 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4050 } else {
4051 return phone.getLteOnCdmaMode();
4052 }
4053 } finally {
4054 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004055 }
Wink Saville36469e72014-06-11 15:17:00 -07004056 }
4057
Wink Saville36469e72014-06-11 15:17:00 -07004058 /**
4059 * {@hide}
4060 * Returns Default subId, 0 in the case of single standby.
4061 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004062 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004063 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004064 }
4065
Shishir Agrawala9f32182016-04-12 12:00:16 -07004066 private int getSlotForDefaultSubscription() {
4067 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4068 }
4069
Wink Savilleb564aae2014-10-23 10:18:09 -07004070 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004071 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004072 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004073
Pengquan Menge92a50d2018-09-21 15:54:48 -07004074 private boolean isActiveSubscription(int subId) {
4075 return mSubscriptionController.isActiveSubId(subId);
4076 }
4077
Ihab Awadf2177b72013-11-25 13:33:23 -08004078 /**
4079 * @see android.telephony.TelephonyManager.WifiCallingChoices
4080 */
4081 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 final long identity = Binder.clearCallingIdentity();
4083 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004084 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4086 getWhenToMakeWifiCallsDefaultPreference());
4087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004090 }
4091
4092 /**
4093 * @see android.telephony.TelephonyManager.WifiCallingChoices
4094 */
4095 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004099 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004104 }
4105
Sailesh Nepald1e68152013-12-12 19:08:02 -08004106 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004107 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004108 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004109 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004110
Jordan Liu4c733742019-02-28 12:03:40 -08004111 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4112 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4113 if (phoneId == -1) {
4114 throw new IllegalArgumentException("Given slot index: " + slotIndex
4115 + " does not correspond to an active phone");
4116 }
4117 return PhoneFactory.getPhone(phoneId);
4118 }
4119
Shishir Agrawal566b7612013-10-28 14:41:00 -07004120 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004121 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4122 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4124 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004126 if (DBG) {
4127 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4128 }
4129 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4130 p2);
4131 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004132
Jordan Liu4c733742019-02-28 12:03:40 -08004133
4134 @Override
4135 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4136 int slotIndex, String callingPackage, String aid, int p2) {
4137 enforceModifyPermission();
4138 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4139 if (DBG) {
4140 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4141 }
4142 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4143 callingPackage, aid, p2);
4144 }
4145
4146 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4147 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 if (TextUtils.equals(ISDR_AID, aid)) {
4151 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004152 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4153 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004154 if (bestComponent == null
4155 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4156 loge("The calling package is not allowed to access ISD-R.");
4157 throw new SecurityException(
4158 "The calling package is not allowed to access ISD-R.");
4159 }
Derek Tan740e1672017-06-27 14:56:27 -07004160 }
Derek Tan740e1672017-06-27 14:56:27 -07004161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004163 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4164 null /* workSource */);
4165 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 return response;
4167 } finally {
4168 Binder.restoreCallingIdentity(identity);
4169 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004170 }
4171
4172 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004173 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4175 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004176 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4177 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4178 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004179
Jordan Liu4c733742019-02-28 12:03:40 -08004180 @Override
4181 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4182 enforceModifyPermission();
4183 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4184 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4185 channel);
4186 }
4187
4188 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004189 final long identity = Binder.clearCallingIdentity();
4190 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004191 if (channel < 0) {
4192 return false;
4193 }
Jordan Liu4c733742019-02-28 12:03:40 -08004194 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4195 null /* workSource */);
4196 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 return success;
4198 } finally {
4199 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004200 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004201 }
4202
4203 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004204 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004205 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4207 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004208 if (DBG) {
4209 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4210 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4211 + p3 + " data=" + data);
4212 }
4213 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4214 command, p1, p2, p3, data);
4215 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004216
Jordan Liu4c733742019-02-28 12:03:40 -08004217 @Override
4218 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4219 int command, int p1, int p2, int p3, String data) {
4220 enforceModifyPermission();
4221 if (DBG) {
4222 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4223 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4224 + p3 + " data=" + data);
4225 }
4226 return iccTransmitApduLogicalChannelWithPermission(
4227 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4228 data);
4229 }
4230
4231 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4232 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004233 final long identity = Binder.clearCallingIdentity();
4234 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004235 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004236 return "";
4237 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004240 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4241 null /* workSource */);
4242 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004244 // Append the returned status code to the end of the response payload.
4245 String s = Integer.toHexString(
4246 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4247 if (response.payload != null) {
4248 s = IccUtils.bytesToHexString(response.payload) + s;
4249 }
4250 return s;
4251 } finally {
4252 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004253 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004254 }
Jake Hambye994d462014-02-03 13:10:13 -08004255
Evan Charltonc66da362014-05-16 14:06:40 -07004256 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004257 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4258 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4260 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004262 if (DBG) {
4263 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4264 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4265 }
4266 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4267 cla, command, p1, p2, p3, data);
4268 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004269
Jordan Liu4c733742019-02-28 12:03:40 -08004270 @Override
4271 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4272 int command, int p1, int p2, int p3, String data) {
4273 enforceModifyPermission();
4274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4275 if (DBG) {
4276 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4277 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4278 + " data=" + data);
4279 }
4280
4281 return iccTransmitApduBasicChannelWithPermission(
4282 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4283 p2, p3, data);
4284 }
4285
4286 // open APDU basic channel assuming the caller has sufficient permissions
4287 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4288 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 final long identity = Binder.clearCallingIdentity();
4290 try {
4291 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4292 && TextUtils.equals(ISDR_AID, data)) {
4293 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004294 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4295 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 if (bestComponent == null
4297 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4298 loge("The calling package is not allowed to select ISD-R.");
4299 throw new SecurityException(
4300 "The calling package is not allowed to select ISD-R.");
4301 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004302 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004305 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4306 null /* workSource */);
4307 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 // Append the returned status code to the end of the response payload.
4310 String s = Integer.toHexString(
4311 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4312 if (response.payload != null) {
4313 s = IccUtils.bytesToHexString(response.payload) + s;
4314 }
4315 return s;
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004318 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004319 }
4320
4321 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004322 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004323 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4325 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 if (DBG) {
4330 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4331 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4332 }
4333
4334 IccIoResult response =
4335 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4336 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4337 subId);
4338
4339 if (DBG) {
4340 log("Exchange SIM_IO [R]" + response);
4341 }
4342
4343 byte[] result = null;
4344 int length = 2;
4345 if (response.payload != null) {
4346 length = 2 + response.payload.length;
4347 result = new byte[length];
4348 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4349 } else {
4350 result = new byte[length];
4351 }
4352
4353 result[length - 1] = (byte) response.sw2;
4354 result[length - 2] = (byte) response.sw1;
4355 return result;
4356 } finally {
4357 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004358 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004359 }
4360
Nathan Haroldb3014052017-01-25 15:57:32 -08004361 /**
4362 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4363 * on a particular subscription
4364 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004365 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4366 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004368 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004369 return null;
4370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371
4372 final long identity = Binder.clearCallingIdentity();
4373 try {
4374 if (appType != TelephonyManager.APPTYPE_USIM
4375 && appType != TelephonyManager.APPTYPE_SIM) {
4376 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4377 return null;
4378 }
4379 Object response = sendRequest(
4380 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4381 if (response instanceof String[]) {
4382 return (String[]) response;
4383 }
yincheng zhao2737e882019-09-06 17:06:54 -07004384 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004386 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 } finally {
4388 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004389 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004390 }
4391
yincheng zhao2737e882019-09-06 17:06:54 -07004392 /**
4393 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4394 * subscription.
4395 *
4396 * @param subId the id of the subscription.
4397 * @param appType the uicc app type, must be USIM or SIM.
4398 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4399 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004400 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004401 * @return number of fplmns that is successfully written to the SIM.
4402 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004403 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4404 String callingFeatureId) {
4405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4406 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004407 if (DBG) logv("no permissions for setForbiddenplmns");
4408 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4409 }
4410 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4411 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4412 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4413 }
4414 if (fplmns == null) {
4415 throw new IllegalArgumentException("Fplmn List provided is null");
4416 }
4417 for (String fplmn : fplmns) {
4418 if (!CellIdentity.isValidPlmn(fplmn)) {
4419 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4420 }
4421 }
4422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 Object response = sendRequest(
4425 CMD_SET_FORBIDDEN_PLMNS,
4426 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4427 subId);
4428 return (int) response;
4429 } finally {
4430 Binder.restoreCallingIdentity(identity);
4431 }
4432 }
4433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004434 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004435 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4437 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004439 final long identity = Binder.clearCallingIdentity();
4440 try {
4441 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4442 if (response.payload == null) {
4443 return "";
4444 }
Evan Charltonc66da362014-05-16 14:06:40 -07004445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 // Append the returned status code to the end of the response payload.
4447 String s = Integer.toHexString(
4448 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4449 s = IccUtils.bytesToHexString(response.payload) + s;
4450 return s;
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
Evan Charltonc66da362014-05-16 14:06:40 -07004454 }
4455
Jake Hambye994d462014-02-03 13:10:13 -08004456 /**
4457 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4458 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4459 *
4460 * @param itemID the ID of the item to read
4461 * @return the NV item as a String, or null on error.
4462 */
4463 @Override
4464 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004465 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4467 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468
4469 final long identity = Binder.clearCallingIdentity();
4470 try {
4471 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004472 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4474 return value;
4475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
Jake Hambye994d462014-02-03 13:10:13 -08004478 }
4479
4480 /**
4481 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4482 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4483 *
4484 * @param itemID the ID of the item to read
4485 * @param itemValue the value to write, as a String
4486 * @return true on success; false on any failure
4487 */
4488 @Override
4489 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004490 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4492 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004493
4494 final long identity = Binder.clearCallingIdentity();
4495 try {
4496 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4497 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004498 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4500 return success;
4501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
Jake Hambye994d462014-02-03 13:10:13 -08004504 }
4505
4506 /**
4507 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4508 * Used for device configuration by some CDMA operators.
4509 *
4510 * @param preferredRoamingList byte array containing the new PRL
4511 * @return true on success; false on any failure
4512 */
4513 @Override
4514 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4516 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517
4518 final long identity = Binder.clearCallingIdentity();
4519 try {
4520 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4521 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4522 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4523 return success;
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
Jake Hambye994d462014-02-03 13:10:13 -08004527 }
4528
4529 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004530 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004531 * Used for device configuration by some CDMA operators.
4532 *
chen xu6dac5ab2018-10-26 17:39:23 -07004533 * @param slotIndex - device slot.
4534 *
Jake Hambye994d462014-02-03 13:10:13 -08004535 * @return true on success; false on any failure
4536 */
4537 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004538 public boolean resetModemConfig(int slotIndex) {
4539 Phone phone = PhoneFactory.getPhone(slotIndex);
4540 if (phone != null) {
4541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4542 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543
chen xu6dac5ab2018-10-26 17:39:23 -07004544 final long identity = Binder.clearCallingIdentity();
4545 try {
4546 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4547 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4548 return success;
4549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004552 }
chen xu6dac5ab2018-10-26 17:39:23 -07004553 return false;
4554 }
4555
4556 /**
4557 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4558 *
4559 * @param slotIndex - device slot.
4560 *
4561 * @return true on success; false on any failure
4562 */
4563 @Override
4564 public boolean rebootModem(int slotIndex) {
4565 Phone phone = PhoneFactory.getPhone(slotIndex);
4566 if (phone != null) {
4567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4568 mApp, phone.getSubId(), "rebootModem");
4569
4570 final long identity = Binder.clearCallingIdentity();
4571 try {
4572 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4573 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4574 return success;
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
4578 }
4579 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004580 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004581
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004582 public String[] getPcscfAddress(String apnType, String callingPackage,
4583 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004584 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4586 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004587 return new String[0];
4588 }
4589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 final long identity = Binder.clearCallingIdentity();
4591 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004592 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593 } finally {
4594 Binder.restoreCallingIdentity(identity);
4595 }
Wink Saville36469e72014-06-11 15:17:00 -07004596 }
4597
Brad Ebinger51f743a2017-01-23 13:50:20 -08004598 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004599 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4600 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004601 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004602 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004603 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004604
4605 final long identity = Binder.clearCallingIdentity();
4606 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004607 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004608 // may happen if the device does not support IMS.
4609 return;
4610 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004611 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612 } finally {
4613 Binder.restoreCallingIdentity(identity);
4614 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004615 }
4616
4617 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004618 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4619 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004620 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004621 public void disableIms(int slotId) {
4622 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623
4624 final long identity = Binder.clearCallingIdentity();
4625 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004626 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004627 // may happen if the device does not support IMS.
4628 return;
4629 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004630 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 } finally {
4632 Binder.restoreCallingIdentity(identity);
4633 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004634 }
4635
4636 /**
4637 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4638 * feature or {@link null} if the service is not available. If the feature is available, the
4639 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4640 */
4641 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004642 IImsServiceFeatureCallback callback) {
4643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644
4645 final long identity = Binder.clearCallingIdentity();
4646 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004647 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004648 // may happen if the device does not support IMS.
4649 return null;
4650 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004651 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004655 }
4656
4657 /**
4658 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4659 * feature during emergency calling or {@link null} if the service is not available. If the
4660 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4661 * listener for feature updates.
4662 */
4663 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004668 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004669 // may happen if the device does not support IMS.
4670 return null;
4671 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004672 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004676 }
4677
Brad Ebinger5f64b052017-12-14 14:26:15 -08004678 /**
4679 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004680 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004681 */
4682 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004687 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004688 // may happen if the device does not support IMS.
4689 return null;
4690 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004691 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004695 }
4696
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004697 /**
4698 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004699 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004700 */
4701 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004703
4704 final long identity = Binder.clearCallingIdentity();
4705 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004706 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004707 // may happen if the device does not support IMS.
4708 return null;
4709 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004710 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004714 }
4715
Brad Ebinger884c07b2018-02-15 16:17:40 -08004716 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004717 * Sets the ImsService Package Name that Telephony will bind to.
4718 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004719 * @param slotIndex the slot ID that the ImsService should bind for.
4720 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004721 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004722 * @param featureTypes An integer array of feature types associated with a packageName.
4723 * @param packageName The name of the package that the current configuration will be replaced
4724 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004725 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004726 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004727 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4728 int[] featureTypes, String packageName) {
4729 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4732 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004733 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 final long identity = Binder.clearCallingIdentity();
4736 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004737 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004738 // may happen if the device does not support IMS.
4739 return false;
4740 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004741 Map<Integer, String> featureConfig = new HashMap<>();
4742 for (int featureType : featureTypes) {
4743 featureConfig.put(featureType, packageName);
4744 }
4745 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4746 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747 } finally {
4748 Binder.restoreCallingIdentity(identity);
4749 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004750 }
4751
4752 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004753 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004754 *
4755 * @param slotId The slot that the ImsService is associated with.
4756 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4757 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004758 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004759 * @return the package name of the ImsService configuration.
4760 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004761 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4762 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004763 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004764 TelephonyPermissions
4765 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4766 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4767 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 final long identity = Binder.clearCallingIdentity();
4770 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004771 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004772 // may happen if the device does not support IMS.
4773 return "";
4774 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004775 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004776 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4777 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 } finally {
4779 Binder.restoreCallingIdentity(identity);
4780 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004781 }
4782
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004783 /**
4784 * Get the MmTelFeature state associated with the requested subscription id.
4785 * @param subId The subscription that the MmTelFeature is associated with.
4786 * @param callback A callback with an integer containing the
4787 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4788 */
4789 @Override
4790 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4791 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4792 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4793 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4794 "IMS not available on device.");
4795 }
4796 final long token = Binder.clearCallingIdentity();
4797 try {
4798 int slotId = getSlotIndex(subId);
4799 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4800 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4801 + subId + "'");
4802 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4803 }
4804 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4805 try {
4806 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4807 } catch (RemoteException e) {
4808 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4809 + "Ignore");
4810 }
4811 });
4812 } finally {
4813 Binder.restoreCallingIdentity(token);
4814 }
4815 }
4816
Wink Saville36469e72014-06-11 15:17:00 -07004817 public void setImsRegistrationState(boolean registered) {
4818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819
4820 final long identity = Binder.clearCallingIdentity();
4821 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004822 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 } finally {
4824 Binder.restoreCallingIdentity(identity);
4825 }
Wink Saville36469e72014-06-11 15:17:00 -07004826 }
4827
4828 /**
Stuart Scott54788802015-03-30 13:18:01 -07004829 * Set the network selection mode to automatic.
4830 *
4831 */
4832 @Override
4833 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4835 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004836
Pengquan Menge92a50d2018-09-21 15:54:48 -07004837 if (!isActiveSubscription(subId)) {
4838 return;
4839 }
4840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 final long identity = Binder.clearCallingIdentity();
4842 try {
4843 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4844 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
Stuart Scott54788802015-03-30 13:18:01 -07004848 }
4849
Pengquan Mengea84e042018-09-20 14:57:26 -07004850 /**
4851 * Ask the radio to connect to the input network and change selection mode to manual.
4852 *
4853 * @param subId the id of the subscription.
4854 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4855 * the operator to attach to.
4856 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4857 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4858 * normal network selection next time.
4859 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004860 */
4861 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004862 public boolean setNetworkSelectionModeManual(
4863 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4865 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004866
4867 if (!isActiveSubscription(subId)) {
4868 return false;
4869 }
4870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 final long identity = Binder.clearCallingIdentity();
4872 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004873 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004875 if (DBG) {
4876 log("setNetworkSelectionModeManual: subId: " + subId
4877 + " operator: " + operatorInfo);
4878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004883 }
4884
4885 /**
4886 * Scans for available networks.
4887 */
4888 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004889 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4890 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4892 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004893 LocationAccessPolicy.LocationPermissionResult locationResult =
4894 LocationAccessPolicy.checkLocationPermission(mApp,
4895 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4896 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004897 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004898 .setCallingPid(Binder.getCallingPid())
4899 .setCallingUid(Binder.getCallingUid())
4900 .setMethod("getCellNetworkScanResults")
4901 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4902 .build());
4903 switch (locationResult) {
4904 case DENIED_HARD:
4905 throw new SecurityException("Not allowed to access scan results -- location");
4906 case DENIED_SOFT:
4907 return null;
4908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909
Pengquan Menga1bb6272018-09-06 09:59:22 -07004910 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 try {
4912 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004913 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915 } finally {
4916 Binder.restoreCallingIdentity(identity);
4917 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004918 }
4919
4920 /**
yinxub1bed742017-04-17 11:45:04 -07004921 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004922 *
yinxub1bed742017-04-17 11:45:04 -07004923 * @param subId id of the subscription
4924 * @param request contains the radio access networks with bands/channels to scan
4925 * @param messenger callback messenger for scan results or errors
4926 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004927 * @return the id of the requested scan which can be used to stop the scan.
4928 */
4929 @Override
4930 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004931 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4933 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004934 LocationAccessPolicy.LocationPermissionResult locationResult =
4935 LocationAccessPolicy.checkLocationPermission(mApp,
4936 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4937 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004938 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004939 .setCallingPid(Binder.getCallingPid())
4940 .setCallingUid(Binder.getCallingUid())
4941 .setMethod("requestNetworkScan")
4942 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4943 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004944 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004945 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004946 if (e != null) {
4947 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4948 throw e;
4949 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004950 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004951 return TelephonyScanManager.INVALID_SCAN_ID;
4952 }
4953 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 }
Hall Liu912dfd32019-04-25 14:02:26 -07004955 int callingUid = Binder.getCallingUid();
4956 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
4959 return mNetworkScanRequestTracker.startNetworkScan(
4960 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004961 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004962 } finally {
4963 Binder.restoreCallingIdentity(identity);
4964 }
yinxu504e1392017-04-12 16:03:22 -07004965 }
4966
Hall Liub2ac8ef2019-02-28 15:56:23 -08004967 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004968 NetworkScanRequest request, int subId) {
4969 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4970 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4971 boolean hasNetworkScanPermission =
4972 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4973 == PERMISSION_GRANTED;
4974
4975 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4976 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4977 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004978 }
4979
4980 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4981 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004982 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4983 return new SecurityException("Specific channels must not be"
4984 + " scanned without location access.");
4985 }
4986 }
4987 }
4988
Hall Liub2ac8ef2019-02-28 15:56:23 -08004989 return null;
4990 }
4991
yinxu504e1392017-04-12 16:03:22 -07004992 /**
4993 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004994 *
4995 * @param subId id of the subscription
4996 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004997 */
4998 @Override
4999 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5001 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002
Hall Liu912dfd32019-04-25 14:02:26 -07005003 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 final long identity = Binder.clearCallingIdentity();
5005 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005006 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 } finally {
5008 Binder.restoreCallingIdentity(identity);
5009 }
yinxu504e1392017-04-12 16:03:22 -07005010 }
5011
5012 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005013 * Get the calculated preferred network type.
5014 * Used for debugging incorrect network type.
5015 *
5016 * @return the preferred network type, defined in RILConstants.java.
5017 */
5018 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005019 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005020 final Phone defaultPhone = getDefaultPhone();
5021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005022 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005023 return RILConstants.PREFERRED_NETWORK_MODE;
5024 }
5025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005029 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005030 } finally {
5031 Binder.restoreCallingIdentity(identity);
5032 }
Junda Liu84d15a22014-07-02 11:21:04 -07005033 }
5034
5035 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005036 * Get the preferred network type.
5037 * Used for device configuration by some CDMA operators.
5038 *
5039 * @return the preferred network type, defined in RILConstants.java.
5040 */
5041 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005042 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005043 TelephonyPermissions
5044 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5045 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046
5047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 if (DBG) log("getPreferredNetworkType");
5050 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5051 int networkType = (result != null ? result[0] : -1);
5052 if (DBG) log("getPreferredNetworkType: " + networkType);
5053 return networkType;
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005057 }
5058
5059 /**
5060 * Set the preferred network type.
5061 * Used for device configuration by some CDMA operators.
5062 *
5063 * @param networkType the preferred network type, defined in RILConstants.java.
5064 * @return true on success; false on any failure.
5065 */
5066 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005067 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5069 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070
5071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
5074 Boolean success = (Boolean) sendRequest(
5075 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5076 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5077 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005078 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5080 }
5081 return success;
5082 } finally {
5083 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005084 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005085 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005086
5087 /**
Miaoa84611c2019-03-15 09:21:10 +08005088 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005089 *
Miaoa84611c2019-03-15 09:21:10 +08005090 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005091 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005092 * @hide
5093 */
5094 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005095 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005096 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005098 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005099 try {
Miaoa84611c2019-03-15 09:21:10 +08005100 if (phone != null) {
5101 return phone.hasMatchedTetherApnSetting();
5102 } else {
5103 return false;
5104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 } finally {
5106 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005107 }
Junda Liu475951f2014-11-07 16:45:03 -08005108 }
5109
5110 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005111 * Set mobile data enabled
5112 * Used by the user through settings etc to turn on/off mobile data
5113 *
5114 * @param enable {@code true} turn turn data on, else {@code false}
5115 */
5116 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005117 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5119 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120
5121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 int phoneId = mSubscriptionController.getPhoneId(subId);
5124 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5125 Phone phone = PhoneFactory.getPhone(phoneId);
5126 if (phone != null) {
5127 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005128 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005130 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 }
5132 } finally {
5133 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005134 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005135 }
5136
5137 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005138 * Get the user enabled state of Mobile Data.
5139 *
5140 * TODO: remove and use isUserDataEnabled.
5141 * This can't be removed now because some vendor codes
5142 * calls through ITelephony directly while they should
5143 * use TelephonyManager.
5144 *
5145 * @return true on enabled
5146 */
5147 @Override
5148 public boolean getDataEnabled(int subId) {
5149 return isUserDataEnabled(subId);
5150 }
5151
5152 /**
5153 * Get whether mobile data is enabled per user setting.
5154 *
5155 * There are other factors deciding whether mobile data is actually enabled, but they are
5156 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005157 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005158 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005159 *
5160 * @return {@code true} if data is enabled else {@code false}
5161 */
5162 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005163 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005164 try {
5165 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5166 null);
5167 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5169 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171
5172 final long identity = Binder.clearCallingIdentity();
5173 try {
5174 int phoneId = mSubscriptionController.getPhoneId(subId);
5175 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5176 Phone phone = PhoneFactory.getPhone(phoneId);
5177 if (phone != null) {
5178 boolean retVal = phone.isUserDataEnabled();
5179 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5180 return retVal;
5181 } else {
5182 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5183 return false;
5184 }
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005187 }
5188 }
5189
5190 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005191 * Checks if the device is capable of mobile data by considering whether whether the
5192 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5193 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005194 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005195 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005196 */
5197 @Override
5198 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005199 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200
5201 final long identity = Binder.clearCallingIdentity();
5202 try {
5203 int phoneId = mSubscriptionController.getPhoneId(subId);
5204 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5205 Phone phone = PhoneFactory.getPhone(phoneId);
5206 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005207 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5209 return retVal;
5210 } else {
5211 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5212 return false;
5213 }
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005216 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005217 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005218
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005219 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5220 Phone phone) {
5221 //load access rules from carrier configs, and check those as well: b/139133814
5222 SubscriptionController subController = SubscriptionController.getInstance();
5223 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5224 || subController == null) return privilegeFromSim;
5225
5226 int uid = Binder.getCallingUid();
5227 PackageManager pkgMgr = phone.getContext().getPackageManager();
5228 String[] packages = pkgMgr.getPackagesForUid(uid);
5229
5230 final long identity = Binder.clearCallingIdentity();
5231 try {
5232 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5233 SubscriptionManager subManager = (SubscriptionManager)
5234 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5235 for (String pkg : packages) {
5236 if (subManager.canManageSubscription(subInfo, pkg)) {
5237 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5238 }
5239 }
5240 return privilegeFromSim;
5241 } finally {
5242 Binder.restoreCallingIdentity(identity);
5243 }
5244 }
5245
5246 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5247 String pkgName) {
5248 //load access rules from carrier configs, and check those as well: b/139133814
5249 SubscriptionController subController = SubscriptionController.getInstance();
5250 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5251 || subController == null) return privilegeFromSim;
5252
5253 final long identity = Binder.clearCallingIdentity();
5254 try {
5255 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5256 SubscriptionManager subManager = (SubscriptionManager)
5257 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5258 return subManager.canManageSubscription(subInfo, pkgName)
5259 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
5263 }
5264
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005265 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005266 public int getCarrierPrivilegeStatus(int subId) {
5267 final Phone phone = getPhone(subId);
5268 if (phone == null) {
5269 loge("getCarrierPrivilegeStatus: Invalid subId");
5270 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5271 }
5272 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005273 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005274 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005275 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5276 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005277
5278 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5279 card.getCarrierPrivilegeStatusForCurrentTransaction(
5280 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005281 }
Junda Liu29340342014-07-10 15:23:27 -07005282
5283 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005284 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005285 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005286 final Phone phone = getPhone(subId);
5287 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005288 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005289 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5290 }
5291 UiccProfile profile =
5292 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5293 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005294 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005295 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5296 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005297 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005298 profile.getCarrierPrivilegeStatusForUid(
5299 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005300 }
5301
5302 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005303 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5304 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005305 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005306 }
5307
5308 int phoneId = SubscriptionManager.getPhoneId(subId);
5309 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005310 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005311 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005312 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5313 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005314 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5315 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5316 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005317 }
5318
5319 @Override
5320 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005321 if (TextUtils.isEmpty(pkgName))
5322 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005323 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5324 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5325 UiccCard card = UiccController.getInstance().getUiccCard(i);
5326 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005327 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005328 continue;
5329 }
5330
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005331 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5332 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5333 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005334 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5335 break;
5336 }
5337 }
5338
5339 return result;
Junda Liu29340342014-07-10 15:23:27 -07005340 }
Derek Tan89e89d42014-07-08 17:00:10 -07005341
5342 @Override
Junda Liue64de782015-04-16 17:19:16 -07005343 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5344 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5345 loge("phoneId " + phoneId + " is not valid.");
5346 return null;
5347 }
5348 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005349 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005350 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005351 return null ;
5352 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005353 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005354 }
5355
Amith Yamasani6e118872016-02-19 12:53:51 -08005356 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005357 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005358 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005359 List<String> privilegedPackages = new ArrayList<>();
5360 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005361 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5362 // has UICC in that slot.
5363 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005364 if (card.hasCarrierPrivilegeRules()) {
5365 if (packages == null) {
5366 // Only check packages in user 0 for now
5367 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005368 PackageManager.MATCH_DISABLED_COMPONENTS
5369 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005370 | PackageManager.GET_SIGNING_CERTIFICATES,
5371 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005372 }
5373 for (int p = packages.size() - 1; p >= 0; p--) {
5374 PackageInfo pkgInfo = packages.get(p);
5375 if (pkgInfo != null && pkgInfo.packageName != null
5376 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005377 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005378 privilegedPackages.add(pkgInfo.packageName);
5379 }
5380 }
5381 }
5382 }
5383 return privilegedPackages;
5384 }
5385
chen xuf7e9fe82019-05-09 19:31:02 -07005386 @Override
5387 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005388 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5389
5390 final long identity = Binder.clearCallingIdentity();
5391
chen xuf7e9fe82019-05-09 19:31:02 -07005392 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005393 try {
5394 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5395 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5396 }
5397 } finally {
5398 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005399 }
5400 return privilegedPackages;
5401 }
5402
Wink Savilleb564aae2014-10-23 10:18:09 -07005403 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005404 final Phone phone = getPhone(subId);
5405 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005406 if (card == null) {
5407 loge("getIccId: No UICC");
5408 return null;
5409 }
5410 String iccId = card.getIccId();
5411 if (TextUtils.isEmpty(iccId)) {
5412 loge("getIccId: ICC ID is null or empty.");
5413 return null;
5414 }
5415 return iccId;
5416 }
5417
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005418 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005419 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5420 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005421 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005422 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 final String iccId = getIccId(subId);
5427 final Phone phone = getPhone(subId);
5428 if (phone == null) {
5429 return false;
5430 }
5431 final String subscriberId = phone.getSubscriberId();
5432
5433 if (DBG_MERGE) {
5434 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5435 + subscriberId + " to " + number);
5436 }
5437
5438 if (TextUtils.isEmpty(iccId)) {
5439 return false;
5440 }
5441
5442 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5443
5444 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5445 if (alphaTag == null) {
5446 editor.remove(alphaTagPrefKey);
5447 } else {
5448 editor.putString(alphaTagPrefKey, alphaTag);
5449 }
5450
5451 // Record both the line number and IMSI for this ICCID, since we need to
5452 // track all merged IMSIs based on line number
5453 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5454 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5455 if (number == null) {
5456 editor.remove(numberPrefKey);
5457 editor.remove(subscriberPrefKey);
5458 } else {
5459 editor.putString(numberPrefKey, number);
5460 editor.putString(subscriberPrefKey, subscriberId);
5461 }
5462
5463 editor.commit();
5464 return true;
5465 } finally {
5466 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005467 }
Derek Tan7226c842014-07-02 17:42:23 -07005468 }
5469
5470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005471 public String getLine1NumberForDisplay(int subId, String callingPackage,
5472 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005473 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005475 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005476 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005477 return null;
5478 }
Derek Tan97ebb422014-09-05 16:55:38 -07005479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 String iccId = getIccId(subId);
5483 if (iccId != null) {
5484 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5485 if (DBG_MERGE) {
5486 log("getLine1NumberForDisplay returning "
5487 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5488 }
5489 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5492 return null;
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005495 }
Derek Tan7226c842014-07-02 17:42:23 -07005496 }
5497
5498 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005499 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5500 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005502 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005503 return null;
5504 }
Derek Tan97ebb422014-09-05 16:55:38 -07005505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 final long identity = Binder.clearCallingIdentity();
5507 try {
5508 String iccId = getIccId(subId);
5509 if (iccId != null) {
5510 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5511 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5512 }
5513 return null;
5514 } finally {
5515 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005516 }
Derek Tan7226c842014-07-02 17:42:23 -07005517 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005518
5519 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005520 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5521 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005522 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5523 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005525 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005526 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005527 return null;
5528 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005529
Jordan Liub49b04b2019-05-06 14:45:15 -07005530 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5531 // the process, where TelephonyManager was instantiated.
5532 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005533 final long identity = Binder.clearCallingIdentity();
5534 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005535 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 final TelephonyManager tele = TelephonyManager.from(context);
5537 final SubscriptionManager sub = SubscriptionManager.from(context);
5538
5539 // Figure out what subscribers are currently active
5540 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541
Jordan Liub49b04b2019-05-06 14:45:15 -07005542 // Only consider subs which match the current subId
5543 // This logic can be simplified. See b/131189269 for progress.
5544 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005545 activeSubscriberIds.add(tele.getSubscriberId(subId));
5546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547
5548 // First pass, find a number override for an active subscriber
5549 String mergeNumber = null;
5550 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5551 for (String key : prefs.keySet()) {
5552 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5553 final String subscriberId = (String) prefs.get(key);
5554 if (activeSubscriberIds.contains(subscriberId)) {
5555 final String iccId = key.substring(
5556 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5557 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5558 mergeNumber = (String) prefs.get(numberKey);
5559 if (DBG_MERGE) {
5560 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5561 + " for active subscriber " + subscriberId);
5562 }
5563 if (!TextUtils.isEmpty(mergeNumber)) {
5564 break;
5565 }
5566 }
5567 }
5568 }
5569
5570 // Shortcut when no active merged subscribers
5571 if (TextUtils.isEmpty(mergeNumber)) {
5572 return null;
5573 }
5574
5575 // Second pass, find all subscribers under that line override
5576 final ArraySet<String> result = new ArraySet<>();
5577 for (String key : prefs.keySet()) {
5578 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5579 final String number = (String) prefs.get(key);
5580 if (mergeNumber.equals(number)) {
5581 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5582 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5583 final String subscriberId = (String) prefs.get(subscriberKey);
5584 if (!TextUtils.isEmpty(subscriberId)) {
5585 result.add(subscriberId);
5586 }
5587 }
5588 }
5589 }
5590
5591 final String[] resultArray = result.toArray(new String[result.size()]);
5592 Arrays.sort(resultArray);
5593 if (DBG_MERGE) {
5594 Slog.d(LOG_TAG,
5595 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5596 }
5597 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005598 } finally {
5599 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005600 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005601 }
5602
5603 @Override
zoey chen38003472019-12-13 17:16:31 +08005604 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5605 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005606
5607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 final TelephonyManager telephonyManager = mApp.getSystemService(
5610 TelephonyManager.class);
5611 String subscriberId = telephonyManager.getSubscriberId(subId);
5612 if (subscriberId == null) {
5613 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005614 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005615 + subId);
5616 }
5617 return null;
5618 }
5619
5620 final SubscriptionInfo info = SubscriptionController.getInstance()
5621 .getSubscriptionInfo(subId);
5622 final ParcelUuid groupUuid = info.getGroupUuid();
5623 // If it doesn't belong to any group, return just subscriberId of itself.
5624 if (groupUuid == null) {
5625 return new String[]{subscriberId};
5626 }
5627
5628 // Get all subscriberIds from the group.
5629 final List<String> mergedSubscriberIds = new ArrayList<>();
5630 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005631 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5632 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005633 for (SubscriptionInfo subInfo : groupInfos) {
5634 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5635 if (subscriberId != null) {
5636 mergedSubscriberIds.add(subscriberId);
5637 }
5638 }
5639
5640 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643
5644 }
5645 }
5646
5647 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005648 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005649 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005650 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 final Phone phone = getPhone(subId);
5655 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5656 } finally {
5657 Binder.restoreCallingIdentity(identity);
5658 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005659 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005660
5661 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005662 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005663 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5664 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005665 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5666 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667
5668 final long identity = Binder.clearCallingIdentity();
5669 try {
5670 final Phone phone = getPhone(subId);
5671 if (phone == null) {
5672 return false;
5673 }
5674 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5675 cdmaNonRoamingList);
5676 } finally {
5677 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005678 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005679 }
5680
5681 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005682 @Deprecated
5683 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5684 enforceModifyPermission();
5685
5686 int returnValue = 0;
5687 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005688 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005689 if(result.exception == null) {
5690 if (result.result != null) {
5691 byte[] responseData = (byte[])(result.result);
5692 if(responseData.length > oemResp.length) {
5693 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5694 responseData.length + "bytes. Buffer Size is " +
5695 oemResp.length + "bytes.");
5696 }
5697 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5698 returnValue = responseData.length;
5699 }
5700 } else {
5701 CommandException ex = (CommandException) result.exception;
5702 returnValue = ex.getCommandError().ordinal();
5703 if(returnValue > 0) returnValue *= -1;
5704 }
5705 } catch (RuntimeException e) {
5706 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5707 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5708 if(returnValue > 0) returnValue *= -1;
5709 }
5710
5711 return returnValue;
5712 }
5713
5714 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005715 public void setRadioCapability(RadioAccessFamily[] rafs) {
5716 try {
5717 ProxyController.getInstance().setRadioCapability(rafs);
5718 } catch (RuntimeException e) {
5719 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5720 }
5721 }
5722
5723 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005724 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005725 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005726 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005727 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005728 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 final long identity = Binder.clearCallingIdentity();
5731 try {
chen xub97461a2018-10-26 14:17:57 -07005732 TelephonyPermissions
5733 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5734 mApp, phone.getSubId(), "getRadioAccessFamily");
5735 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
chen xub97461a2018-10-26 14:17:57 -07005739 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005740 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005741
5742 @Override
5743 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005744 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005749 ImsManager.getInstance(defaultPhone.getContext(),
5750 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005754 }
5755
5756 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005757 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005758 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5760 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005761 return false;
5762 }
Svet Ganovb320e182015-04-16 12:30:10 -07005763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 // Check the user preference and the system-level IMS setting. Even if the user has
5767 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5768 // In the long run, we may instead need to check if there exists a connection service
5769 // which can support video calling.
5770 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005771 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 return imsManager.isVtEnabledByPlatform()
5773 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5774 && imsManager.isVtEnabledByUser();
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005778 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005779
Andrew Leea1239f22015-03-02 17:44:07 -08005780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005781 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5782 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005784 mApp, subId, callingPackage, callingFeatureId,
5785 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 return false;
5787 }
5788
5789 final long identity = Binder.clearCallingIdentity();
5790 try {
5791 CarrierConfigManager configManager =
5792 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005793 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Andrew Leea1239f22015-03-02 17:44:07 -08005798 }
5799
5800 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005801 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005803 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 return false;
5805 }
5806
5807 final long identity = Binder.clearCallingIdentity();
5808 try {
5809 CarrierConfigManager configManager =
5810 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005811 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
Andrew Leea1239f22015-03-02 17:44:07 -08005816 }
5817
Andrew Lee9431b832015-03-09 18:46:45 -07005818 @Override
5819 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005820 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005821 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005822 }
5823
5824 @Override
5825 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 final long identity = Binder.clearCallingIdentity();
5827 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005828 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 } finally {
5830 Binder.restoreCallingIdentity(identity);
5831 }
Andrew Lee9431b832015-03-09 18:46:45 -07005832 }
5833
Hall Liuf6668912018-10-31 17:05:23 -07005834 /**
5835 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5836 * support for the feature and device firmware support.
5837 *
5838 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5839 */
5840 @Override
5841 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005843 final Phone phone = getPhone(subscriptionId);
5844 if (phone == null) {
5845 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5846 return false;
5847 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005849 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5851 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005852 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853 return isCarrierSupported && isDeviceSupported;
5854 } finally {
5855 Binder.restoreCallingIdentity(identity);
5856 }
Hall Liu98187582018-01-22 19:15:32 -08005857 }
5858
Hall Liuf6668912018-10-31 17:05:23 -07005859 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005860 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5861 * RTT setting, will return true if the device and carrier both support RTT.
5862 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005863 */
5864 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 final long identity = Binder.clearCallingIdentity();
5866 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005867 boolean isRttSupported = isRttSupported(subscriptionId);
5868 boolean isUserRttSettingOn = Settings.Secure.getInt(
5869 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5870 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5871 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5872 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873 } finally {
5874 Binder.restoreCallingIdentity(identity);
5875 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005876 }
5877
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005878 @Deprecated
5879 @Override
5880 public String getDeviceId(String callingPackage) {
5881 return getDeviceIdWithFeature(callingPackage, null);
5882 }
5883
Sanket Padawe7310cc72015-01-14 09:53:20 -08005884 /**
5885 * Returns the unique device ID of phone, for example, the IMEI for
5886 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5887 *
5888 * <p>Requires Permission:
5889 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5890 */
5891 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005892 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005893 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005894 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005895 return null;
5896 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005897 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005898 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005899 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005900 return null;
5901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
5905 return phone.getDeviceId();
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005909 }
5910
Ping Sunc67b7c22016-03-02 19:16:45 +08005911 /**
5912 * {@hide}
5913 * Returns the IMS Registration Status on a particular subid
5914 *
5915 * @param subId
5916 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005917 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005918 Phone phone = getPhone(subId);
5919 if (phone != null) {
5920 return phone.isImsRegistered();
5921 } else {
5922 return false;
5923 }
5924 }
5925
Santos Cordon7a1885b2015-02-03 11:15:19 -08005926 @Override
5927 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 final long identity = Binder.clearCallingIdentity();
5929 try {
5930 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005934 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005935
Tyler Gunnf70ed162019-04-03 15:28:53 -07005936 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005937 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005938 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005940 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005941 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5942 }
5943 final long identity = Binder.clearCallingIdentity();
5944 try {
5945 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5946 } finally {
5947 Binder.restoreCallingIdentity(identity);
5948 }
5949 }
5950
5951 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005952 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 Phone phone = getPhone(subscriptionId);
5956 if (phone == null) {
5957 return null;
5958 }
5959 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
5963 }
5964
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005965 /**
5966 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005967 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005968 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 final long identity = Binder.clearCallingIdentity();
5970 try {
5971 Phone phone = getPhone(subId);
5972 if (phone != null) {
5973 return phone.isWifiCallingEnabled();
5974 } else {
5975 return false;
5976 }
5977 } finally {
5978 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005979 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005980 }
5981
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005982 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005983 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005984 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005985 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 final long identity = Binder.clearCallingIdentity();
5987 try {
5988 Phone phone = getPhone(subId);
5989 if (phone != null) {
5990 return phone.isVideoEnabled();
5991 } else {
5992 return false;
5993 }
5994 } finally {
5995 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005996 }
5997 }
5998
5999 /**
6000 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6001 * defined in {@link ImsRegistrationImplBase}.
6002 */
6003 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 final long identity = Binder.clearCallingIdentity();
6005 try {
6006 Phone phone = getPhone(subId);
6007 if (phone != null) {
6008 return phone.getImsRegistrationTech();
6009 } else {
6010 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6011 }
6012 } finally {
6013 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006014 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006015 }
6016
Stuart Scott8eef64f2015-04-08 15:13:54 -07006017 @Override
6018 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006019 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006020 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6021 return;
6022 }
6023
Svet Ganovcc087f82015-05-12 20:35:54 -07006024 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006025
Svet Ganovcc087f82015-05-12 20:35:54 -07006026 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006027 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6028 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006029 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006030 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006031 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006032 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6033 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006034 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006035 // There has been issues when Sms raw table somehow stores orphan
6036 // fragments. They lead to garbled message when new fragments come
6037 // in and combined with those stale ones. In case this happens again,
6038 // user can reset all network settings which will clean up this table.
6039 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006040 // Clean up IMS settings as well here.
6041 int slotId = getSlotIndex(subId);
6042 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6043 ImsManager.getInstance(mApp, slotId).factoryReset();
6044 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006045
6046 // Erase modem config if erase modem on network setting is enabled.
6047 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6048 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6049 if (configValue != null && Boolean.parseBoolean(configValue)) {
6050 sendEraseModemConfig(getDefaultPhone());
6051 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006052 } finally {
6053 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006054 }
6055 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006056
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006057 private void cleanUpSmsRawTable(Context context) {
6058 ContentResolver resolver = context.getContentResolver();
6059 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6060 resolver.delete(uri, null, null);
6061 }
6062
Narayan Kamath1c496c22015-04-16 14:40:19 +01006063 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006064 public String getSimLocaleForSubscriber(int subId) {
6065 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6066 final Phone phone = getPhone(subId);
6067 if (phone == null) {
6068 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006069 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 final long identity = Binder.clearCallingIdentity();
6072 try {
chen xu5d3637b2019-01-21 23:31:38 -08006073 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006074 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006075 if (info == null) {
6076 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6077 return null;
6078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 // Try and fetch the locale from the carrier properties or from the SIM language
6080 // preferences (EF-PL and EF-LI)...
6081 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006083 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6084 if (localeFromDefaultSim != null) {
6085 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6086 if (DBG) log("Using locale from subId: " + subId + " locale: "
6087 + localeFromDefaultSim);
6088 return localeFromDefaultSim.toLanguageTag();
6089 } else {
6090 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 }
6092 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 // The SIM language preferences only store a language (e.g. fr = French), not an
6095 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6096 // the SIM and carrier preferences does not include a country we add the country
6097 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006098 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006100 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 return mccLocale.toLanguageTag();
6102 }
6103
6104 if (DBG) log("No locale found - returning null");
6105 return null;
6106 } finally {
6107 Binder.restoreCallingIdentity(identity);
6108 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006109 }
6110
6111 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006112 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6113 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006114 }
6115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 /**
6117 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6118 */
6119 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006120 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6121 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006122 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006123
Chenjie Yu1ba97252018-01-11 18:16:20 -08006124 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006125 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006126
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006127 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006128 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6129 * representing the state of the modem.
6130 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006131 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6132 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006133 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006134 */
6135 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006136 public void requestModemActivityInfo(ResultReceiver result) {
6137 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006138 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139
6140 final long identity = Binder.clearCallingIdentity();
6141 try {
6142 ModemActivityInfo ret = null;
6143 synchronized (mLastModemActivityInfo) {
6144 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6145 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006146 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006147 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006149 int[] txTimeMs = info.getTransmitTimeMillis();
6150 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006152 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 }
6154 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006155 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6156 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 mLastModemActivityInfo.setIdleTimeMillis(
6158 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006159 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6160 mLastModemActivityInfo.setReceiveTimeMillis(
6161 info.getReceiveTimeMillis() + mLastModemActivityInfo
6162 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006163 }
Chen Xud78231e2019-09-10 18:49:52 -07006164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6166 mLastModemActivityInfo.getSleepTimeMillis(),
6167 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006168 mLastModemActivityInfo.getTransmitTimeMillis(),
6169 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 Bundle bundle = new Bundle();
6172 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6173 result.send(0, bundle);
6174 } finally {
6175 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006176 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006177 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006178
Siddharth Rayb8114062018-06-17 15:02:38 -07006179 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6180 // less than total activity duration.
6181 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6182 if (info == null) {
6183 return false;
6184 }
6185 int activityDurationMs =
6186 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6187 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006188 int[] txTimeMs = info.getTransmitTimeMillis();
6189 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6190 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006191 }
6192 return (info.isValid()
6193 && (info.getSleepTimeMillis() <= activityDurationMs)
6194 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006195 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006196 && (totalTxTimeMs <= activityDurationMs));
6197 }
6198
Jack Yu85bd38a2015-11-09 11:34:32 -08006199 /**
6200 * {@hide}
6201 * Returns the service state information on specified subscription.
6202 */
6203 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006204 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6205 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006207 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006208 return null;
6209 }
6210
Hall Liuf19c44f2018-11-27 14:38:17 -08006211 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6212 LocationAccessPolicy.checkLocationPermission(mApp,
6213 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6214 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006215 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006216 .setCallingPid(Binder.getCallingPid())
6217 .setCallingUid(Binder.getCallingUid())
6218 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006219 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006220 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6221 .build());
6222
6223 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6224 LocationAccessPolicy.checkLocationPermission(mApp,
6225 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6226 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006227 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006228 .setCallingPid(Binder.getCallingPid())
6229 .setCallingUid(Binder.getCallingUid())
6230 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006231 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006232 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6233 .build());
6234 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6235 boolean hasFinePermission =
6236 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6237 boolean hasCoarsePermission =
6238 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 final long identity = Binder.clearCallingIdentity();
6241 try {
6242 final Phone phone = getPhone(subId);
6243 if (phone == null) {
6244 return null;
6245 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006246
Hall Liuf19c44f2018-11-27 14:38:17 -08006247 ServiceState ss = phone.getServiceState();
6248
6249 // Scrub out the location info in ServiceState depending on what level of access
6250 // the caller has.
6251 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006252 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6253 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 } finally {
6255 Binder.restoreCallingIdentity(identity);
6256 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006257 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006258
6259 /**
6260 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6261 *
6262 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6263 * voicemail ringtone.
6264 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6265 * PhoneAccount.
6266 */
6267 @Override
6268 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269 final long identity = Binder.clearCallingIdentity();
6270 try {
6271 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6272 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006273 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6277 } finally {
6278 Binder.restoreCallingIdentity(identity);
6279 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006280 }
6281
6282 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006283 * Sets the per-account voicemail ringtone.
6284 *
6285 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6286 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6287 *
6288 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6289 * voicemail ringtone.
6290 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6291 * PhoneAccount.
6292 */
6293 @Override
6294 public void setVoicemailRingtoneUri(String callingPackage,
6295 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006296 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006297 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006298 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6299 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6301 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6302 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304
6305 final long identity = Binder.clearCallingIdentity();
6306 try {
6307 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6308 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006309 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 }
6311 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6312 } finally {
6313 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006314 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006315 }
6316
6317 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006318 * Returns whether vibration is set for voicemail notification in Phone settings.
6319 *
6320 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6321 * voicemail vibration setting.
6322 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6323 */
6324 @Override
6325 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 final long identity = Binder.clearCallingIdentity();
6327 try {
6328 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6329 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006330 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6334 } finally {
6335 Binder.restoreCallingIdentity(identity);
6336 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006337 }
6338
Youhan Wange64578a2016-05-02 15:32:42 -07006339 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006340 * Sets the per-account voicemail vibration.
6341 *
6342 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6343 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6344 *
6345 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6346 * voicemail vibration setting.
6347 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6348 * specific PhoneAccount.
6349 */
6350 @Override
6351 public void setVoicemailVibrationEnabled(String callingPackage,
6352 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006353 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006354 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006355 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6356 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6358 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6359 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006360 }
6361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362 final long identity = Binder.clearCallingIdentity();
6363 try {
6364 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6365 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006366 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 }
6368 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6369 } finally {
6370 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006371 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006372 }
6373
6374 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006375 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6376 *
6377 * @throws SecurityException if the caller does not have the required permission
6378 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006379 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006380 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006381 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006382 }
6383
6384 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006385 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6386 * permission.
6387 *
6388 * @throws SecurityException if the caller does not have the required permission
6389 */
6390 private void enforceSendSmsPermission() {
6391 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6392 }
6393
6394 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006395 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006396 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006397 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006398 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006399 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 final long identity = Binder.clearCallingIdentity();
6401 try {
6402 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006403 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404 if (componentName == null) {
6405 throw new SecurityException(
6406 "Caller not current active visual voicemail package[null]");
6407 }
6408 String vvmPackage = componentName.getPackageName();
6409 if (!callingPackage.equals(vvmPackage)) {
6410 throw new SecurityException("Caller not current active visual voicemail package["
6411 + vvmPackage + "]");
6412 }
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006415 }
6416 }
6417
6418 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006419 * Return the application ID for the app type.
6420 *
6421 * @param subId the subscription ID that this request applies to.
6422 * @param appType the uicc app type.
6423 * @return Application ID for specificied app type, or null if no uicc.
6424 */
6425 @Override
6426 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006427 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006428 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
6430 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006431 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 if (phone == null) {
6433 return null;
6434 }
6435 String aid = null;
6436 try {
6437 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6438 .getApplicationByType(appType).getAid();
6439 } catch (Exception e) {
6440 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6441 }
6442 return aid;
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006445 }
Youhan Wange64578a2016-05-02 15:32:42 -07006446 }
6447
Youhan Wang4001d252016-05-11 10:29:41 -07006448 /**
6449 * Return the Electronic Serial Number.
6450 *
6451 * @param subId the subscription ID that this request applies to.
6452 * @return ESN or null if error.
6453 */
6454 @Override
6455 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006456 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006457 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458
6459 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006460 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461 if (phone == null) {
6462 return null;
6463 }
6464 String esn = null;
6465 try {
6466 esn = phone.getEsn();
6467 } catch (Exception e) {
6468 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6469 }
6470 return esn;
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006473 }
Youhan Wang4001d252016-05-11 10:29:41 -07006474 }
6475
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006476 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006477 * Return the Preferred Roaming List Version.
6478 *
6479 * @param subId the subscription ID that this request applies to.
6480 * @return PRLVersion or null if error.
6481 */
6482 @Override
6483 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006484 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006485 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006486
6487 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006488 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 if (phone == null) {
6490 return null;
6491 }
6492 String cdmaPrlVersion = null;
6493 try {
6494 cdmaPrlVersion = phone.getCdmaPrlVersion();
6495 } catch (Exception e) {
6496 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6497 }
6498 return cdmaPrlVersion;
6499 } finally {
6500 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006501 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006502 }
6503
6504 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006505 * Get snapshot of Telephony histograms
6506 * @return List of Telephony histograms
6507 * @hide
6508 */
6509 @Override
6510 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6512 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513
6514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 return RIL.getTelephonyRILTimingHistograms();
6517 } finally {
6518 Binder.restoreCallingIdentity(identity);
6519 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006520 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006521
6522 /**
6523 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006524 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6525 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006526 * Require system privileges. In the future we may add this to carrier APIs.
6527 *
Michele Berionne482f8202018-11-27 18:57:59 -08006528 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006529 */
6530 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006531 @TelephonyManager.SetCarrierRestrictionResult
6532 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006533 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006534 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006535
Michele Berionne482f8202018-11-27 18:57:59 -08006536 if (carrierRestrictionRules == null) {
6537 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006538 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 final long identity = Binder.clearCallingIdentity();
6541 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006542 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006543 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 } finally {
6545 Binder.restoreCallingIdentity(identity);
6546 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006547 }
6548
6549 /**
6550 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006551 * Get the allowed carrier list and the excluded carrier list, including the priority between
6552 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006553 * Require system privileges. In the future we may add this to carrier APIs.
6554 *
Michele Berionne482f8202018-11-27 18:57:59 -08006555 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006556 */
6557 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006558 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006559 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006560 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561
6562 final long identity = Binder.clearCallingIdentity();
6563 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006564 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6565 if (response instanceof CarrierRestrictionRules) {
6566 return (CarrierRestrictionRules) response;
6567 }
6568 // Response is an Exception of some kind,
6569 // which is signalled to the user as a NULL retval
6570 return null;
6571 } catch (Exception e) {
6572 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6573 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006577 }
6578
fionaxu59545b42016-05-25 15:53:37 -07006579 /**
6580 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6581 * @param subId the subscription ID that this action applies to.
6582 * @param enabled control enable or disable metered apns.
6583 * {@hide}
6584 */
6585 @Override
6586 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6587 enforceModifyPermission();
6588 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589
6590 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006591 if (phone == null) {
6592 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6593 return;
6594 }
6595 try {
6596 phone.carrierActionSetMeteredApnsEnabled(enabled);
6597 } catch (Exception e) {
6598 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 } finally {
6600 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006601 }
6602 }
6603
6604 /**
6605 * Action set from carrier signalling broadcast receivers to enable/disable radio
6606 * @param subId the subscription ID that this action applies to.
6607 * @param enabled control enable or disable radio.
6608 * {@hide}
6609 */
6610 @Override
6611 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6612 enforceModifyPermission();
6613 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614
6615 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006616 if (phone == null) {
6617 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6618 return;
6619 }
6620 try {
6621 phone.carrierActionSetRadioEnabled(enabled);
6622 } catch (Exception e) {
6623 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006624 } finally {
6625 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006626 }
6627 }
6628
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006629 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006630 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6631 * network status based on which carrier apps could apply actions accordingly,
6632 * enable/disable default url handler for example.
6633 *
6634 * @param subId the subscription ID that this action applies to.
6635 * @param report control start/stop reporting the default network status.
6636 * {@hide}
6637 */
6638 @Override
6639 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6640 enforceModifyPermission();
6641 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006642
6643 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006644 if (phone == null) {
6645 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6646 return;
6647 }
6648 try {
6649 phone.carrierActionReportDefaultNetworkStatus(report);
6650 } catch (Exception e) {
6651 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652 } finally {
6653 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006654 }
6655 }
6656
6657 /**
fionaxud9622282017-07-17 17:51:30 -07006658 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6659 * @param subId the subscription ID that this action applies to.
6660 * {@hide}
6661 */
6662 @Override
6663 public void carrierActionResetAll(int subId) {
6664 enforceModifyPermission();
6665 final Phone phone = getPhone(subId);
6666 if (phone == null) {
6667 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6668 return;
6669 }
6670 try {
6671 phone.carrierActionResetAll();
6672 } catch (Exception e) {
6673 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6674 }
6675 }
6676
6677 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006678 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6679 * bug report is being generated.
6680 */
6681 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006682 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006683 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6684 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006685 writer.println("Permission Denial: can't dump Phone from pid="
6686 + Binder.getCallingPid()
6687 + ", uid=" + Binder.getCallingUid()
6688 + "without permission "
6689 + android.Manifest.permission.DUMP);
6690 return;
6691 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006692 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006693 }
Jack Yueb89b242016-06-22 13:27:47 -07006694
Brad Ebingerdac2f002018-04-03 15:17:52 -07006695 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006696 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6697 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6698 @NonNull String[] args) {
6699 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6700 this, in.getFileDescriptor(), out.getFileDescriptor(),
6701 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006702 }
6703
Jack Yueb89b242016-06-22 13:27:47 -07006704 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006705 * Get aggregated video call data usage since boot.
6706 *
6707 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6708 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006709 * {@hide}
6710 */
6711 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006712 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006713 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6714 null);
6715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 final long identity = Binder.clearCallingIdentity();
6717 try {
6718 // NetworkStatsService keeps tracking the active network interface and identity. It
6719 // records the delta with the corresponding network identity.
6720 // We just return the total video call data usage snapshot since boot.
6721 Phone phone = getPhone(subId);
6722 if (phone != null) {
6723 return phone.getVtDataUsage(perUidStats);
6724 }
6725 return null;
6726 } finally {
6727 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006728 }
Jack Yueb89b242016-06-22 13:27:47 -07006729 }
Jack Yu75ab2952016-07-08 14:29:33 -07006730
6731 /**
6732 * Policy control of data connection. Usually used when data limit is passed.
6733 * @param enabled True if enabling the data, otherwise disabling.
6734 * @param subId Subscription index
6735 * {@hide}
6736 */
6737 @Override
6738 public void setPolicyDataEnabled(boolean enabled, int subId) {
6739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740
6741 final long identity = Binder.clearCallingIdentity();
6742 try {
6743 Phone phone = getPhone(subId);
6744 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006745 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 }
6747 } finally {
6748 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006749 }
6750 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006751
6752 /**
6753 * Get Client request stats
6754 * @return List of Client Request Stats
6755 * @hide
6756 */
6757 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006758 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6759 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006761 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006762 return null;
6763 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006764 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 final long identity = Binder.clearCallingIdentity();
6767 try {
6768 if (phone != null) {
6769 return phone.getClientRequestStats();
6770 }
6771
6772 return null;
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
6775 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006776 }
6777
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006778 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006779 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006780 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006781 }
Jack Yueb4124c2017-02-16 15:32:43 -08006782
6783 /**
Grace Chen70990072017-03-24 17:21:30 -07006784 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006785 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006786 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006787 * @param state State of SIM (power down, power up, pass through)
6788 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6789 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6790 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006791 *
6792 **/
6793 @Override
Grace Chen70990072017-03-24 17:21:30 -07006794 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006795 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006796 Phone phone = PhoneFactory.getPhone(slotIndex);
6797
vagdeviaf9a5b92018-08-15 16:01:53 -07006798 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006800 final long identity = Binder.clearCallingIdentity();
6801 try {
6802 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006803 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 }
6805 } finally {
6806 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006807 }
6808 }
Shuo Qiandd210312017-04-12 22:11:33 +00006809
Tyler Gunn65d45c22017-06-05 11:22:26 -07006810 private boolean isUssdApiAllowed(int subId) {
6811 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006812 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006813 if (configManager == null) {
6814 return false;
6815 }
6816 PersistableBundle pb = configManager.getConfigForSubId(subId);
6817 if (pb == null) {
6818 return false;
6819 }
6820 return pb.getBoolean(
6821 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6822 }
6823
Shuo Qiandd210312017-04-12 22:11:33 +00006824 /**
6825 * Check if phone is in emergency callback mode
6826 * @return true if phone is in emergency callback mode
6827 * @param subId sub id
6828 */
goneil9c5f4872017-12-05 14:07:56 -08006829 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006830 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006831 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833
6834 final long identity = Binder.clearCallingIdentity();
6835 try {
6836 if (phone != null) {
6837 return phone.isInEcm();
6838 } else {
6839 return false;
6840 }
6841 } finally {
6842 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006843 }
6844 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006845
6846 /**
6847 * Get the current signal strength information for the given subscription.
6848 * Because this information is not updated when the device is in a low power state
6849 * it should not be relied-upon to be current.
6850 * @param subId Subscription index
6851 * @return the most recent cached signal strength info from the modem
6852 */
6853 @Override
6854 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 final long identity = Binder.clearCallingIdentity();
6856 try {
6857 Phone p = getPhone(subId);
6858 if (p == null) {
6859 return null;
6860 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 return p.getSignalStrength();
6863 } finally {
6864 Binder.restoreCallingIdentity(identity);
6865 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006866 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006867
Pengquan Meng77b7f132018-08-22 14:49:57 -07006868 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006869 * Get the current modem radio state for the given slot.
6870 * @param slotIndex slot index.
6871 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006872 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006873 * @return the current radio power state from the modem
6874 */
6875 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006876 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006877 Phone phone = PhoneFactory.getPhone(slotIndex);
6878 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6880 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006881 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6882 }
6883
6884 final long identity = Binder.clearCallingIdentity();
6885 try {
6886 return phone.getRadioPowerState();
6887 } finally {
6888 Binder.restoreCallingIdentity(identity);
6889 }
6890 }
6891 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6892 }
6893
6894 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006895 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6896 *
6897 * <p>Requires one of the following permissions:
6898 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6899 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6900 * privileges.
6901 *
6902 * @param subId subscription id
6903 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6904 * {@code false}.
6905 */
6906 @Override
6907 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006908 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6909 null /* message */);
6910
Pengquan Menga1bb6272018-09-06 09:59:22 -07006911 boolean isEnabled = false;
6912 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006913 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006914 Phone phone = getPhone(subId);
6915 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006916 } catch (Exception e) {
6917 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6918 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006919 } finally {
6920 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006921 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006922 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006923 }
6924
6925
6926 /**
6927 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6928 *
6929 * <p> Requires permission:
6930 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6931 * privileges.
6932 *
6933 * @param subId subscription id
6934 * @param isEnabled {@code true} means enable, {@code false} means disable.
6935 */
6936 @Override
6937 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6939 mApp, subId, "setDataRoamingEnabled");
6940
Pengquan Menga1bb6272018-09-06 09:59:22 -07006941 final long identity = Binder.clearCallingIdentity();
6942 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006943 Phone phone = getPhone(subId);
6944 if (phone != null) {
6945 phone.setDataRoamingEnabled(isEnabled);
6946 }
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006949 }
6950 }
6951
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006952 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006953 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006954 TelephonyPermissions
6955 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006956 mApp, subId, "isManualNetworkSelectionAllowed");
6957
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006958 boolean isAllowed = true;
6959 final long identity = Binder.clearCallingIdentity();
6960 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006961 Phone phone = getPhone(subId);
6962 if (phone != null) {
6963 isAllowed = phone.isCspPlmnEnabled();
6964 }
6965 } finally {
6966 Binder.restoreCallingIdentity(identity);
6967 }
6968 return isAllowed;
6969 }
6970
6971 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006972 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006973 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006974 try {
6975 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006976 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006977 } catch (SecurityException e) {
6978 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6979 // has carrier privileges on an active UICC
6980 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6981 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006982 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006983 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006984 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006985
6986 final long identity = Binder.clearCallingIdentity();
6987 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006988 UiccController uiccController = UiccController.getInstance();
6989 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006990 if (hasReadPermission) {
6991 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006992 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006993
6994 // Remove private info if the caller doesn't have access
6995 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6996 for (UiccCardInfo cardInfo : cardInfos) {
6997 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6998 // is available
6999 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7000 if (card == null || card.getUiccProfile() == null) {
7001 // assume no access if the card or profile is unavailable
7002 filteredInfos.add(cardInfo.getUnprivileged());
7003 continue;
7004 }
7005 UiccProfile profile = card.getUiccProfile();
7006 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7007 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7008 filteredInfos.add(cardInfo);
7009 } else {
7010 filteredInfos.add(cardInfo.getUnprivileged());
7011 }
7012 }
7013 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007014 } finally {
7015 Binder.restoreCallingIdentity(identity);
7016 }
7017 }
7018
7019 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007020 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007021 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7026 if (slots == null) {
7027 Rlog.i(LOG_TAG, "slots is null.");
7028 return null;
7029 }
7030
7031 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7032 for (int i = 0; i < slots.length; i++) {
7033 UiccSlot slot = slots[i];
7034 if (slot == null) {
7035 continue;
7036 }
7037
Jordan Liu7be7e652019-05-06 18:55:02 +00007038 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039 UiccCard card = slot.getUiccCard();
7040 if (card != null) {
7041 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007042 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007043 cardId = slot.getEid();
7044 if (TextUtils.isEmpty(cardId)) {
7045 cardId = slot.getIccId();
7046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047 }
7048
Jordan Liu857451f2019-05-09 16:35:35 -07007049 if (cardId != null) {
7050 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7051 // if cardId is an EID, it's all digits so this is fine
7052 cardId = IccUtils.stripTrailingFs(cardId);
7053 }
7054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 int cardState = 0;
7056 switch (slot.getCardState()) {
7057 case CARDSTATE_ABSENT:
7058 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7059 break;
7060 case CARDSTATE_PRESENT:
7061 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7062 break;
7063 case CARDSTATE_ERROR:
7064 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7065 break;
7066 case CARDSTATE_RESTRICTED:
7067 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7068 break;
7069 default:
7070 break;
7071
7072 }
7073
7074 infos[i] = new UiccSlotInfo(
7075 slot.isActive(),
7076 slot.isEuicc(),
7077 cardId,
7078 cardState,
7079 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007080 slot.isExtendedApduSupported(),
7081 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 }
7083 return infos;
7084 } finally {
7085 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007086 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007087 }
7088
7089 @Override
7090 public boolean switchSlots(int[] physicalSlots) {
7091 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092
7093 final long identity = Binder.clearCallingIdentity();
7094 try {
7095 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007099 }
Jack Yu4c988042018-02-27 15:30:01 -08007100
7101 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007102 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007103 final long identity = Binder.clearCallingIdentity();
7104 try {
7105 return UiccController.getInstance().getCardIdForDefaultEuicc();
7106 } finally {
7107 Binder.restoreCallingIdentity(identity);
7108 }
7109 }
7110
7111 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007112 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7113 enforceModifyPermission();
7114 final Phone phone = getPhone(subId);
7115 if (phone == null) {
7116 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7117 return;
7118 }
7119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 final long identity = Binder.clearCallingIdentity();
7121 try {
7122 phone.setRadioIndicationUpdateMode(filters, mode);
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125 }
Jack Yu4c988042018-02-27 15:30:01 -08007126 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007127
7128 /**
goneil47ffb6e2018-04-06 15:40:58 -07007129 * A test API to reload the UICC profile.
7130 *
7131 * <p>Requires that the calling app has permission
7132 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7133 * @hide
7134 */
7135 @Override
7136 public void refreshUiccProfile(int subId) {
7137 enforceModifyPermission();
7138
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 Phone phone = getPhone(subId);
7142 if (phone == null) {
7143 return;
7144 }
7145 UiccCard uiccCard = phone.getUiccCard();
7146 if (uiccCard == null) {
7147 return;
7148 }
7149 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7150 if (uiccProfile == null) {
7151 return;
7152 }
7153 uiccProfile.refresh();
7154 } finally {
7155 Binder.restoreCallingIdentity(identity);
7156 }
7157 }
7158
7159 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007160 * Returns false if the mobile data is disabled by default, otherwise return true.
7161 */
7162 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007163 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007164 }
7165
7166 /**
7167 * Returns true if the data roaming is enabled by default, i.e the system property
7168 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7169 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7170 */
7171 private boolean getDefaultDataRoamingEnabled(int subId) {
7172 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007173 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007174 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007175 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7176 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7177 return isDataRoamingEnabled;
7178 }
7179
7180 /**
7181 * Returns the default network type for the given {@code subId}, if the default network type is
7182 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7183 */
7184 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007185 List<Integer> list = TelephonyProperties.default_network();
7186 int phoneId = mSubscriptionController.getPhoneId(subId);
7187 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7188 return list.get(phoneId);
7189 }
7190 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007191 }
fionaxua13278b2018-03-21 00:08:13 -07007192
7193 @Override
7194 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007195 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007196 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197
7198 final long identity = Binder.clearCallingIdentity();
7199 try {
7200 final Phone phone = getPhone(subId);
7201 if (phone == null) {
7202 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7203 return;
7204 }
chen xueaba88a2019-03-15 13:15:10 -07007205 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7206 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 } finally {
7208 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007209 }
fionaxua13278b2018-03-21 00:08:13 -07007210 }
7211
7212 @Override
7213 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007214 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215
7216 final long identity = Binder.clearCallingIdentity();
7217 try {
7218 final Phone phone = getPhone(subId);
7219 if (phone == null) {
7220 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7221 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7222 }
7223 return phone.getCarrierIdListVersion();
7224 } finally {
7225 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007226 }
fionaxua13278b2018-03-21 00:08:13 -07007227 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007228
7229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007230 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7231 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007233 mApp, subId, callingPackage, callingFeatureId,
7234 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007235 return -1;
7236 }
7237
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
7244 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007245
7246 @Override
7247 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007248 TelephonyPermissions
7249 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007250 mApp, subId, "getCdmaRoamingMode");
7251
7252 final long identity = Binder.clearCallingIdentity();
7253 try {
7254 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7255 } finally {
7256 Binder.restoreCallingIdentity(identity);
7257 }
7258 }
7259
7260 @Override
7261 public boolean setCdmaRoamingMode(int subId, int mode) {
7262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7263 mApp, subId, "setCdmaRoamingMode");
7264
7265 final long identity = Binder.clearCallingIdentity();
7266 try {
7267 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
7270 }
7271 }
7272
7273 @Override
7274 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7276 mApp, subId, "setCdmaSubscriptionMode");
7277
7278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
7283 }
7284 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007285
sqianc5eccab2018-10-19 18:46:41 -07007286 @Override
sqian8c685422019-02-22 15:55:18 -08007287 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007288 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007290 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7291 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007292 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7293 }
7294 final long identity = Binder.clearCallingIdentity();
7295 try {
sqian854d44b2018-12-12 16:48:18 -08007296 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7297 for (Phone phone: PhoneFactory.getPhones()) {
7298 if (phone.getEmergencyNumberTracker() != null
7299 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7300 emergencyNumberListInternal.put(
7301 phone.getSubId(),
7302 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7303 }
sqian11b7a0e2018-12-05 18:48:28 -08007304 }
sqian854d44b2018-12-12 16:48:18 -08007305 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007306 } finally {
7307 Binder.restoreCallingIdentity(identity);
7308 }
sqianc5eccab2018-10-19 18:46:41 -07007309 }
7310
7311 @Override
sqian8c685422019-02-22 15:55:18 -08007312 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007313 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007314 if (!exactMatch) {
7315 TelephonyPermissions
7316 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007317 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007318 }
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
sqian854d44b2018-12-12 16:48:18 -08007321 for (Phone phone: PhoneFactory.getPhones()) {
7322 if (phone.getEmergencyNumberTracker() != null
7323 && phone.getEmergencyNumberTracker() != null) {
7324 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7325 number, exactMatch)) {
7326 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007327 }
7328 }
sqian11b7a0e2018-12-05 18:48:28 -08007329 }
7330 return false;
7331 } finally {
7332 Binder.restoreCallingIdentity(identity);
7333 }
7334 }
7335
sqianf4ca7ed2019-01-15 18:32:07 -08007336 /**
7337 * Update emergency number list for test mode.
7338 */
7339 @Override
7340 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7341 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7342 "updateEmergencyNumberListTestMode");
7343
7344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 for (Phone phone: PhoneFactory.getPhones()) {
7347 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7348 if (tracker != null) {
7349 tracker.executeEmergencyNumberTestModeCommand(action, num);
7350 }
7351 }
7352 } finally {
7353 Binder.restoreCallingIdentity(identity);
7354 }
7355 }
7356
7357 /**
7358 * Get the full emergency number list for test mode.
7359 */
7360 @Override
7361 public List<String> getEmergencyNumberListTestMode() {
7362 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7363 "getEmergencyNumberListTestMode");
7364
7365 final long identity = Binder.clearCallingIdentity();
7366 try {
7367 Set<String> emergencyNumbers = new HashSet<>();
7368 for (Phone phone: PhoneFactory.getPhones()) {
7369 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7370 if (tracker != null) {
7371 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7372 emergencyNumbers.add(num.getNumber());
7373 }
7374 }
7375 }
7376 return new ArrayList<>(emergencyNumbers);
7377 } finally {
7378 Binder.restoreCallingIdentity(identity);
7379 }
7380 }
7381
chen xud6b45bd2018-10-30 22:27:10 -07007382 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007383 public int getEmergencyNumberDbVersion(int subId) {
7384 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7385
7386 final long identity = Binder.clearCallingIdentity();
7387 try {
7388 final Phone phone = getPhone(subId);
7389 if (phone == null) {
7390 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7391 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7392 }
7393 return phone.getEmergencyNumberDbVersion();
7394 } finally {
7395 Binder.restoreCallingIdentity(identity);
7396 }
7397 }
7398
7399 @Override
7400 public void notifyOtaEmergencyNumberDbInstalled() {
7401 enforceModifyPermission();
7402
7403 final long identity = Binder.clearCallingIdentity();
7404 try {
7405 for (Phone phone: PhoneFactory.getPhones()) {
7406 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7407 if (tracker != null) {
7408 tracker.updateOtaEmergencyNumberDatabase();
7409 }
7410 }
7411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
7414 }
7415
7416 @Override
7417 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7418 enforceActiveEmergencySessionPermission();
7419
7420 final long identity = Binder.clearCallingIdentity();
7421 try {
7422 for (Phone phone: PhoneFactory.getPhones()) {
7423 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7424 if (tracker != null) {
7425 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7426 }
7427 }
7428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
7431 }
7432
7433 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007434 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7435 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7436 Phone phone = getPhone(subId);
7437 if (phone == null) {
7438 return null;
7439 }
7440 final long identity = Binder.clearCallingIdentity();
7441 try {
7442 UiccProfile profile = UiccController.getInstance()
7443 .getUiccProfileForPhone(phone.getPhoneId());
7444 if (profile != null) {
7445 return profile.getCertsFromCarrierPrivilegeAccessRules();
7446 }
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
7450 return null;
7451 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007452
7453 /**
7454 * Enable or disable a modem stack.
7455 */
7456 @Override
7457 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7458 enforceModifyPermission();
7459
7460 final long identity = Binder.clearCallingIdentity();
7461 try {
7462 Phone phone = PhoneFactory.getPhone(slotIndex);
7463 if (phone == null) {
7464 return false;
7465 } else {
7466 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7467 }
7468 } finally {
7469 Binder.restoreCallingIdentity(identity);
7470 }
7471 }
Michelecea4cf22018-12-21 15:00:11 -08007472
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007473 /**
7474 * Whether a modem stack is enabled or not.
7475 */
7476 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007477 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7478 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007479 Phone phone = PhoneFactory.getPhone(slotIndex);
7480 if (phone == null) return false;
7481
7482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007483 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7484 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007485 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7486 }
7487
7488 final long identity = Binder.clearCallingIdentity();
7489 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007490 try {
7491 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7492 } catch (NoSuchElementException ex) {
7493 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7494 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007495 } finally {
7496 Binder.restoreCallingIdentity(identity);
7497 }
7498 }
7499
Michelecea4cf22018-12-21 15:00:11 -08007500 @Override
Michele0ea7d782019-03-19 14:58:42 -07007501 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007502 enforceModifyPermission();
7503
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007507 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007508 .commit();
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
7512 }
7513
7514 @Override
Michele0ea7d782019-03-19 14:58:42 -07007515 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007516 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007518 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7519 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007520 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007521 }
Michelecea4cf22018-12-21 15:00:11 -08007522
7523 final long identity = Binder.clearCallingIdentity();
7524 try {
Michele0ea7d782019-03-19 14:58:42 -07007525 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007526 } finally {
7527 Binder.restoreCallingIdentity(identity);
7528 }
7529 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007530
Michele0ea7d782019-03-19 14:58:42 -07007531 @TelephonyManager.IsMultiSimSupportedResult
7532 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007533 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7534 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7535 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007536 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7537 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007538 }
7539 // Check if the hardware supports multisim functionality. If usage of multisim is not
7540 // supported by the modem, indicate that it is restricted.
7541 PhoneCapability staticCapability =
7542 mPhoneConfigurationManager.getStaticPhoneCapability();
7543 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007544 loge("isMultiSimSupportedInternal: no static configuration available");
7545 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007546 }
7547 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007548 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7549 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007550 }
7551 // Check if support of multiple SIMs is restricted by carrier
7552 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007553 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007554 }
7555
Michele0ea7d782019-03-19 14:58:42 -07007556 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007557 }
7558
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007559 /**
7560 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007561 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7562 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7563 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007564 * @param numOfSims number of active sims we want to switch to
7565 */
7566 @Override
7567 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007568 if (numOfSims == 1) {
7569 enforceModifyPermission();
7570 } else {
7571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7572 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7573 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007574 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007575
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007576 try {
Michele30b57b22019-03-01 12:01:14 -08007577 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007578 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007579 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7580 return;
7581 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007582 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7583 } finally {
7584 Binder.restoreCallingIdentity(identity);
7585 }
7586 }
7587
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007588 @Override
7589 public boolean isApplicationOnUicc(int subId, int appType) {
7590 enforceReadPrivilegedPermission("isApplicationOnUicc");
7591 Phone phone = getPhone(subId);
7592 if (phone == null) {
7593 return false;
7594 }
7595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 UiccCard uiccCard = phone.getUiccCard();
7598 if (uiccCard == null) {
7599 return false;
7600 }
7601 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7602 if (uiccProfile == null) {
7603 return false;
7604 }
7605 if (TelephonyManager.APPTYPE_SIM <= appType
7606 && appType <= TelephonyManager.APPTYPE_ISIM) {
7607 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7608 }
7609 return false;
7610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
7613 }
7614
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007615 /**
chen xub4baa772019-04-03 10:23:41 -07007616 * Get whether making changes to modem configurations will trigger reboot.
7617 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007618 */
7619 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007620 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7621 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007623 mApp, subId, callingPackage, callingFeatureId,
7624 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007625 return false;
7626 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007627 final long identity = Binder.clearCallingIdentity();
7628 try {
7629 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
7632 }
7633 }
7634
Nathan Harold29f5f052019-02-15 13:41:57 -08007635 private void updateModemStateMetrics() {
7636 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7637 // TODO: check the state for each modem if the api is ready.
7638 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7639 }
7640
Pengquan Meng3889a572019-01-23 11:16:29 -08007641 @Override
7642 public int[] getSlotsMapping() {
7643 enforceReadPrivilegedPermission("getSlotsMapping");
7644
7645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7648 // All logical slots should have a mapping to a physical slot.
7649 int[] logicalSlotsMapping = new int[phoneCount];
7650 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7651 for (int i = 0; i < slotInfos.length; i++) {
7652 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7653 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7654 }
7655 }
7656 return logicalSlotsMapping;
7657 } finally {
7658 Binder.restoreCallingIdentity(identity);
7659 }
7660 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007661
7662 /**
7663 * Get the IRadio HAL Version
7664 */
7665 @Override
7666 public int getRadioHalVersion() {
7667 Phone phone = getDefaultPhone();
7668 if (phone == null) return -1;
7669 HalVersion hv = phone.getHalVersion();
7670 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7671 return hv.major * 100 + hv.minor;
7672 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007673
7674 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007675 * Get the current calling package name.
7676 * @return the current calling package name
7677 */
7678 @Override
7679 public String getCurrentPackageName() {
7680 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7681 }
7682
7683 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007684 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7685 * corresponding network requests on a subId.
7686 *
7687 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007688 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007689 * 2) APN is un-metered for this subscription, or
7690 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007691 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007692 *
7693 * @return whether data is allowed for a apn type.
7694 *
7695 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007696 */
7697 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007698 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007699 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7700 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007701
7702 // Now that all security checks passes, perform the operation as ourselves.
7703 final long identity = Binder.clearCallingIdentity();
7704 try {
7705 Phone phone = getPhone(subId);
7706 if (phone == null) return false;
7707
Jack Yu41407ee2019-05-13 16:54:09 -07007708 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007709 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7710 } finally {
7711 Binder.restoreCallingIdentity(identity);
7712 }
7713 }
7714
7715 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007716 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007717 enforceReadPrivilegedPermission("isApnMetered");
7718
7719 // Now that all security checks passes, perform the operation as ourselves.
7720 final long identity = Binder.clearCallingIdentity();
7721 try {
7722 Phone phone = getPhone(subId);
7723 if (phone == null) return true; // By default return true.
7724
Jack Yu41407ee2019-05-13 16:54:09 -07007725 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007726 } finally {
7727 Binder.restoreCallingIdentity(identity);
7728 }
7729 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007730
7731 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007732 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7733 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7734 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7735 if (iccRecords == null) {
7736 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7737 return false;
7738 }
7739 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7740 }
7741
7742 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007743 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007744 if (callingPackage == null) {
7745 callingPackage = getCurrentPackageName();
7746 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007747 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7748 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7749 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7750 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7751 }
7752 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7753 Intent intent = new Intent();
7754 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7755 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7756 // Bring up choose default SMS subscription dialog right now
7757 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7758 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7759 mApp.startActivity(intent);
7760 }
chen xud5ca2d52019-05-28 15:20:57 -07007761
7762 @Override
7763 public String getMmsUAProfUrl(int subId) {
7764 //TODO investigate if this API should require proper permission check in R b/133791609
7765 final long identity = Binder.clearCallingIdentity();
7766 try {
7767 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7768 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7769 } finally {
7770 Binder.restoreCallingIdentity(identity);
7771 }
7772 }
7773
7774 @Override
7775 public String getMmsUserAgent(int subId) {
7776 //TODO investigate if this API should require proper permission check in R b/133791609
7777 final long identity = Binder.clearCallingIdentity();
7778 try {
7779 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7780 .getString(com.android.internal.R.string.config_mms_user_agent);
7781 } finally {
7782 Binder.restoreCallingIdentity(identity);
7783 }
7784 }
Jack Yub07d4972019-05-28 16:12:25 -07007785
7786 @Override
7787 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7788 enforceModifyPermission();
7789
7790 // Now that all security checks passes, perform the operation as ourselves.
7791 final long identity = Binder.clearCallingIdentity();
7792 try {
7793 Phone phone = getPhone(subId);
7794 if (phone == null) return false;
7795
7796 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7797 } finally {
7798 Binder.restoreCallingIdentity(identity);
7799 }
7800 }
7801
7802 @Override
7803 public boolean isDataAllowedInVoiceCall(int subId) {
7804 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7805
7806 // Now that all security checks passes, perform the operation as ourselves.
7807 final long identity = Binder.clearCallingIdentity();
7808 try {
7809 Phone phone = getPhone(subId);
7810 if (phone == null) return false;
7811
7812 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7813 } finally {
7814 Binder.restoreCallingIdentity(identity);
7815 }
7816 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007817
changbettyd5c246e2019-12-24 15:40:37 +08007818 @Override
7819 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7820 enforceModifyPermission();
7821
7822 // Now that all security checks passes, perform the operation as ourselves.
7823 final long identity = Binder.clearCallingIdentity();
7824 try {
7825 Phone phone = getPhone(subId);
7826 if (phone == null) return false;
7827
7828 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7829 } finally {
7830 Binder.restoreCallingIdentity(identity);
7831 }
7832 }
7833
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007834 /**
7835 * Updates whether conference event pacakge handling is enabled.
7836 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7837 * otherwise.
7838 */
7839 @Override
7840 public void setCepEnabled(boolean isCepEnabled) {
7841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7842
7843 final long identity = Binder.clearCallingIdentity();
7844 try {
7845 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7846 for (Phone phone : PhoneFactory.getPhones()) {
7847 Phone defaultPhone = phone.getImsPhone();
7848 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7849 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7850 ImsPhoneCallTracker imsPhoneCallTracker =
7851 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7852 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7853 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7854 + imsPhone.getMsisdn());
7855 }
7856 }
7857 } finally {
7858 Binder.restoreCallingIdentity(identity);
7859 }
7860 }
allenwtsu46dcc572020-01-08 18:24:03 +08007861
7862 /**
7863 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7864 *
7865 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7866 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7867 * before being read.
7868 */
7869 @Override
7870 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7871 isCompressed) {
7872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7873 mApp, subId, "notifyRcsAutoConfigurationReceived");
7874 try {
7875 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7876 if (configBinder == null) {
7877 Rlog.e(LOG_TAG, "null result for getImsConfig");
7878 } else {
7879 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7880 }
7881 } catch (RemoteException e) {
7882 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7883 }
7884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007885}