blob: 0226ef2640f8e7e113dbbbd7dd57ac7ce7654b1b [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
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunn327a9722019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070047import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080048import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070049import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070051import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070052import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070054import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070055import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070056import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080057import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070058import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080059import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080060import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070061import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070062import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080063import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070065import android.telephony.CellInfoGsm;
66import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070067import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070069import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070070import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080071import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070072import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080073import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070074import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080075import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080076import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070077import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080078import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080081import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070082import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080094import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080096import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070097import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080098import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070099import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsMmTelFeature;
101import android.telephony.ims.aidl.IImsRcsFeature;
102import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800104import android.telephony.ims.feature.MmTelFeature;
105import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800106import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800110import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800112
Brad Ebinger4c460712018-10-01 10:40:55 -0700113import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700114import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800115import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700117import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700118import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800119import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700120import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800123import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800124import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800126import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700127import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100128import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700129import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700132import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800133import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700134import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700135import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700136import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700137import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700138import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800140import com.android.internal.telephony.SmsApplication;
141import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800142import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800143import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chen460810d2019-04-10 18:25:07 -0700144import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqian9d4df8b2019-01-15 18:32:07 -0800145import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700146import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800147import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800148import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.uicc.IccIoResult;
150import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800151import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700152import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800153import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000156import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700157import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700159import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800160import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700161import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700162import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800163
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700164import java.io.FileDescriptor;
165import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800166import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800168import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800169import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800170import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800171import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800172import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100173import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800175import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176
177/**
178 * Implementation of the ITelephony interface.
179 */
Santos Cordon117fee72014-05-16 17:56:12 -0700180public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181 private static final String LOG_TAG = "PhoneInterfaceManager";
182 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
183 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185
186 // Message codes used with mMainThreadHandler
187 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700188 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
189 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190 private static final int CMD_OPEN_CHANNEL = 9;
191 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
192 private static final int CMD_CLOSE_CHANNEL = 11;
193 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800194 private static final int CMD_NV_READ_ITEM = 13;
195 private static final int EVENT_NV_READ_ITEM_DONE = 14;
196 private static final int CMD_NV_WRITE_ITEM = 15;
197 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
198 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
199 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700200 private static final int CMD_RESET_MODEM_CONFIG = 19;
201 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800202 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
203 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
204 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
205 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800206 private static final int CMD_SEND_ENVELOPE = 25;
207 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000208 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
209 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700210 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
211 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
212 private static final int CMD_EXCHANGE_SIM_IO = 31;
213 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800214 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
215 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700216 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
217 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700218 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
219 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700220 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
221 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
222 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
223 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700224 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
225 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
226 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
227 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700228 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800229 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
230 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000231 private static final int CMD_SWITCH_SLOTS = 50;
232 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700233 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
234 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
235 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
236 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
237 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
238 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
239 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
240 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700241 private static final int CMD_GET_ALL_CELL_INFO = 60;
242 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
243 private static final int CMD_GET_CELL_LOCATION = 62;
244 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700245 private static final int CMD_MODEM_REBOOT = 64;
246 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700247 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
248 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800249 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
250 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800252 // Parameters of select command.
253 private static final int SELECT_COMMAND = 0xA4;
254 private static final int SELECT_P1 = 0x04;
255 private static final int SELECT_P2 = 0;
256 private static final int SELECT_P3 = 0x10;
257
Pengquan Meng85728fb2018-03-12 16:31:21 -0700258 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
259 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
260 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
261
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262 /** The singleton instance. */
263 private static PhoneInterfaceManager sInstance;
264
Wink Saville3ab207e2014-11-20 13:07:20 -0800265 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800266 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700267 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800268 private AppOpsManager mAppOps;
269 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800270 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800271 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700272 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273
Derek Tan97ebb422014-09-05 16:55:38 -0700274 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
275 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800276 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800277 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700278
Micheled3107c52018-12-21 15:00:11 -0800279 // String to store multi SIM allowed
280 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
281
Derek Tan740e1672017-06-27 14:56:27 -0700282 // The AID of ISD-R.
283 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
284
yinxub1bed742017-04-17 11:45:04 -0700285 private NetworkScanRequestTracker mNetworkScanRequestTracker;
286
David Kelly5e06a7f2018-03-12 14:10:59 +0000287 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
288 private static final int MANUFACTURER_CODE_LENGTH = 8;
289
Derek Tan89e89d42014-07-08 17:00:10 -0700290 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700291 * A request object to use for transmitting data to an ICC.
292 */
293 private static final class IccAPDUArgument {
294 public int channel, cla, command, p1, p2, p3;
295 public String data;
296
297 public IccAPDUArgument(int channel, int cla, int command,
298 int p1, int p2, int p3, String data) {
299 this.channel = channel;
300 this.cla = cla;
301 this.command = command;
302 this.p1 = p1;
303 this.p2 = p2;
304 this.p3 = p3;
305 this.data = data;
306 }
307 }
308
309 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700310 * A request object to use for transmitting data to an ICC.
311 */
312 private static final class ManualNetworkSelectionArgument {
313 public OperatorInfo operatorInfo;
314 public boolean persistSelection;
315
316 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
317 this.operatorInfo = operatorInfo;
318 this.persistSelection = persistSelection;
319 }
320 }
321
322 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
324 * request after sending. The main thread will notify the request when it is complete.
325 */
326 private static final class MainThreadRequest {
327 /** The argument to use for the request */
328 public Object argument;
329 /** The result of the request that is run on the main thread */
330 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800331 // The subscriber id that this request applies to. Defaults to
332 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
333 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334
Nathan Harold92bed182018-10-12 18:16:49 -0700335 // In cases where subId is unavailable, the caller needs to specify the phone.
336 public Phone phone;
337
vagdevie435a3e2018-08-15 16:01:53 -0700338 public WorkSource workSource;
339
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340 public MainThreadRequest(Object argument) {
341 this.argument = argument;
342 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800343
Nathan Harold92bed182018-10-12 18:16:49 -0700344 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
345 this.argument = argument;
346 if (phone != null) {
347 this.phone = phone;
348 }
349 this.workSource = workSource;
350 }
351
vagdevie435a3e2018-08-15 16:01:53 -0700352 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800353 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800354 if (subId != null) {
355 this.subId = subId;
356 }
vagdevie435a3e2018-08-15 16:01:53 -0700357 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 }
360
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800361 private static final class IncomingThirdPartyCallArgs {
362 public final ComponentName component;
363 public final String callId;
364 public final String callerDisplayName;
365
366 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
367 String callerDisplayName) {
368 this.component = component;
369 this.callId = callId;
370 this.callerDisplayName = callerDisplayName;
371 }
372 }
373
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 /**
375 * A handler that processes messages on the main thread in the phone process. Since many
376 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
377 * inbound binder threads to the main thread in the phone process. The Binder thread
378 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
379 * on, which will be notified when the operation completes and will contain the result of the
380 * request.
381 *
382 * <p>If a MainThreadRequest object is provided in the msg.obj field,
383 * note that request.result must be set to something non-null for the calling thread to
384 * unblock.
385 */
386 private final class MainThreadHandler extends Handler {
387 @Override
388 public void handleMessage(Message msg) {
389 MainThreadRequest request;
390 Message onCompleted;
391 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800392 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700393 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800394 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395
396 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700397 case CMD_HANDLE_USSD_REQUEST: {
398 request = (MainThreadRequest) msg.obj;
399 final Phone phone = getPhoneFromRequest(request);
400 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
401 String ussdRequest = ussdObject.first;
402 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700403
Pengquan Meng0c05b502018-09-06 09:59:22 -0700404 if (!isUssdApiAllowed(request.subId)) {
405 // Carrier does not support use of this API, return failure.
406 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
407 UssdResponse response = new UssdResponse(ussdRequest, null);
408 Bundle returnData = new Bundle();
409 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
410 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700411
Pengquan Meng0c05b502018-09-06 09:59:22 -0700412 request.result = true;
413 notifyRequester(request);
414 return;
415 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700416
Pengquan Meng0c05b502018-09-06 09:59:22 -0700417 try {
418 request.result = phone != null
419 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
420 } catch (CallStateException cse) {
421 request.result = false;
422 }
423 // Wake up the requesting thread
424 notifyRequester(request);
425 break;
pkanwar32d516d2016-10-14 19:37:38 -0700426 }
427
Yorke Lee716f67e2015-06-17 15:39:16 -0700428 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700430 final Phone phone = getPhoneFromRequest(request);
431 request.result = phone != null ?
432 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
433 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700435 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700439 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800442 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700443 if (uiccCard == null) {
444 loge("iccTransmitApduLogicalChannel: No UICC");
445 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700446 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700447 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
449 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 iccArgument.channel, iccArgument.cla, iccArgument.command,
452 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700454 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 break;
456
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 ar = (AsyncResult) msg.obj;
459 request = (MainThreadRequest) ar.userObj;
460 if (ar.exception == null && ar.result != null) {
461 request.result = ar.result;
462 } else {
463 request.result = new IccIoResult(0x6F, 0, (byte[])null);
464 if (ar.result == null) {
465 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800466 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800468 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700469 } else {
470 loge("iccTransmitApduLogicalChannel: Unknown exception");
471 }
472 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700473 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 break;
475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
477 request = (MainThreadRequest) msg.obj;
478 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800479 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 if (uiccCard == null) {
481 loge("iccTransmitApduBasicChannel: No UICC");
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700483 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 } else {
485 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
486 request);
487 uiccCard.iccTransmitApduBasicChannel(
488 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
489 iccArgument.p3, iccArgument.data, onCompleted);
490 }
491 break;
492
493 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
494 ar = (AsyncResult) msg.obj;
495 request = (MainThreadRequest) ar.userObj;
496 if (ar.exception == null && ar.result != null) {
497 request.result = ar.result;
498 } else {
499 request.result = new IccIoResult(0x6F, 0, (byte[])null);
500 if (ar.result == null) {
501 loge("iccTransmitApduBasicChannel: Empty response");
502 } else if (ar.exception instanceof CommandException) {
503 loge("iccTransmitApduBasicChannel: CommandException: " +
504 ar.exception);
505 } else {
506 loge("iccTransmitApduBasicChannel: Unknown exception");
507 }
508 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700509 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700510 break;
511
512 case CMD_EXCHANGE_SIM_IO:
513 request = (MainThreadRequest) msg.obj;
514 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800515 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 if (uiccCard == null) {
517 loge("iccExchangeSimIO: No UICC");
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 } else {
521 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
522 request);
523 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
524 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
525 iccArgument.data, onCompleted);
526 }
527 break;
528
529 case EVENT_EXCHANGE_SIM_IO_DONE:
530 ar = (AsyncResult) msg.obj;
531 request = (MainThreadRequest) ar.userObj;
532 if (ar.exception == null && ar.result != null) {
533 request.result = ar.result;
534 } else {
535 request.result = new IccIoResult(0x6f, 0, (byte[])null);
536 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700537 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 break;
539
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 case CMD_SEND_ENVELOPE:
541 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800542 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 if (uiccCard == null) {
544 loge("sendEnvelopeWithStatus: No UICC");
545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700546 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 } else {
548 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
549 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
550 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800551 break;
552
553 case EVENT_SEND_ENVELOPE_DONE:
554 ar = (AsyncResult) msg.obj;
555 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700556 if (ar.exception == null && ar.result != null) {
557 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
560 if (ar.result == null) {
561 loge("sendEnvelopeWithStatus: Empty response");
562 } else if (ar.exception instanceof CommandException) {
563 loge("sendEnvelopeWithStatus: CommandException: " +
564 ar.exception);
565 } else {
566 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
567 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800568 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700569 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 break;
571
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 case CMD_OPEN_CHANNEL:
573 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800574 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800575 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 if (uiccCard == null) {
577 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800578 request.result = new IccOpenLogicalChannelResponse(-1,
579 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 } else {
582 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800583 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
584 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700585 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 break;
587
588 case EVENT_OPEN_CHANNEL_DONE:
589 ar = (AsyncResult) msg.obj;
590 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 int[] result = (int[]) ar.result;
594 int channelId = result[0];
595 byte[] selectResponse = null;
596 if (result.length > 1) {
597 selectResponse = new byte[result.length - 1];
598 for (int i = 1; i < result.length; ++i) {
599 selectResponse[i - 1] = (byte) result[i];
600 }
601 }
602 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700603 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 if (ar.result == null) {
606 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 if (ar.exception != null) {
609 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
610 }
611
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700612 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700613 if (ar.exception instanceof CommandException) {
614 CommandException.Error error =
615 ((CommandException) (ar.exception)).getCommandError();
616 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700618 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700619 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 }
621 }
622 openChannelResp = new IccOpenLogicalChannelResponse(
623 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700625 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700626 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 break;
628
629 case CMD_CLOSE_CHANNEL:
630 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800631 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 if (uiccCard == null) {
633 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900634 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 } else {
637 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
638 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
639 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 break;
641
642 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800643 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
644 break;
645
646 case CMD_NV_READ_ITEM:
647 request = (MainThreadRequest) msg.obj;
648 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800649 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
650 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800651 break;
652
653 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800659 request.result = "";
660 if (ar.result == null) {
661 loge("nvReadItem: Empty response");
662 } else if (ar.exception instanceof CommandException) {
663 loge("nvReadItem: CommandException: " +
664 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800666 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 }
668 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 break;
671
Jake Hambye994d462014-02-03 13:10:13 -0800672 case CMD_NV_WRITE_ITEM:
673 request = (MainThreadRequest) msg.obj;
674 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
675 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800676 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700677 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800678 break;
679
680 case EVENT_NV_WRITE_ITEM_DONE:
681 handleNullReturnEvent(msg, "nvWriteItem");
682 break;
683
684 case CMD_NV_WRITE_CDMA_PRL:
685 request = (MainThreadRequest) msg.obj;
686 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800687 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800688 break;
689
690 case EVENT_NV_WRITE_CDMA_PRL_DONE:
691 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
692 break;
693
chen xu1cc0abe2018-10-26 17:39:23 -0700694 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800695 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700696 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800697 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
chen xu1cc0abe2018-10-26 17:39:23 -0700700 case EVENT_RESET_MODEM_CONFIG_DONE:
701 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800702 break;
703
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 case CMD_GET_PREFERRED_NETWORK_TYPE:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700707 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800708 break;
709
710 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
711 ar = (AsyncResult) msg.obj;
712 request = (MainThreadRequest) ar.userObj;
713 if (ar.exception == null && ar.result != null) {
714 request.result = ar.result; // Integer
715 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800716 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 if (ar.result == null) {
718 loge("getPreferredNetworkType: Empty response");
719 } else if (ar.exception instanceof CommandException) {
720 loge("getPreferredNetworkType: CommandException: " +
721 ar.exception);
722 } else {
723 loge("getPreferredNetworkType: Unknown exception");
724 }
725 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700726 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 break;
728
729 case CMD_SET_PREFERRED_NETWORK_TYPE:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
732 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700733 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 break;
735
736 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
737 handleNullReturnEvent(msg, "setPreferredNetworkType");
738 break;
739
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000740 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
741 request = (MainThreadRequest)msg.obj;
742 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800743 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000744 break;
745
746 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
747 ar = (AsyncResult)msg.obj;
748 request = (MainThreadRequest)ar.userObj;
749 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700750 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000751 break;
752
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800753 case CMD_SET_VOICEMAIL_NUMBER:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
756 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800757 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
758 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800759 break;
760
761 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
762 handleNullReturnEvent(msg, "setVoicemailNumber");
763 break;
764
Stuart Scott54788802015-03-30 13:18:01 -0700765 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
768 request);
769 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
770 break;
771
772 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
773 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
774 break;
775
Shishir Agrawal302c8692015-06-19 13:49:39 -0700776 case CMD_PERFORM_NETWORK_SCAN:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
779 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
780 break;
781
782 case EVENT_PERFORM_NETWORK_SCAN_DONE:
783 ar = (AsyncResult) msg.obj;
784 request = (MainThreadRequest) ar.userObj;
785 CellNetworkScanResult cellScanResult;
786 if (ar.exception == null && ar.result != null) {
787 cellScanResult = new CellNetworkScanResult(
788 CellNetworkScanResult.STATUS_SUCCESS,
789 (List<OperatorInfo>) ar.result);
790 } else {
791 if (ar.result == null) {
792 loge("getCellNetworkScanResults: Empty response");
793 }
794 if (ar.exception != null) {
795 loge("getCellNetworkScanResults: Exception: " + ar.exception);
796 }
797 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
798 if (ar.exception instanceof CommandException) {
799 CommandException.Error error =
800 ((CommandException) (ar.exception)).getCommandError();
801 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
802 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
803 } else if (error == CommandException.Error.GENERIC_FAILURE) {
804 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
805 }
806 }
807 cellScanResult = new CellNetworkScanResult(errorCode, null);
808 }
809 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700810 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700811 break;
812
813 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
814 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700815 ManualNetworkSelectionArgument selArg =
816 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
818 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700819 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
820 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700821 break;
822
823 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700824 ar = (AsyncResult) msg.obj;
825 request = (MainThreadRequest) ar.userObj;
826 if (ar.exception == null) {
827 request.result = true;
828 } else {
829 request.result = false;
830 loge("setNetworkSelectionModeManual " + ar.exception);
831 }
832 notifyRequester(request);
833 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700836 case CMD_GET_MODEM_ACTIVITY_INFO:
837 request = (MainThreadRequest) msg.obj;
838 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisc56281c2019-04-03 14:18:34 -0700839 if (defaultPhone != null) {
840 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
841 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700842 break;
843
844 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
847 if (ar.exception == null && ar.result != null) {
848 request.result = ar.result;
849 } else {
850 if (ar.result == null) {
851 loge("queryModemActivityInfo: Empty response");
852 } else if (ar.exception instanceof CommandException) {
853 loge("queryModemActivityInfo: CommandException: " +
854 ar.exception);
855 } else {
856 loge("queryModemActivityInfo: Unknown exception");
857 }
858 }
Amit Mahajand4766222016-01-28 15:28:28 -0800859 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
860 if (request.result == null) {
861 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
862 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700863 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700864 break;
865
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 case CMD_SET_ALLOWED_CARRIERS:
867 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800868 CarrierRestrictionRules argument =
869 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700870 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800871 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700872 break;
873
874 case EVENT_SET_ALLOWED_CARRIERS_DONE:
875 ar = (AsyncResult) msg.obj;
876 request = (MainThreadRequest) ar.userObj;
877 if (ar.exception == null && ar.result != null) {
878 request.result = ar.result;
879 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800880 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
881 if (ar.exception instanceof CommandException) {
882 loge("setAllowedCarriers: CommandException: " + ar.exception);
883 CommandException.Error error =
884 ((CommandException) (ar.exception)).getCommandError();
885 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
886 request.result =
887 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
888 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 } else {
890 loge("setAllowedCarriers: Unknown exception");
891 }
892 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700893 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 break;
895
896 case CMD_GET_ALLOWED_CARRIERS:
897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800899 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700900 break;
901
902 case EVENT_GET_ALLOWED_CARRIERS_DONE:
903 ar = (AsyncResult) msg.obj;
904 request = (MainThreadRequest) ar.userObj;
905 if (ar.exception == null && ar.result != null) {
906 request.result = ar.result;
907 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800908 request.result = new IllegalStateException(
909 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 if (ar.result == null) {
911 loge("getAllowedCarriers: Empty response");
912 } else if (ar.exception instanceof CommandException) {
913 loge("getAllowedCarriers: CommandException: " +
914 ar.exception);
915 } else {
916 loge("getAllowedCarriers: Unknown exception");
917 }
918 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700919 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 break;
921
Nathan Haroldb3014052017-01-25 15:57:32 -0800922 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
923 ar = (AsyncResult) msg.obj;
924 request = (MainThreadRequest) ar.userObj;
925 if (ar.exception == null && ar.result != null) {
926 request.result = ar.result;
927 } else {
928 request.result = new IllegalArgumentException(
929 "Failed to retrieve Forbidden Plmns");
930 if (ar.result == null) {
931 loge("getForbiddenPlmns: Empty response");
932 } else {
933 loge("getForbiddenPlmns: Unknown exception");
934 }
935 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700936 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800937 break;
938
939 case CMD_GET_FORBIDDEN_PLMNS:
940 request = (MainThreadRequest) msg.obj;
941 uiccCard = getUiccCardFromRequest(request);
942 if (uiccCard == null) {
943 loge("getForbiddenPlmns() UiccCard is null");
944 request.result = new IllegalArgumentException(
945 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700946 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800947 break;
948 }
949 Integer appType = (Integer) request.argument;
950 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
951 if (uiccApp == null) {
952 loge("getForbiddenPlmns() no app with specified type -- "
953 + appType);
954 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700955 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800956 break;
957 } else {
958 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
959 + " specified type -- " + appType);
960 }
961 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
962 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
963 onCompleted);
964 break;
965
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000966 case CMD_SWITCH_SLOTS:
967 request = (MainThreadRequest) msg.obj;
968 int[] physicalSlots = (int[]) request.argument;
969 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
970 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
971 break;
972
973 case EVENT_SWITCH_SLOTS_DONE:
974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
976 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700977 notifyRequester(request);
978 break;
979 case CMD_GET_NETWORK_SELECTION_MODE:
980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
982 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
983 break;
984
985 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 if (ar.exception != null) {
989 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
990 } else {
991 int mode = ((int[]) ar.result)[0];
992 if (mode == 0) {
993 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
994 } else {
995 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
996 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000997 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700998 notifyRequester(request);
999 break;
1000 case CMD_GET_CDMA_ROAMING_MODE:
1001 request = (MainThreadRequest) msg.obj;
1002 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1003 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1004 break;
1005 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1006 ar = (AsyncResult) msg.obj;
1007 request = (MainThreadRequest) ar.userObj;
1008 if (ar.exception != null) {
1009 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1010 } else {
1011 request.result = ((int[]) ar.result)[0];
1012 }
1013 notifyRequester(request);
1014 break;
1015 case CMD_SET_CDMA_ROAMING_MODE:
1016 request = (MainThreadRequest) msg.obj;
1017 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1018 int mode = (int) request.argument;
1019 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1020 break;
1021 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1022 ar = (AsyncResult) msg.obj;
1023 request = (MainThreadRequest) ar.userObj;
1024 request.result = ar.exception == null;
1025 notifyRequester(request);
1026 break;
1027 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1030 int subscriptionMode = (int) request.argument;
1031 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1032 break;
1033 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
1036 request.result = ar.exception == null;
1037 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001038 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001039 case CMD_GET_ALL_CELL_INFO:
1040 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001041 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001042 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001043 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001044 case EVENT_GET_ALL_CELL_INFO_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001047 // If a timeout occurs, the response will be null
1048 request.result = (ar.exception == null && ar.result != null)
1049 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 synchronized (request) {
1051 request.notifyAll();
1052 }
1053 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001054 case CMD_REQUEST_CELL_INFO_UPDATE:
1055 request = (MainThreadRequest) msg.obj;
1056 request.phone.requestCellInfoUpdate(request.workSource,
1057 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1058 break;
1059 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1060 ar = (AsyncResult) msg.obj;
1061 request = (MainThreadRequest) ar.userObj;
1062 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1063 try {
1064 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001066 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1067 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001069 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001070 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001071 } else {
1072 // use the result as returned
1073 cb.onCellInfo((List<CellInfo>) ar.result);
1074 }
1075 } catch (RemoteException re) {
1076 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1077 }
1078 break;
1079 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001080 request = (MainThreadRequest) msg.obj;
1081 WorkSource ws = (WorkSource) request.argument;
1082 Phone phone = getPhoneFromRequest(request);
1083 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1084 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
1088 if (ar.exception == null) {
1089 request.result = ar.result;
1090 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001092 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1093 ? new CdmaCellLocation() : new GsmCellLocation();
1094 }
1095
1096 synchronized (request) {
1097 request.notifyAll();
1098 }
1099 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001100 case CMD_MODEM_REBOOT:
1101 request = (MainThreadRequest) msg.obj;
1102 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001103 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001104 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001105 case EVENT_CMD_MODEM_REBOOT_DONE:
1106 handleNullReturnEvent(msg, "rebootModem");
1107 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001108 case CMD_REQUEST_ENABLE_MODEM:
1109 request = (MainThreadRequest) msg.obj;
1110 boolean enable = (boolean) request.argument;
1111 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001112 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001113 PhoneConfigurationManager.getInstance()
1114 .enablePhone(request.phone, enable, onCompleted);
1115 break;
1116 case EVENT_ENABLE_MODEM_DONE:
1117 ar = (AsyncResult) msg.obj;
1118 request = (MainThreadRequest) ar.userObj;
1119 request.result = (ar.exception == null);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001120 //update the cache as modem status has changed
1121 mPhoneConfigurationManager.addToPhoneStatusCache(
1122 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001123 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001124 notifyRequester(request);
1125 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001126 default:
1127 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1128 break;
1129 }
1130 }
Jake Hambye994d462014-02-03 13:10:13 -08001131
Pengquan Meng0c05b502018-09-06 09:59:22 -07001132 private void notifyRequester(MainThreadRequest request) {
1133 synchronized (request) {
1134 request.notifyAll();
1135 }
1136 }
1137
Jake Hambye994d462014-02-03 13:10:13 -08001138 private void handleNullReturnEvent(Message msg, String command) {
1139 AsyncResult ar = (AsyncResult) msg.obj;
1140 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1141 if (ar.exception == null) {
1142 request.result = true;
1143 } else {
1144 request.result = false;
1145 if (ar.exception instanceof CommandException) {
1146 loge(command + ": CommandException: " + ar.exception);
1147 } else {
1148 loge(command + ": Unknown exception");
1149 }
1150 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001151 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001153 }
1154
1155 /**
1156 * Posts the specified command to be executed on the main thread,
1157 * waits for the request to complete, and returns the result.
1158 * @see #sendRequestAsync
1159 */
1160 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001161 return sendRequest(
1162 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001163 }
1164
1165 /**
1166 * Posts the specified command to be executed on the main thread,
1167 * waits for the request to complete, and returns the result.
1168 * @see #sendRequestAsync
1169 */
1170 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1171 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001172 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001173 }
1174
1175 /**
1176 * Posts the specified command to be executed on the main thread,
1177 * waits for the request to complete, and returns the result.
1178 * @see #sendRequestAsync
1179 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001180 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001181 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001182 }
1183
1184 /**
1185 * Posts the specified command to be executed on the main thread,
1186 * waits for the request to complete, and returns the result.
1187 * @see #sendRequestAsync
1188 */
Nathan Harold92bed182018-10-12 18:16:49 -07001189 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1190 return sendRequest(command, argument, subId, null, workSource);
1191 }
1192
1193 /**
1194 * Posts the specified command to be executed on the main thread,
1195 * waits for the request to complete, and returns the result.
1196 * @see #sendRequestAsync
1197 */
1198 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1199 return sendRequest(
1200 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1201 }
1202
1203 /**
1204 * Posts the specified command to be executed on the main thread,
1205 * waits for the request to complete, and returns the result.
1206 * @see #sendRequestAsync
1207 */
1208 private Object sendRequest(
1209 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001210 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1211 throw new RuntimeException("This method will deadlock if called from the main thread.");
1212 }
1213
Nathan Harold92bed182018-10-12 18:16:49 -07001214 MainThreadRequest request = null;
1215 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1216 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1217 } else if (phone != null) {
1218 request = new MainThreadRequest(argument, phone, workSource);
1219 } else {
1220 request = new MainThreadRequest(argument, subId, workSource);
1221 }
1222
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 Message msg = mMainThreadHandler.obtainMessage(command, request);
1224 msg.sendToTarget();
1225
1226 // Wait for the request to complete
1227 synchronized (request) {
1228 while (request.result == null) {
1229 try {
1230 request.wait();
1231 } catch (InterruptedException e) {
1232 // Do nothing, go back and wait until the request is complete
1233 }
1234 }
1235 }
1236 return request.result;
1237 }
1238
1239 /**
1240 * Asynchronous ("fire and forget") version of sendRequest():
1241 * Posts the specified command to be executed on the main thread, and
1242 * returns immediately.
1243 * @see #sendRequest
1244 */
1245 private void sendRequestAsync(int command) {
1246 mMainThreadHandler.sendEmptyMessage(command);
1247 }
1248
1249 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001250 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001251 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001252 */
1253 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001254 sendRequestAsync(command, argument, null, null);
1255 }
1256
1257 /**
1258 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1259 * @see {@link #sendRequest(int,Object)}
1260 */
1261 private void sendRequestAsync(
1262 int command, Object argument, Phone phone, WorkSource workSource) {
1263 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001264 Message msg = mMainThreadHandler.obtainMessage(command, request);
1265 msg.sendToTarget();
1266 }
1267
1268 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001269 * Initialize the singleton PhoneInterfaceManager instance.
1270 * This is only done once, at startup, from PhoneApp.onCreate().
1271 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001272 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 synchronized (PhoneInterfaceManager.class) {
1274 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001275 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 } else {
1277 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1278 }
1279 return sInstance;
1280 }
1281 }
1282
1283 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001284 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001287 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1289 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001290 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001291 mTelephonySharedPreferences =
1292 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001293 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001294 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001295
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001296 publish();
1297 }
1298
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001299 private Phone getDefaultPhone() {
1300 Phone thePhone = getPhone(getDefaultSubscription());
1301 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1302 }
1303
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 private void publish() {
1305 if (DBG) log("publish: " + this);
1306
1307 ServiceManager.addService("phone", this);
1308 }
1309
Stuart Scott584921c2015-01-15 17:10:34 -08001310 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001311 if (request.phone != null) {
1312 return request.phone;
1313 } else {
1314 return getPhoneFromSubId(request.subId);
1315 }
1316 }
1317
1318 private Phone getPhoneFromSubId(int subId) {
1319 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1320 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001321 }
1322
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001323 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1324 Phone phone = getPhoneFromRequest(request);
1325 return phone == null ? null :
1326 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1327 }
1328
Wink Saville36469e72014-06-11 15:17:00 -07001329 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001330 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001331 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333
1334 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001335 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001336 }
1337
Wink Savilleb564aae2014-10-23 10:18:09 -07001338 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 if (DBG) log("dial: " + number);
1340 // No permission check needed here: This is just a wrapper around the
1341 // ACTION_DIAL intent, which is available to any app since it puts up
1342 // the UI before it does anything.
1343
Malcolm Chend965c8b2018-02-28 15:00:40 -08001344 final long identity = Binder.clearCallingIdentity();
1345 try {
1346 String url = createTelUrl(number);
1347 if (url == null) {
1348 return;
1349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350
Malcolm Chend965c8b2018-02-28 15:00:40 -08001351 // PENDING: should we just silently fail if phone is offhook or ringing?
1352 PhoneConstants.State state = mCM.getState(subId);
1353 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1354 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1355 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1356 mApp.startActivity(intent);
1357 }
1358 } finally {
1359 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 }
1361 }
1362
1363 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001364 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001365 }
1366
Wink Savilleb564aae2014-10-23 10:18:09 -07001367 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 if (DBG) log("call: " + number);
1369
1370 // This is just a wrapper around the ACTION_CALL intent, but we still
1371 // need to do a permission check since we're calling startActivity()
1372 // from the context of the phone app.
1373 enforceCallPermission();
1374
1375 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1376 != AppOpsManager.MODE_ALLOWED) {
1377 return;
1378 }
1379
Malcolm Chend965c8b2018-02-28 15:00:40 -08001380 final long identity = Binder.clearCallingIdentity();
1381 try {
1382 String url = createTelUrl(number);
1383 if (url == null) {
1384 return;
1385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386
Malcolm Chend965c8b2018-02-28 15:00:40 -08001387 boolean isValid = false;
1388 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1389 if (slist != null) {
1390 for (SubscriptionInfo subInfoRecord : slist) {
1391 if (subInfoRecord.getSubscriptionId() == subId) {
1392 isValid = true;
1393 break;
1394 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001395 }
Wink Saville08874612014-08-31 19:19:58 -07001396 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001397 if (!isValid) {
1398 return;
1399 }
Wink Saville08874612014-08-31 19:19:58 -07001400
Malcolm Chend965c8b2018-02-28 15:00:40 -08001401 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1402 intent.putExtra(SUBSCRIPTION_KEY, subId);
1403 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1404 mApp.startActivity(intent);
1405 } finally {
1406 Binder.restoreCallingIdentity(identity);
1407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 }
1409
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001411 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001412 }
1413
Wink Savilleb564aae2014-10-23 10:18:09 -07001414 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001415 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001416 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1417 }
1418
1419 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001420 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001421 }
1422
Wink Savilleb564aae2014-10-23 10:18:09 -07001423 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001424 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001425 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1426 }
1427
1428 /** {@hide} */
1429 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001430 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001431 }
1432
Wink Savilleb564aae2014-10-23 10:18:09 -07001433 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001434 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001435
1436 final long identity = Binder.clearCallingIdentity();
1437 try {
1438 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1439 checkSimPin.start();
1440 return checkSimPin.unlockSim(null, pin);
1441 } finally {
1442 Binder.restoreCallingIdentity(identity);
1443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001444 }
1445
Wink Saville9de0f752013-10-22 19:04:03 -07001446 /** {@hide} */
1447 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001448 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001449 }
1450
Wink Savilleb564aae2014-10-23 10:18:09 -07001451 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001453
1454 final long identity = Binder.clearCallingIdentity();
1455 try {
1456 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1457 checkSimPuk.start();
1458 return checkSimPuk.unlockSim(puk, pin);
1459 } finally {
1460 Binder.restoreCallingIdentity(identity);
1461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 }
1463
1464 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001465 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 * a synchronous one.
1467 */
1468 private static class UnlockSim extends Thread {
1469
1470 private final IccCard mSimCard;
1471
1472 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001473 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1474 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475
1476 // For replies from SimCard interface
1477 private Handler mHandler;
1478
1479 // For async handler to identify request type
1480 private static final int SUPPLY_PIN_COMPLETE = 100;
1481
1482 public UnlockSim(IccCard simCard) {
1483 mSimCard = simCard;
1484 }
1485
1486 @Override
1487 public void run() {
1488 Looper.prepare();
1489 synchronized (UnlockSim.this) {
1490 mHandler = new Handler() {
1491 @Override
1492 public void handleMessage(Message msg) {
1493 AsyncResult ar = (AsyncResult) msg.obj;
1494 switch (msg.what) {
1495 case SUPPLY_PIN_COMPLETE:
1496 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1497 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001498 mRetryCount = msg.arg1;
1499 if (ar.exception != null) {
1500 if (ar.exception instanceof CommandException &&
1501 ((CommandException)(ar.exception)).getCommandError()
1502 == CommandException.Error.PASSWORD_INCORRECT) {
1503 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1504 } else {
1505 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1506 }
1507 } else {
1508 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 mDone = true;
1511 UnlockSim.this.notifyAll();
1512 }
1513 break;
1514 }
1515 }
1516 };
1517 UnlockSim.this.notifyAll();
1518 }
1519 Looper.loop();
1520 }
1521
1522 /*
1523 * Use PIN or PUK to unlock SIM card
1524 *
1525 * If PUK is null, unlock SIM card with PIN
1526 *
1527 * If PUK is not null, unlock SIM card with PUK and set PIN code
1528 */
Wink Saville9de0f752013-10-22 19:04:03 -07001529 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530
1531 while (mHandler == null) {
1532 try {
1533 wait();
1534 } catch (InterruptedException e) {
1535 Thread.currentThread().interrupt();
1536 }
1537 }
1538 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1539
1540 if (puk == null) {
1541 mSimCard.supplyPin(pin, callback);
1542 } else {
1543 mSimCard.supplyPuk(puk, pin, callback);
1544 }
1545
1546 while (!mDone) {
1547 try {
1548 Log.d(LOG_TAG, "wait for done");
1549 wait();
1550 } catch (InterruptedException e) {
1551 // Restore the interrupted status
1552 Thread.currentThread().interrupt();
1553 }
1554 }
1555 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001556 int[] resultArray = new int[2];
1557 resultArray[0] = mResult;
1558 resultArray[1] = mRetryCount;
1559 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 }
1561 }
1562
1563 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001564 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001565
1566 }
1567
Wink Savilleb564aae2014-10-23 10:18:09 -07001568 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 // No permission check needed here: this call is harmless, and it's
1570 // needed for the ServiceState.requestStateUpdate() call (which is
1571 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001572 final long identity = Binder.clearCallingIdentity();
1573 try {
1574 final Phone phone = getPhone(subId);
1575 if (phone != null) {
1576 phone.updateServiceLocation();
1577 }
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 }
1582
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001583 @Override
1584 public boolean isRadioOn(String callingPackage) {
1585 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001586 }
1587
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001588 @Override
1589 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001591 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001592 return false;
1593 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001594
1595 final long identity = Binder.clearCallingIdentity();
1596 try {
1597 return isRadioOnForSubscriber(subId);
1598 } finally {
1599 Binder.restoreCallingIdentity(identity);
1600 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001601 }
1602
1603 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001604 final long identity = Binder.clearCallingIdentity();
1605 try {
1606 final Phone phone = getPhone(subId);
1607 if (phone != null) {
1608 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1609 } else {
1610 return false;
1611 }
1612 } finally {
1613 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
1616
1617 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001618 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 }
Wink Saville36469e72014-06-11 15:17:00 -07001620
Wink Savilleb564aae2014-10-23 10:18:09 -07001621 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001623
1624 final long identity = Binder.clearCallingIdentity();
1625 try {
1626 final Phone phone = getPhone(subId);
1627 if (phone != null) {
1628 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1629 }
1630 } finally {
1631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001632 }
Wink Saville36469e72014-06-11 15:17:00 -07001633 }
1634
1635 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001636 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001637 }
1638
Wink Savilleb564aae2014-10-23 10:18:09 -07001639 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001640 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001641
1642 final long identity = Binder.clearCallingIdentity();
1643 try {
1644 final Phone phone = getPhone(subId);
1645 if (phone == null) {
1646 return false;
1647 }
1648 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1649 toggleRadioOnOffForSubscriber(subId);
1650 }
1651 return true;
1652 } finally {
1653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 }
Wink Saville36469e72014-06-11 15:17:00 -07001656
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001657 public boolean needMobileRadioShutdown() {
1658 /*
1659 * If any of the Radios are available, it will need to be
1660 * shutdown. So return true if any Radio is available.
1661 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1665 Phone phone = PhoneFactory.getPhone(i);
1666 if (phone != null && phone.isRadioAvailable()) return true;
1667 }
1668 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1669 return false;
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001672 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001673 }
1674
Malcolm Chend965c8b2018-02-28 15:00:40 -08001675 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001676 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001677 enforceModifyPermission();
1678
1679 final long identity = Binder.clearCallingIdentity();
1680 try {
1681 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1682 logv("Shutting down Phone " + i);
1683 shutdownRadioUsingPhoneId(i);
1684 }
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001687 }
1688 }
1689
1690 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001691 Phone phone = PhoneFactory.getPhone(phoneId);
1692 if (phone != null && phone.isRadioAvailable()) {
1693 phone.shutdownRadio();
1694 }
1695 }
1696
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001698 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001699
1700 final long identity = Binder.clearCallingIdentity();
1701 try {
1702 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1703 if (defaultPhone != null) {
1704 defaultPhone.setRadioPower(turnOn);
1705 return true;
1706 } else {
1707 loge("There's no default phone.");
1708 return false;
1709 }
1710 } finally {
1711 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001712 }
Wink Saville36469e72014-06-11 15:17:00 -07001713 }
1714
Wink Savilleb564aae2014-10-23 10:18:09 -07001715 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 final Phone phone = getPhone(subId);
1721 if (phone != null) {
1722 phone.setRadioPower(turnOn);
1723 return true;
1724 } else {
1725 return false;
1726 }
1727 } finally {
1728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 }
1731
Wink Saville36469e72014-06-11 15:17:00 -07001732 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 public boolean enableDataConnectivity() {
1735 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001736
1737 final long identity = Binder.clearCallingIdentity();
1738 try {
1739 int subId = mSubscriptionController.getDefaultDataSubId();
1740 final Phone phone = getPhone(subId);
1741 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001742 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001743 return true;
1744 } else {
1745 return false;
1746 }
1747 } finally {
1748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
1751
Wink Saville36469e72014-06-11 15:17:00 -07001752 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001753 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 public boolean disableDataConnectivity() {
1755 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 int subId = mSubscriptionController.getDefaultDataSubId();
1760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001762 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001763 return true;
1764 } else {
1765 return false;
1766 }
1767 } finally {
1768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001773 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001774 final long identity = Binder.clearCallingIdentity();
1775 try {
1776 final Phone phone = getPhone(subId);
1777 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001778 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001779 } else {
1780 return false;
1781 }
1782 } finally {
1783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
1787 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001788 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001789 }
1790
pkanwarae03a6b2016-11-06 20:37:09 -08001791 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001792 enforceCallPermission();
1793
1794 final long identity = Binder.clearCallingIdentity();
1795 try {
1796 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1797 return;
1798 }
1799 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1800 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1801 } finally {
1802 Binder.restoreCallingIdentity(identity);
1803 }
pkanwar32d516d2016-10-14 19:37:38 -07001804 };
1805
Wink Savilleb564aae2014-10-23 10:18:09 -07001806 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001808
1809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1812 return false;
1813 }
1814 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1815 } finally {
1816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 }
1819
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001821 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001822 }
1823
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001824 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001825 final long identity = Binder.clearCallingIdentity();
1826 try {
1827 Phone phone = PhoneFactory.getPhone(slotIndex);
1828 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1829 PhoneConstantConversions.convertCallState(phone.getState());
1830 } finally {
1831 Binder.restoreCallingIdentity(identity);
1832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 }
1834
Sanket Padawe356d7632015-06-22 14:03:32 -07001835 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001837 final long identity = Binder.clearCallingIdentity();
1838 try {
1839 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1840 if (phone != null) {
1841 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1842 } else {
1843 return PhoneConstantConversions.convertDataState(
1844 PhoneConstants.DataState.DISCONNECTED);
1845 }
1846 } finally {
1847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 }
1850
Sanket Padawe356d7632015-06-22 14:03:32 -07001851 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001852 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001853 final long identity = Binder.clearCallingIdentity();
1854 try {
1855 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1856 if (phone != null) {
1857 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1858 } else {
1859 return TelephonyManager.DATA_ACTIVITY_NONE;
1860 }
1861 } finally {
1862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 }
1865
1866 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001867 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001868 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001869 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001870
1871 LocationAccessPolicy.LocationPermissionResult locationResult =
1872 LocationAccessPolicy.checkLocationPermission(mApp,
1873 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1874 .setCallingPackage(callingPackage)
1875 .setCallingPid(Binder.getCallingPid())
1876 .setCallingUid(Binder.getCallingUid())
1877 .setMethod("getCellLocation")
1878 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1879 .build());
1880 switch (locationResult) {
1881 case DENIED_HARD:
1882 throw new SecurityException("Not allowed to access cell location");
1883 case DENIED_SOFT:
1884 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001887 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001888 final long identity = Binder.clearCallingIdentity();
1889 try {
1890 if (DBG_LOC) log("getCellLocation: is active user");
1891 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001892 int subId = mSubscriptionController.getDefaultDataSubId();
1893 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1894 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001895 return data;
1896 } finally {
1897 Binder.restoreCallingIdentity(identity);
1898 }
Svetoslav64fad262015-04-14 14:35:21 -07001899 }
1900
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001902 public String getNetworkCountryIsoForPhone(int phoneId) {
1903 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1904 // registered cell info, so return a NULL country instead.
1905 final long identity = Binder.clearCallingIdentity();
1906 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001907 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1908 // Get default phone in this case.
1909 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1910 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001911 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001912 // Todo: fix this when we can get the actual cellular network info when the device
1913 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001914 if (TelephonyManager.NETWORK_TYPE_IWLAN
1915 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1916 return "";
1917 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001918 Phone phone = PhoneFactory.getPhone(phoneId);
1919 if (phone != null) {
1920 ServiceStateTracker sst = phone.getServiceStateTracker();
1921 if (sst != null) {
1922 LocaleTracker lt = sst.getLocaleTracker();
1923 if (lt != null) {
1924 return lt.getCurrentCountry();
1925 }
1926 }
1927 }
1928 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001929 } finally {
1930 Binder.restoreCallingIdentity(identity);
1931 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001932 }
1933
1934 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001936 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001937 }
1938
Sanket Padawe356d7632015-06-22 14:03:32 -07001939 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001940 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 mApp.enforceCallingOrSelfPermission(
1942 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001943
1944 final long identity = Binder.clearCallingIdentity();
1945 try {
1946 final Phone phone = getPhone(subId);
1947 if (phone != null) {
1948 phone.enableLocationUpdates();
1949 }
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
1955 @Override
1956 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001957 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001958 }
1959
Sanket Padawe356d7632015-06-22 14:03:32 -07001960 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001961 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 mApp.enforceCallingOrSelfPermission(
1963 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001964
1965 final long identity = Binder.clearCallingIdentity();
1966 try {
1967 final Phone phone = getPhone(subId);
1968 if (phone != null) {
1969 phone.disableLocationUpdates();
1970 }
1971 } finally {
1972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Nathan Harold31d7ff32018-10-15 20:20:30 -07001976 /**
1977 * Returns the target SDK version number for a given package name.
1978 *
1979 * @return target SDK if the package is found or INT_MAX.
1980 */
1981 private int getTargetSdk(String packageName) {
1982 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001983 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1984 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001985 if (ai != null) return ai.targetSdkVersion;
1986 } catch (PackageManager.NameNotFoundException unexpected) {
1987 }
1988 return Integer.MAX_VALUE;
1989 }
1990
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 @Override
1992 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001993 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1994 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001995 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1996 throw new SecurityException(
1997 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1998 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001999
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2001 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2002 return null;
2003 }
Svetoslav64fad262015-04-14 14:35:21 -07002004
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002005 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006
Nathan Haroldf180aac2018-06-01 18:43:55 -07002007 List<CellInfo> info = getAllCellInfo(callingPackage);
2008 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009
Nathan Haroldf180aac2018-06-01 18:43:55 -07002010 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2011 for (CellInfo ci : info) {
2012 if (ci instanceof CellInfoGsm) {
2013 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2014 } else if (ci instanceof CellInfoWcdma) {
2015 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002018 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 }
2020
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002021 private List<CellInfo> getCachedCellInfo() {
2022 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2023 for (Phone phone : PhoneFactory.getPhones()) {
2024 List<CellInfo> info = phone.getAllCellInfo();
2025 if (info != null) cellInfos.addAll(info);
2026 }
2027 return cellInfos;
2028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029
2030 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002031 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002032 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002033 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002034
2035 LocationAccessPolicy.LocationPermissionResult locationResult =
2036 LocationAccessPolicy.checkLocationPermission(mApp,
2037 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2038 .setCallingPackage(callingPackage)
2039 .setCallingPid(Binder.getCallingPid())
2040 .setCallingUid(Binder.getCallingUid())
2041 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002042 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002043 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2044 .build());
2045 switch (locationResult) {
2046 case DENIED_HARD:
2047 throw new SecurityException("Not allowed to access cell info");
2048 case DENIED_SOFT:
2049 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050 }
2051
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002052 final int targetSdk = getTargetSdk(callingPackage);
2053 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2054 return getCachedCellInfo();
2055 }
2056
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002057 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002058 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002059 final long identity = Binder.clearCallingIdentity();
2060 try {
2061 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2062 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002063 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002064 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002065 if (info != null) cellInfos.addAll(info);
2066 }
2067 return cellInfos;
2068 } finally {
2069 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070 }
2071 }
2072
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002073 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002074 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2075 requestCellInfoUpdateInternal(
2076 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2077 }
2078
2079 @Override
2080 public void requestCellInfoUpdateWithWorkSource(
2081 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2082 enforceModifyPermission();
2083 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2084 }
2085
2086 private void requestCellInfoUpdateInternal(
2087 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002088 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002089 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002090
2091 LocationAccessPolicy.LocationPermissionResult locationResult =
2092 LocationAccessPolicy.checkLocationPermission(mApp,
2093 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2094 .setCallingPackage(callingPackage)
2095 .setCallingPid(Binder.getCallingPid())
2096 .setCallingUid(Binder.getCallingUid())
2097 .setMethod("requestCellInfoUpdate")
2098 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2099 .build());
2100 switch (locationResult) {
2101 case DENIED_HARD:
2102 throw new SecurityException("Not allowed to access cell info");
2103 case DENIED_SOFT:
2104 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002105 }
2106
2107 final Phone phone = getPhone(subId);
2108 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2109
2110 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2111 }
2112
2113 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002115 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002116 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002117
2118 final long identity = Binder.clearCallingIdentity();
2119 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002120 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002121 } finally {
2122 Binder.restoreCallingIdentity(identity);
2123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 }
2125
Shishir Agrawala9f32182016-04-12 12:00:16 -07002126 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002127 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002128 Phone phone = PhoneFactory.getPhone(slotIndex);
2129 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002130 return null;
2131 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002132 int subId = phone.getSubId();
2133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2134 mApp, subId, callingPackage, "getImeiForSlot")) {
2135 return null;
2136 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002137
2138 final long identity = Binder.clearCallingIdentity();
2139 try {
2140 return phone.getImei();
2141 } finally {
2142 Binder.restoreCallingIdentity(identity);
2143 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002144 }
2145
2146 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002147 public String getTypeAllocationCodeForSlot(int slotIndex) {
2148 Phone phone = PhoneFactory.getPhone(slotIndex);
2149 String tac = null;
2150 if (phone != null) {
2151 String imei = phone.getImei();
2152 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2153 }
2154 return tac;
2155 }
2156
2157 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002158 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002159 Phone phone = PhoneFactory.getPhone(slotIndex);
2160 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002161 return null;
2162 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002163
Jeff Davidson913390f2018-02-23 17:11:49 -08002164 int subId = phone.getSubId();
2165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2166 mApp, subId, callingPackage, "getMeidForSlot")) {
2167 return null;
2168 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002169
2170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 return phone.getMeid();
2173 } finally {
2174 Binder.restoreCallingIdentity(identity);
2175 }
Jack Yu2af8d712017-03-15 17:14:14 -07002176 }
2177
2178 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002179 public String getManufacturerCodeForSlot(int slotIndex) {
2180 Phone phone = PhoneFactory.getPhone(slotIndex);
2181 String manufacturerCode = null;
2182 if (phone != null) {
2183 String meid = phone.getMeid();
2184 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2185 }
2186 return manufacturerCode;
2187 }
2188
2189 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002190 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002191 Phone phone = PhoneFactory.getPhone(slotIndex);
2192 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002193 return null;
2194 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002195 int subId = phone.getSubId();
2196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2197 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2198 return null;
2199 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002200
2201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 return phone.getDeviceSvn();
2204 } finally {
2205 Binder.restoreCallingIdentity(identity);
2206 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002207 }
2208
fionaxu43304da2017-11-27 22:51:16 -08002209 @Override
2210 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002211 final long identity = Binder.clearCallingIdentity();
2212 try {
2213 final Phone phone = getPhone(subId);
2214 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2215 } finally {
2216 Binder.restoreCallingIdentity(identity);
2217 }
fionaxu43304da2017-11-27 22:51:16 -08002218 }
2219
2220 @Override
2221 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002222 final long identity = Binder.clearCallingIdentity();
2223 try {
2224 final Phone phone = getPhone(subId);
2225 return phone == null ? null : phone.getCarrierName();
2226 } finally {
2227 Binder.restoreCallingIdentity(identity);
2228 }
fionaxu43304da2017-11-27 22:51:16 -08002229 }
2230
calvinpaneed9ae82018-11-01 19:43:06 +08002231 @Override
chen xua31f22b2019-03-06 15:28:50 -08002232 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002233 final long identity = Binder.clearCallingIdentity();
2234 try {
2235 final Phone phone = getPhone(subId);
2236 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002237 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002238 } finally {
2239 Binder.restoreCallingIdentity(identity);
2240 }
2241 }
2242
2243 @Override
chen xua31f22b2019-03-06 15:28:50 -08002244 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002245 final long identity = Binder.clearCallingIdentity();
2246 try {
2247 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002248 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002249 } finally {
2250 Binder.restoreCallingIdentity(identity);
2251 }
2252 }
2253
chen xu02581692018-11-11 19:03:44 -08002254 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002255 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2256 if (!isSubscriptionMccMnc) {
2257 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2258 }
chen xu02581692018-11-11 19:03:44 -08002259 final Phone phone = PhoneFactory.getPhone(slotIndex);
2260 if (phone == null) {
2261 return TelephonyManager.UNKNOWN_CARRIER_ID;
2262 }
2263 final long identity = Binder.clearCallingIdentity();
2264 try {
2265 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2266 } finally {
2267 Binder.restoreCallingIdentity(identity);
2268 }
2269 }
2270
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 //
2272 // Internal helper methods.
2273 //
2274
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002275 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2277 *
2278 * @throws SecurityException if the caller does not have the required permission
2279 */
2280 private void enforceModifyPermission() {
2281 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2282 }
2283
2284 /**
2285 * Make sure the caller has the CALL_PHONE permission.
2286 *
2287 * @throws SecurityException if the caller does not have the required permission
2288 */
2289 private void enforceCallPermission() {
2290 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2291 }
2292
Stuart Scott8eef64f2015-04-08 15:13:54 -07002293 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002294 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002295 "ConnectivityService");
2296 }
2297
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 private String createTelUrl(String number) {
2299 if (TextUtils.isEmpty(number)) {
2300 return null;
2301 }
2302
Jake Hambye994d462014-02-03 13:10:13 -08002303 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 }
2305
Ihab Awadf9e92732013-12-05 18:02:52 -08002306 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2308 }
2309
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002310 private static void logv(String msg) {
2311 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2312 }
2313
Ihab Awadf9e92732013-12-05 18:02:52 -08002314 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2316 }
2317
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002318 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002320 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002321 }
2322
Sanket Padawe356d7632015-06-22 14:03:32 -07002323 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002324 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 final Phone phone = PhoneFactory.getPhone(slotIndex);
2328 if (phone == null) {
2329 return PhoneConstants.PHONE_TYPE_NONE;
2330 } else {
2331 return phone.getPhoneType();
2332 }
2333 } finally {
2334 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 }
2337
2338 /**
2339 * Returns the CDMA ERI icon index to display
2340 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002341 @Override
2342 public int getCdmaEriIconIndex(String callingPackage) {
2343 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002344 }
2345
Sanket Padawe356d7632015-06-22 14:03:32 -07002346 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002347 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002349 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002350 return -1;
2351 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002352
2353 final long identity = Binder.clearCallingIdentity();
2354 try {
2355 final Phone phone = getPhone(subId);
2356 if (phone != null) {
2357 return phone.getCdmaEriIconIndex();
2358 } else {
2359 return -1;
2360 }
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 }
2365
2366 /**
2367 * Returns the CDMA ERI icon mode,
2368 * 0 - ON
2369 * 1 - FLASHING
2370 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002371 @Override
2372 public int getCdmaEriIconMode(String callingPackage) {
2373 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002374 }
2375
Sanket Padawe356d7632015-06-22 14:03:32 -07002376 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002377 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002379 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002380 return -1;
2381 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002382
2383 final long identity = Binder.clearCallingIdentity();
2384 try {
2385 final Phone phone = getPhone(subId);
2386 if (phone != null) {
2387 return phone.getCdmaEriIconMode();
2388 } else {
2389 return -1;
2390 }
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 }
2395
2396 /**
2397 * Returns the CDMA ERI text,
2398 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002399 @Override
2400 public String getCdmaEriText(String callingPackage) {
2401 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002402 }
2403
Sanket Padawe356d7632015-06-22 14:03:32 -07002404 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002405 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002406 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002407 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002408 return null;
2409 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002410
2411 final long identity = Binder.clearCallingIdentity();
2412 try {
2413 final Phone phone = getPhone(subId);
2414 if (phone != null) {
2415 return phone.getCdmaEriText();
2416 } else {
2417 return null;
2418 }
2419 } finally {
2420 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 }
2423
2424 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002425 * Returns the CDMA MDN.
2426 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002427 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002428 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2430 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002431
2432 final long identity = Binder.clearCallingIdentity();
2433 try {
2434 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002435 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002436 return phone.getLine1Number();
2437 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002438 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002439 return null;
2440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002443 }
2444 }
2445
2446 /**
2447 * Returns the CDMA MIN.
2448 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002449 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002450 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2452 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002453
2454 final long identity = Binder.clearCallingIdentity();
2455 try {
2456 final Phone phone = getPhone(subId);
2457 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2458 return phone.getCdmaMin();
2459 } else {
2460 return null;
2461 }
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002464 }
2465 }
2466
Hall Liud892bec2018-11-30 14:51:45 -08002467 @Override
2468 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2469 INumberVerificationCallback callback, String callingPackage) {
2470 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2471 != PERMISSION_GRANTED) {
2472 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2473 }
2474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2475
2476 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2477 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2478 throw new SecurityException("Calling package must be configured in the device config");
2479 }
2480
2481 if (range == null) {
2482 throw new NullPointerException("Range must be non-null");
2483 }
2484
2485 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002486 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002487
2488 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2489 }
2490
Junda Liuca05d5d2014-08-14 22:36:34 -07002491 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 * Returns true if CDMA provisioning needs to run.
2493 */
2494 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002495 final long identity = Binder.clearCallingIdentity();
2496 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002497 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002498 } finally {
2499 Binder.restoreCallingIdentity(identity);
2500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
2503 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002504 * Sets the voice mail number of a given subId.
2505 */
2506 @Override
2507 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002508 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002509
2510 final long identity = Binder.clearCallingIdentity();
2511 try {
2512 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2513 new Pair<String, String>(alphaTag, number), new Integer(subId));
2514 return success;
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002518 }
2519
Ta-wei Yen87c49842016-05-13 21:19:52 -07002520 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002521 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2522 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002523 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002524 if (!TextUtils.equals(callingPackage, systemDialer)) {
2525 throw new SecurityException("caller must be system dialer");
2526 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002527
2528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2531 if (phoneAccountHandle == null) {
2532 return null;
2533 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002534 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002535 } finally {
2536 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002537 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002538 }
2539
2540 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002541 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002544 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002545 return null;
2546 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002547
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002548 final long identity = Binder.clearCallingIdentity();
2549 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002550 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002551 } finally {
2552 Binder.restoreCallingIdentity(identity);
2553 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002554 }
2555
2556 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002557 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2558 VisualVoicemailSmsFilterSettings settings) {
2559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002560
2561 final long identity = Binder.clearCallingIdentity();
2562 try {
2563 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002564 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002568 }
2569
2570 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002571 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2572 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002577 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002578 } finally {
2579 Binder.restoreCallingIdentity(identity);
2580 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002581 }
2582
2583 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002584 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2585 String callingPackage, int subId) {
2586 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002587
2588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002591 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002592 } finally {
2593 Binder.restoreCallingIdentity(identity);
2594 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002595 }
2596
2597 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002598 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002599 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002600
2601 final long identity = Binder.clearCallingIdentity();
2602 try {
2603 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002604 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002605 } finally {
2606 Binder.restoreCallingIdentity(identity);
2607 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002608 }
2609
2610 @Override
2611 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2612 String number, int port, String text, PendingIntent sentIntent) {
2613 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002614 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002615 enforceSendSmsPermission();
2616 // Make the calls as the phone process.
2617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2620 if (port == 0) {
2621 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2622 sentIntent, null, false);
2623 } else {
2624 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2625 smsManager.sendDataMessageWithSelfPermissions(number, null,
2626 (short) port, data, sentIntent, null);
2627 }
2628 } finally {
2629 Binder.restoreCallingIdentity(identity);
2630 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002631 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002632 /**
fionaxu0152e512016-11-14 13:36:14 -08002633 * Sets the voice activation state of a given subId.
2634 */
2635 @Override
2636 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2638 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002639
2640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
2643 if (phone != null) {
2644 phone.setVoiceActivationState(activationState);
2645 } else {
2646 loge("setVoiceActivationState fails with invalid subId: " + subId);
2647 }
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002650 }
2651 }
2652
2653 /**
2654 * Sets the data activation state of a given subId.
2655 */
2656 @Override
2657 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2659 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002660
2661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 final Phone phone = getPhone(subId);
2664 if (phone != null) {
2665 phone.setDataActivationState(activationState);
2666 } else {
2667 loge("setVoiceActivationState fails with invalid subId: " + subId);
2668 }
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002671 }
2672 }
2673
2674 /**
2675 * Returns the voice activation state of a given subId.
2676 */
2677 @Override
2678 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002679 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002680
fionaxu0152e512016-11-14 13:36:14 -08002681 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 if (phone != null) {
2685 return phone.getVoiceActivationState();
2686 } else {
2687 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002691 }
2692 }
2693
2694 /**
2695 * Returns the data activation state of a given subId.
2696 */
2697 @Override
2698 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002699 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002700
fionaxu0152e512016-11-14 13:36:14 -08002701 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 if (phone != null) {
2705 return phone.getDataActivationState();
2706 } else {
2707 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2708 }
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002711 }
2712 }
2713
2714 /**
Wink Saville36469e72014-06-11 15:17:00 -07002715 * Returns the unread count of voicemails for a subId
2716 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002717 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002718 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2720 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2721 return 0;
2722 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 final Phone phone = getPhone(subId);
2726 if (phone != null) {
2727 return phone.getVoiceMessageCount();
2728 } else {
2729 return 0;
2730 }
2731 } finally {
2732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 }
2735
2736 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002737 * returns true, if the device is in a state where both voice and data
2738 * are supported simultaneously. This can change based on location or network condition.
2739 */
2740 @Override
2741 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 final Phone phone = getPhone(subId);
2745 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2746 } finally {
2747 Binder.restoreCallingIdentity(identity);
2748 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002749 }
2750
2751 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002752 * Send the dialer code if called from the current default dialer or the caller has
2753 * carrier privilege.
2754 * @param inputCode The dialer code to send
2755 */
2756 @Override
2757 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002758 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002759 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002760 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2761 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002762 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002763 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2764 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002765 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002766
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002769 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002770 } finally {
2771 Binder.restoreCallingIdentity(identity);
2772 }
fionaxu235cc5e2017-03-06 22:25:57 -08002773 }
2774
2775 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002776 * Returns the data network type.
2777 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 *
2779 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2780 */
2781 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002782 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 final Phone phone = getPhone(getDefaultSubscription());
2786 if (phone != null) {
2787 return phone.getServiceState().getDataNetworkType();
2788 } else {
2789 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2790 }
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002793 }
Wink Saville36469e72014-06-11 15:17:00 -07002794 }
2795
Pengquan Meng0c05b502018-09-06 09:59:22 -07002796 @Override
2797 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002798 if (!isActiveSubscription(subId)) {
2799 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2800 }
2801
Pengquan Meng0c05b502018-09-06 09:59:22 -07002802 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2803 }
2804
Brad Ebinger4c460712018-10-01 10:40:55 -07002805 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002806 public boolean isInEmergencySmsMode() {
2807 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 for (Phone phone : PhoneFactory.getPhones()) {
2811 if (phone.isInEmergencySmsMode()) {
2812 return true;
2813 }
2814 }
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
2818 return false;
2819 }
2820
2821 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002822 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2823 throws RemoteException {
2824 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002825 final long token = Binder.clearCallingIdentity();
2826 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002828 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002829 .addRegistrationCallbackForSubscription(c, subId);
2830 } finally {
2831 Binder.restoreCallingIdentity(token);
2832 }
2833 }
2834
2835 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002836 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2837 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002838 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2839 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2840 }
2841 Binder.withCleanCallingIdentity(() -> {
2842 try {
2843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002844 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002845 .removeRegistrationCallbackForSubscription(c, subId);
2846 } catch (IllegalArgumentException e) {
2847 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2848 + "is inactive, ignoring unregister.");
2849 // If the subscription is no longer active, just return, since the callback
2850 // will already have been removed internally.
2851 }
2852 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002853 }
2854
2855 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002856 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2857 throws RemoteException {
2858 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2860 final long token = Binder.clearCallingIdentity();
2861 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002862 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002863 .addCapabilitiesCallbackForSubscription(c, subId);
2864 } finally {
2865 Binder.restoreCallingIdentity(token);
2866 }
2867 }
2868
2869 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002870 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2871 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002872
2873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2875 }
2876 Binder.withCleanCallingIdentity(() -> {
2877 try {
2878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002879 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002880 .removeCapabilitiesCallbackForSubscription(c, subId);
2881 } catch (IllegalArgumentException e) {
2882 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2883 + "is inactive, ignoring unregister.");
2884 // If the subscription is no longer active, just return, since the callback
2885 // will already have been removed internally.
2886 }
2887 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002888 }
2889
2890 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002891 public boolean isCapable(int subId, int capability, int regTech) {
2892 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2894 final long token = Binder.clearCallingIdentity();
2895 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002896 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002897 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2898 } catch (ImsException e) {
2899 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2900 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002901 } catch (IllegalArgumentException e) {
2902 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2903 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002904 } finally {
2905 Binder.restoreCallingIdentity(token);
2906 }
2907 }
2908
2909 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002910 public boolean isAvailable(int subId, int capability, int regTech) {
2911 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002912 final long token = Binder.clearCallingIdentity();
2913 try {
2914 Phone phone = getPhone(subId);
2915 if (phone == null) return false;
2916 return phone.isImsCapabilityAvailable(capability, regTech);
2917 } finally {
2918 Binder.restoreCallingIdentity(token);
2919 }
2920 }
2921
2922 @Override
2923 public boolean isAdvancedCallingSettingEnabled(int subId) {
2924 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2926 final long token = Binder.clearCallingIdentity();
2927 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002928 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002929 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2930 } finally {
2931 Binder.restoreCallingIdentity(token);
2932 }
2933 }
2934
2935 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002936 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002938 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002942 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002943 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
2947 }
2948
2949 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002950 public boolean isVtSettingEnabled(int subId) {
2951 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002955 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002956 getSlotIndexOrException(subId)).isVtEnabledByUser();
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
2959 }
2960 }
2961
2962 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002963 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002965 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002966 final long identity = Binder.clearCallingIdentity();
2967 try {
2968 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002969 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002970 } finally {
2971 Binder.restoreCallingIdentity(identity);
2972 }
2973 }
2974
2975 @Override
2976 public boolean isVoWiFiSettingEnabled(int subId) {
2977 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002981 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002982 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
2986 }
2987
2988 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002989 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002991 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002995 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
2999 }
3000
3001 @Override
3002 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3003 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003007 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003008 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
3012 }
3013
3014 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003015 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003017 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003021 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003022 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
3026 }
3027
3028 @Override
3029 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3031 "setVoWiFiNonPersistent");
3032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003035 boolean isRoaming = TelephonyManager.from(
3036 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003037 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003038 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
3042 }
3043
3044 @Override
3045 public int getVoWiFiModeSetting(int subId) {
3046 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003050 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003051 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
3055 }
3056
3057 @Override
3058 public void setVoWiFiModeSetting(int subId, int mode) {
3059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3060 "setVoWiFiModeSetting");
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003064 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003065 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
3069 }
3070
3071 @Override
3072 public int getVoWiFiRoamingModeSetting(int subId) {
3073 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003077 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003078 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
3082 }
3083
3084 @Override
3085 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3087 "setVoWiFiRoamingModeSetting");
3088 final long identity = Binder.clearCallingIdentity();
3089 try {
3090 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003091 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003092 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
3096 }
3097
3098 @Override
3099 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3101 "setRttCapabilityEnabled");
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003105 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003106 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
3110 }
3111
3112 @Override
3113 public boolean isTtyOverVolteEnabled(int subId) {
3114 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003118 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003119 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
3123 }
3124
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003125 @Override
3126 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3127 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003131 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003132 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
3136 }
3137
3138 @Override
3139 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3140 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3141 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003142 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3143 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3144 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003145 try {
3146 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003147 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003148 .removeProvisioningCallbackForSubscription(callback, subId);
3149 } catch (IllegalArgumentException e) {
3150 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3151 + "is inactive, ignoring unregister.");
3152 // If the subscription is no longer active, just return, since the callback will already
3153 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
3157 }
3158
3159 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003160 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3161 boolean isProvisioned) {
3162 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3163 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3164 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3165 }
3166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3167 "setProvisioningStatusForCapability");
3168 final long identity = Binder.clearCallingIdentity();
3169 try {
3170 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3171 Phone phone = getPhone(subId);
3172 if (phone == null) {
3173 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3174 + subId);
3175 return;
3176 }
3177 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3178 return;
3179 }
3180
3181 // this capability requires provisioning, route to the correct API.
3182 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3183 switch (capability) {
3184 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3185 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3186 ims.setVolteProvisioned(isProvisioned);
3187 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3188 ims.setWfcProvisioned(isProvisioned);
3189 }
3190 break;
3191 }
3192 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3193 // There is currently no difference in VT provisioning type.
3194 ims.setVtProvisioned(isProvisioned);
3195 break;
3196 }
3197 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3198 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3199 // change the capability of the feature instead if needed.
3200 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3201 == isProvisioned) {
3202 // No change in provisioning.
3203 return;
3204 }
3205 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3206 try {
3207 ims.changeMmTelCapability(capability, tech, isProvisioned);
3208 } catch (ImsException e) {
3209 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3210 + ", Exception" + e.getMessage());
3211 }
3212 break;
3213 }
3214 default: {
3215 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3216 + capability + "', which does not require provisioning.");
3217 }
3218 }
3219
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
3223 }
3224
3225 @Override
3226 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3227 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3228 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3229 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3230 }
3231 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3235 Phone phone = getPhone(subId);
3236 if (phone == null) {
3237 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3238 + subId);
3239 // We will fail with "true" as the provisioning status because this is the default
3240 // if we do not require provisioning.
3241 return true;
3242 }
3243
3244 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3245 return true;
3246 }
3247
3248 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3249 switch (capability) {
3250 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3251 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3252 return ims.isVolteProvisionedOnDevice();
3253 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3254 return ims.isWfcProvisionedOnDevice();
3255 }
3256 // This should never happen, since we are checking tech above to make sure it
3257 // is either LTE or IWLAN.
3258 throw new IllegalArgumentException("Invalid radio technology for voice "
3259 + "capability.");
3260 }
3261 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3262 // There is currently no difference in VT provisioning type.
3263 return ims.isVtProvisionedOnDevice();
3264 }
3265 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3266 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3267 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3268 }
3269 default: {
3270 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3271 + capability + "', which does not require provisioning.");
3272 }
3273 }
3274
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
3278 }
3279
3280 @Override
3281 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3282 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3283 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3284 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3285 }
3286 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3287 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3288 return (provisionedBits & capability) > 0;
3289 }
3290
3291 @Override
3292 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3293 boolean isProvisioned) {
3294 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3295 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3296 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3297 }
3298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3299 "setProvisioningStatusForCapability");
3300 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3301 // If the current provisioning status for capability already matches isProvisioned,
3302 // do nothing.
3303 if (((provisionedBits & capability) > 0) == isProvisioned) {
3304 return;
3305 }
3306 if (isProvisioned) {
3307 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3308 } else {
3309 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3310 }
3311 }
3312
3313 /**
3314 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3315 * technology. The bitfield should mirror the bitfield defined by
3316 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3317 */
3318 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3319 String key = getMmTelProvisioningKey(subId, tech);
3320 // Default is no capabilities are provisioned.
3321 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3322 }
3323
3324 /**
3325 * Sets the MmTel capability provisioning bitfield (defined by
3326 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3327 * technology specified.
3328 *
3329 * Note: This is a synchronous command and should not be called on UI thread.
3330 */
3331 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3332 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3333 String key = getMmTelProvisioningKey(subId, tech);
3334 editor.putInt(key, newField);
3335 editor.commit();
3336 }
3337
3338 private static String getMmTelProvisioningKey(int subId, int tech) {
3339 // resulting key is provision_ims_mmtel_{subId}_{tech}
3340 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3341 }
3342
3343 /**
3344 * Query CarrierConfig to see if the specified capability requires provisioning for the
3345 * carrier associated with the subscription id.
3346 */
3347 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3348 int capability) {
3349 CarrierConfigManager configManager = new CarrierConfigManager(context);
3350 PersistableBundle c = configManager.getConfigForSubId(subId);
3351 boolean requireUtProvisioning = c.getBoolean(
3352 // By default, this config is true (even if there is no SIM). We also check to make
3353 // sure the subscription needs provisioning here, so we do not need to check for
3354 // the no-SIM case, where we would normally shortcut this to false.
3355 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3356 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3357 false);
3358 boolean requireVoiceVtProvisioning = c.getBoolean(
3359 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3360
3361 // First check to make sure that the capability requires provisioning.
3362 switch (capability) {
3363 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3364 // intentional fallthrough
3365 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3366 if (requireVoiceVtProvisioning) {
3367 // Voice and Video requires provisioning
3368 return true;
3369 }
3370 break;
3371 }
3372 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3373 if (requireUtProvisioning) {
3374 // UT requires provisioning
3375 return true;
3376 }
3377 break;
3378 }
3379 }
3380 return false;
3381 }
3382
3383 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003384 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003385 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3386 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3387 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003388 enforceReadPrivilegedPermission("getImsProvisioningInt");
3389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003392 int slotId = getSlotIndex(subId);
3393 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3394 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3395 + subId + "' for key:" + key);
3396 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3397 }
3398 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003399 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003400 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3401 + subId + "' for key:" + key);
3402 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
3406 }
3407
3408 @Override
3409 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003410 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3411 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3412 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003413 enforceReadPrivilegedPermission("getImsProvisioningString");
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003417 int slotId = getSlotIndex(subId);
3418 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3419 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3420 + subId + "' for key:" + key);
3421 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3422 }
3423 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003425 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3426 + subId + "' for key:" + key);
3427 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
3431 }
3432
3433 @Override
3434 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003435 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3436 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3437 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3439 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003443 int slotId = getSlotIndex(subId);
3444 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3445 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3446 + subId + "' for key:" + key);
3447 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3448 }
3449 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003450 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003451 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3452 + "' for key:" + key);
3453 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003454 } finally {
3455 Binder.restoreCallingIdentity(identity);
3456 }
3457 }
3458
3459 @Override
3460 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003461 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3462 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3463 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3465 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003469 int slotId = getSlotIndex(subId);
3470 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3471 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3472 + subId + "' for key:" + key);
3473 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3474 }
3475 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003476 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003477 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3478 + "' for key:" + key);
3479 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003480 } finally {
3481 Binder.restoreCallingIdentity(identity);
3482 }
3483 }
3484
Brad Ebinger4c460712018-10-01 10:40:55 -07003485 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3486 int slotId = SubscriptionManager.getSlotIndex(subId);
3487 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003488 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003489 }
3490 return slotId;
3491 }
3492
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003493 private int getSlotIndex(int subId) {
3494 int slotId = SubscriptionManager.getSlotIndex(subId);
3495 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3496 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3497 }
3498 return slotId;
3499 }
3500
Wink Saville36469e72014-06-11 15:17:00 -07003501 /**
3502 * Returns the network type for a subId
3503 */
3504 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003505 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003507 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003508 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3509 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003510
Malcolm Chend965c8b2018-02-28 15:00:40 -08003511 final long identity = Binder.clearCallingIdentity();
3512 try {
3513 final Phone phone = getPhone(subId);
3514 if (phone != null) {
3515 return phone.getServiceState().getDataNetworkType();
3516 } else {
3517 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3518 }
3519 } finally {
3520 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522 }
3523
3524 /**
3525 * Returns the data network type
3526 */
3527 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003528 public int getDataNetworkType(String callingPackage) {
3529 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003530 }
3531
3532 /**
3533 * Returns the data network type for a subId
3534 */
3535 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003536 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003538 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003539 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3540 }
3541
Malcolm Chend965c8b2018-02-28 15:00:40 -08003542 final long identity = Binder.clearCallingIdentity();
3543 try {
3544 final Phone phone = getPhone(subId);
3545 if (phone != null) {
3546 return phone.getServiceState().getDataNetworkType();
3547 } else {
3548 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3549 }
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003553 }
3554
3555 /**
Wink Saville36469e72014-06-11 15:17:00 -07003556 * Returns the Voice network type for a subId
3557 */
3558 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003559 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003561 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003562 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3563 }
3564
Malcolm Chend965c8b2018-02-28 15:00:40 -08003565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 final Phone phone = getPhone(subId);
3568 if (phone != null) {
3569 return phone.getServiceState().getVoiceNetworkType();
3570 } else {
3571 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3572 }
3573 } finally {
3574 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003576 }
3577
3578 /**
3579 * @return true if a ICC card is present
3580 */
3581 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003582 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003583 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3584 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003585 }
3586
3587 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003588 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003589 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003590 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003591 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 final Phone phone = PhoneFactory.getPhone(slotIndex);
3595 if (phone != null) {
3596 return phone.getIccCard().hasIccCard();
3597 } else {
3598 return false;
3599 }
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003603 }
3604
3605 /**
3606 * Return if the current radio is LTE on CDMA. This
3607 * is a tri-state return value as for a period of time
3608 * the mode may be unknown.
3609 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003610 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003611 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003612 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003613 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003614 @Override
3615 public int getLteOnCdmaMode(String callingPackage) {
3616 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003617 }
3618
Sanket Padawe356d7632015-06-22 14:03:32 -07003619 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003620 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003622 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003623 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3624 }
3625
Malcolm Chend965c8b2018-02-28 15:00:40 -08003626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 final Phone phone = getPhone(subId);
3629 if (phone == null) {
3630 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3631 } else {
3632 return phone.getLteOnCdmaMode();
3633 }
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003636 }
Wink Saville36469e72014-06-11 15:17:00 -07003637 }
3638
Wink Saville36469e72014-06-11 15:17:00 -07003639 /**
3640 * {@hide}
3641 * Returns Default subId, 0 in the case of single standby.
3642 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003643 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003644 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003645 }
3646
Shishir Agrawala9f32182016-04-12 12:00:16 -07003647 private int getSlotForDefaultSubscription() {
3648 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3649 }
3650
Wink Savilleb564aae2014-10-23 10:18:09 -07003651 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003652 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003653 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003654
Pengquan Meng466e2482018-09-21 15:54:48 -07003655 private boolean isActiveSubscription(int subId) {
3656 return mSubscriptionController.isActiveSubId(subId);
3657 }
3658
Ihab Awadf2177b72013-11-25 13:33:23 -08003659 /**
3660 * @see android.telephony.TelephonyManager.WifiCallingChoices
3661 */
3662 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003663 final long identity = Binder.clearCallingIdentity();
3664 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003665 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003666 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3667 getWhenToMakeWifiCallsDefaultPreference());
3668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003671 }
3672
3673 /**
3674 * @see android.telephony.TelephonyManager.WifiCallingChoices
3675 */
3676 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003680 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003681 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003685 }
3686
Sailesh Nepald1e68152013-12-12 19:08:02 -08003687 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003688 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003689 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003690 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003691
Jordan Liu73b078d2019-02-28 12:03:40 -08003692 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3693 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3694 if (phoneId == -1) {
3695 throw new IllegalArgumentException("Given slot index: " + slotIndex
3696 + " does not correspond to an active phone");
3697 }
3698 return PhoneFactory.getPhone(phoneId);
3699 }
3700
Shishir Agrawal566b7612013-10-28 14:41:00 -07003701 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003702 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3703 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3705 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003707 if (DBG) {
3708 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3709 }
3710 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3711 p2);
3712 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003713
Jordan Liu73b078d2019-02-28 12:03:40 -08003714
3715 @Override
3716 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3717 int slotIndex, String callingPackage, String aid, int p2) {
3718 enforceModifyPermission();
3719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3720 if (DBG) {
3721 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3722 }
3723 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3724 callingPackage, aid, p2);
3725 }
3726
3727 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3728 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003729 final long identity = Binder.clearCallingIdentity();
3730 try {
3731 if (TextUtils.equals(ISDR_AID, aid)) {
3732 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003733 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3734 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003735 if (bestComponent == null
3736 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3737 loge("The calling package is not allowed to access ISD-R.");
3738 throw new SecurityException(
3739 "The calling package is not allowed to access ISD-R.");
3740 }
Derek Tan740e1672017-06-27 14:56:27 -07003741 }
Derek Tan740e1672017-06-27 14:56:27 -07003742
Malcolm Chend965c8b2018-02-28 15:00:40 -08003743 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003744 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3745 null /* workSource */);
3746 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003747 return response;
3748 } finally {
3749 Binder.restoreCallingIdentity(identity);
3750 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003751 }
3752
3753 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003754 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3756 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003757 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3758 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3759 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003760
Jordan Liu73b078d2019-02-28 12:03:40 -08003761 @Override
3762 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3763 enforceModifyPermission();
3764 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3765 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3766 channel);
3767 }
3768
3769 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003770 final long identity = Binder.clearCallingIdentity();
3771 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003772 if (channel < 0) {
3773 return false;
3774 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003775 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3776 null /* workSource */);
3777 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003778 return success;
3779 } finally {
3780 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003781 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003782 }
3783
3784 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003785 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003786 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3788 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003789 if (DBG) {
3790 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3791 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3792 + p3 + " data=" + data);
3793 }
3794 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3795 command, p1, p2, p3, data);
3796 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003797
Jordan Liu73b078d2019-02-28 12:03:40 -08003798 @Override
3799 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3800 int command, int p1, int p2, int p3, String data) {
3801 enforceModifyPermission();
3802 if (DBG) {
3803 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3804 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3805 + p3 + " data=" + data);
3806 }
3807 return iccTransmitApduLogicalChannelWithPermission(
3808 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3809 data);
3810 }
3811
3812 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3813 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003816 if (channel < 0) {
3817 return "";
3818 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003819
Malcolm Chend965c8b2018-02-28 15:00:40 -08003820 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003821 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3822 null /* workSource */);
3823 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003824
Malcolm Chend965c8b2018-02-28 15:00:40 -08003825 // Append the returned status code to the end of the response payload.
3826 String s = Integer.toHexString(
3827 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3828 if (response.payload != null) {
3829 s = IccUtils.bytesToHexString(response.payload) + s;
3830 }
3831 return s;
3832 } finally {
3833 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003834 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003835 }
Jake Hambye994d462014-02-03 13:10:13 -08003836
Evan Charltonc66da362014-05-16 14:06:40 -07003837 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003838 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3839 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3841 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003842 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003843 if (DBG) {
3844 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3845 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3846 }
3847 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3848 cla, command, p1, p2, p3, data);
3849 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003850
Jordan Liu73b078d2019-02-28 12:03:40 -08003851 @Override
3852 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3853 int command, int p1, int p2, int p3, String data) {
3854 enforceModifyPermission();
3855 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3856 if (DBG) {
3857 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3858 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3859 + " data=" + data);
3860 }
3861
3862 return iccTransmitApduBasicChannelWithPermission(
3863 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3864 p2, p3, data);
3865 }
3866
3867 // open APDU basic channel assuming the caller has sufficient permissions
3868 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3869 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3873 && TextUtils.equals(ISDR_AID, data)) {
3874 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003875 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3876 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003877 if (bestComponent == null
3878 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3879 loge("The calling package is not allowed to select ISD-R.");
3880 throw new SecurityException(
3881 "The calling package is not allowed to select ISD-R.");
3882 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003883 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003884
Malcolm Chend965c8b2018-02-28 15:00:40 -08003885 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003886 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3887 null /* workSource */);
3888 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003889
Malcolm Chend965c8b2018-02-28 15:00:40 -08003890 // Append the returned status code to the end of the response payload.
3891 String s = Integer.toHexString(
3892 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3893 if (response.payload != null) {
3894 s = IccUtils.bytesToHexString(response.payload) + s;
3895 }
3896 return s;
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003899 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003900 }
3901
3902 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003903 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003904 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3906 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003907
Malcolm Chend965c8b2018-02-28 15:00:40 -08003908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 if (DBG) {
3911 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3912 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3913 }
3914
3915 IccIoResult response =
3916 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3917 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3918 subId);
3919
3920 if (DBG) {
3921 log("Exchange SIM_IO [R]" + response);
3922 }
3923
3924 byte[] result = null;
3925 int length = 2;
3926 if (response.payload != null) {
3927 length = 2 + response.payload.length;
3928 result = new byte[length];
3929 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3930 } else {
3931 result = new byte[length];
3932 }
3933
3934 result[length - 1] = (byte) response.sw2;
3935 result[length - 2] = (byte) response.sw1;
3936 return result;
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003939 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003940 }
3941
Nathan Haroldb3014052017-01-25 15:57:32 -08003942 /**
3943 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3944 * on a particular subscription
3945 */
sqianb6e41952018-03-12 14:54:01 -07003946 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3948 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3949 return null;
3950 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003951
3952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 if (appType != TelephonyManager.APPTYPE_USIM
3955 && appType != TelephonyManager.APPTYPE_SIM) {
3956 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3957 return null;
3958 }
3959 Object response = sendRequest(
3960 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3961 if (response instanceof String[]) {
3962 return (String[]) response;
3963 }
3964 // Response is an Exception of some kind,
3965 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003966 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003967 } finally {
3968 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003969 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003970 }
3971
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003972 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003973 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3975 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003976
Malcolm Chend965c8b2018-02-28 15:00:40 -08003977 final long identity = Binder.clearCallingIdentity();
3978 try {
3979 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3980 if (response.payload == null) {
3981 return "";
3982 }
Evan Charltonc66da362014-05-16 14:06:40 -07003983
Malcolm Chend965c8b2018-02-28 15:00:40 -08003984 // Append the returned status code to the end of the response payload.
3985 String s = Integer.toHexString(
3986 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3987 s = IccUtils.bytesToHexString(response.payload) + s;
3988 return s;
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
Evan Charltonc66da362014-05-16 14:06:40 -07003992 }
3993
Jake Hambye994d462014-02-03 13:10:13 -08003994 /**
3995 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3996 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3997 *
3998 * @param itemID the ID of the item to read
3999 * @return the NV item as a String, or null on error.
4000 */
4001 @Override
4002 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004003 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4005 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004006
4007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004010 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004011 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4012 return value;
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
4015 }
Jake Hambye994d462014-02-03 13:10:13 -08004016 }
4017
4018 /**
4019 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4020 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4021 *
4022 * @param itemID the ID of the item to read
4023 * @param itemValue the value to write, as a String
4024 * @return true on success; false on any failure
4025 */
4026 @Override
4027 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004028 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4030 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004031
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4035 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004036 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004037 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4038 return success;
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
4041 }
Jake Hambye994d462014-02-03 13:10:13 -08004042 }
4043
4044 /**
4045 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4046 * Used for device configuration by some CDMA operators.
4047 *
4048 * @param preferredRoamingList byte array containing the new PRL
4049 * @return true on success; false on any failure
4050 */
4051 @Override
4052 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4054 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004055
4056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4059 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4060 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4061 return success;
4062 } finally {
4063 Binder.restoreCallingIdentity(identity);
4064 }
Jake Hambye994d462014-02-03 13:10:13 -08004065 }
4066
4067 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004068 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004069 * Used for device configuration by some CDMA operators.
4070 *
chen xu1cc0abe2018-10-26 17:39:23 -07004071 * @param slotIndex - device slot.
4072 *
Jake Hambye994d462014-02-03 13:10:13 -08004073 * @return true on success; false on any failure
4074 */
4075 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004076 public boolean resetModemConfig(int slotIndex) {
4077 Phone phone = PhoneFactory.getPhone(slotIndex);
4078 if (phone != null) {
4079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004081
chen xu1cc0abe2018-10-26 17:39:23 -07004082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4085 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4086 return success;
4087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004090 }
chen xu1cc0abe2018-10-26 17:39:23 -07004091 return false;
4092 }
4093
4094 /**
4095 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4096 *
4097 * @param slotIndex - device slot.
4098 *
4099 * @return true on success; false on any failure
4100 */
4101 @Override
4102 public boolean rebootModem(int slotIndex) {
4103 Phone phone = PhoneFactory.getPhone(slotIndex);
4104 if (phone != null) {
4105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4106 mApp, phone.getSubId(), "rebootModem");
4107
4108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4111 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4112 return success;
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
4116 }
4117 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004118 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004119
Svet Ganovb320e182015-04-16 12:30:10 -07004120 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004121 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004123 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004124 return new String[0];
4125 }
4126
Malcolm Chend965c8b2018-02-28 15:00:40 -08004127 final long identity = Binder.clearCallingIdentity();
4128 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004129 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
Wink Saville36469e72014-06-11 15:17:00 -07004133 }
4134
Brad Ebinger51f743a2017-01-23 13:50:20 -08004135 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004136 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4137 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004138 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004139 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004140 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004141
4142 final long identity = Binder.clearCallingIdentity();
4143 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004144 ImsResolver resolver = PhoneFactory.getImsResolver();
4145 if (resolver == null) {
4146 // may happen if the device does not support IMS.
4147 return;
4148 }
4149 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004150 } finally {
4151 Binder.restoreCallingIdentity(identity);
4152 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004153 }
4154
4155 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004156 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4157 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004158 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004159 public void disableIms(int slotId) {
4160 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004161
4162 final long identity = Binder.clearCallingIdentity();
4163 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004164 ImsResolver resolver = PhoneFactory.getImsResolver();
4165 if (resolver == null) {
4166 // may happen if the device does not support IMS.
4167 return;
4168 }
4169 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004173 }
4174
4175 /**
4176 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4177 * feature or {@link null} if the service is not available. If the feature is available, the
4178 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4179 */
4180 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004181 IImsServiceFeatureCallback callback) {
4182 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004183
4184 final long identity = Binder.clearCallingIdentity();
4185 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004186 ImsResolver resolver = PhoneFactory.getImsResolver();
4187 if (resolver == null) {
4188 // may happen if the device does not support IMS.
4189 return null;
4190 }
4191 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004192 } finally {
4193 Binder.restoreCallingIdentity(identity);
4194 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004195 }
4196
4197 /**
4198 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4199 * feature during emergency calling or {@link null} if the service is not available. If the
4200 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4201 * listener for feature updates.
4202 */
4203 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4204 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004205
4206 final long identity = Binder.clearCallingIdentity();
4207 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004208 ImsResolver resolver = PhoneFactory.getImsResolver();
4209 if (resolver == null) {
4210 // may happen if the device does not support IMS.
4211 return null;
4212 }
4213 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004217 }
4218
Brad Ebinger5f64b052017-12-14 14:26:15 -08004219 /**
4220 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004221 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004222 */
4223 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4224 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004225
4226 final long identity = Binder.clearCallingIdentity();
4227 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004228 ImsResolver resolver = PhoneFactory.getImsResolver();
4229 if (resolver == null) {
4230 // may happen if the device does not support IMS.
4231 return null;
4232 }
4233 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004234 } finally {
4235 Binder.restoreCallingIdentity(identity);
4236 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004237 }
4238
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004239 /**
4240 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004241 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004242 */
4243 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4244 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004245
4246 final long identity = Binder.clearCallingIdentity();
4247 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004248 ImsResolver resolver = PhoneFactory.getImsResolver();
4249 if (resolver == null) {
4250 // may happen if the device does not support IMS.
4251 return null;
4252 }
4253 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004254 } finally {
4255 Binder.restoreCallingIdentity(identity);
4256 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004257 }
4258
Brad Ebinger884c07b2018-02-15 16:17:40 -08004259 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004260 * Sets the ImsService Package Name that Telephony will bind to.
4261 *
4262 * @param slotId the slot ID that the ImsService should bind for.
4263 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4264 * ImsService is the device default ImsService.
4265 * @param packageName The package name of the application that contains the ImsService to bind
4266 * to.
4267 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4268 * @hide
4269 */
4270 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004271 int[] subIds = SubscriptionManager.getSubId(slotId);
4272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4273 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4274 "setImsService");
4275
Malcolm Chend965c8b2018-02-28 15:00:40 -08004276 final long identity = Binder.clearCallingIdentity();
4277 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004278 ImsResolver resolver = PhoneFactory.getImsResolver();
4279 if (resolver == null) {
4280 // may happen if the device does not support IMS.
4281 return false;
4282 }
4283 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4284 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004285 } finally {
4286 Binder.restoreCallingIdentity(identity);
4287 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004288 }
4289
4290 /**
4291 * Return the ImsService configuration.
4292 *
4293 * @param slotId The slot that the ImsService is associated with.
4294 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4295 * the device default.
4296 * @return the package name of the ImsService configuration.
4297 */
4298 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004299 int[] subIds = SubscriptionManager.getSubId(slotId);
4300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4301 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4302 "getImsService");
4303
Malcolm Chend965c8b2018-02-28 15:00:40 -08004304 final long identity = Binder.clearCallingIdentity();
4305 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004306 ImsResolver resolver = PhoneFactory.getImsResolver();
4307 if (resolver == null) {
4308 // may happen if the device does not support IMS.
4309 return "";
4310 }
4311 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004315 }
4316
Wink Saville36469e72014-06-11 15:17:00 -07004317 public void setImsRegistrationState(boolean registered) {
4318 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004319
4320 final long identity = Binder.clearCallingIdentity();
4321 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004322 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
Wink Saville36469e72014-06-11 15:17:00 -07004326 }
4327
4328 /**
Stuart Scott54788802015-03-30 13:18:01 -07004329 * Set the network selection mode to automatic.
4330 *
4331 */
4332 @Override
4333 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4335 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004336
Pengquan Meng466e2482018-09-21 15:54:48 -07004337 if (!isActiveSubscription(subId)) {
4338 return;
4339 }
4340
Malcolm Chend965c8b2018-02-28 15:00:40 -08004341 final long identity = Binder.clearCallingIdentity();
4342 try {
4343 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4344 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
Stuart Scott54788802015-03-30 13:18:01 -07004348 }
4349
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004350 /**
4351 * Ask the radio to connect to the input network and change selection mode to manual.
4352 *
4353 * @param subId the id of the subscription.
4354 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4355 * the operator to attach to.
4356 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4357 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4358 * normal network selection next time.
4359 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004360 */
4361 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004362 public boolean setNetworkSelectionModeManual(
4363 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4365 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004366
4367 if (!isActiveSubscription(subId)) {
4368 return false;
4369 }
4370
Malcolm Chend965c8b2018-02-28 15:00:40 -08004371 final long identity = Binder.clearCallingIdentity();
4372 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004373 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004374 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004375 if (DBG) {
4376 log("setNetworkSelectionModeManual: subId: " + subId
4377 + " operator: " + operatorInfo);
4378 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004379 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004383 }
4384
4385 /**
4386 * Scans for available networks.
4387 */
4388 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004389 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4391 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004392 LocationAccessPolicy.LocationPermissionResult locationResult =
4393 LocationAccessPolicy.checkLocationPermission(mApp,
4394 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4395 .setCallingPackage(callingPackage)
4396 .setCallingPid(Binder.getCallingPid())
4397 .setCallingUid(Binder.getCallingUid())
4398 .setMethod("getCellNetworkScanResults")
4399 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4400 .build());
4401 switch (locationResult) {
4402 case DENIED_HARD:
4403 throw new SecurityException("Not allowed to access scan results -- location");
4404 case DENIED_SOFT:
4405 return null;
4406 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004407
Pengquan Meng0c05b502018-09-06 09:59:22 -07004408 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004409 try {
4410 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004411 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004412 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004413 } finally {
4414 Binder.restoreCallingIdentity(identity);
4415 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004416 }
4417
4418 /**
yinxub1bed742017-04-17 11:45:04 -07004419 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004420 *
yinxub1bed742017-04-17 11:45:04 -07004421 * @param subId id of the subscription
4422 * @param request contains the radio access networks with bands/channels to scan
4423 * @param messenger callback messenger for scan results or errors
4424 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004425 * @return the id of the requested scan which can be used to stop the scan.
4426 */
4427 @Override
4428 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004429 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4431 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004432 LocationAccessPolicy.LocationPermissionResult locationResult =
4433 LocationAccessPolicy.checkLocationPermission(mApp,
4434 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4435 .setCallingPackage(callingPackage)
4436 .setCallingPid(Binder.getCallingPid())
4437 .setCallingUid(Binder.getCallingUid())
4438 .setMethod("requestNetworkScan")
4439 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4440 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004441 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4442 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4443 if (e != null) {
4444 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4445 throw e;
4446 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004447 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004448 return TelephonyScanManager.INVALID_SCAN_ID;
4449 }
4450 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004451 }
Hall Liubac7d482019-04-25 14:02:26 -07004452 int callingUid = Binder.getCallingUid();
4453 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004454 final long identity = Binder.clearCallingIdentity();
4455 try {
4456 return mNetworkScanRequestTracker.startNetworkScan(
4457 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004458 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004459 } finally {
4460 Binder.restoreCallingIdentity(identity);
4461 }
yinxu504e1392017-04-12 16:03:22 -07004462 }
4463
Hall Liub2ac8ef2019-02-28 15:56:23 -08004464 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4465 NetworkScanRequest request) {
4466 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4467 != PERMISSION_GRANTED) {
4468 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4469 + " without location access.");
4470 }
4471
4472 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4473 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004474 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4475 return new SecurityException("Specific channels must not be"
4476 + " scanned without location access.");
4477 }
4478 }
4479 }
4480
Hall Liub2ac8ef2019-02-28 15:56:23 -08004481 return null;
4482 }
4483
yinxu504e1392017-04-12 16:03:22 -07004484 /**
4485 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004486 *
4487 * @param subId id of the subscription
4488 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004489 */
4490 @Override
4491 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4493 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004494
Hall Liubac7d482019-04-25 14:02:26 -07004495 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
Hall Liubac7d482019-04-25 14:02:26 -07004498 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
yinxu504e1392017-04-12 16:03:22 -07004502 }
4503
4504 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004505 * Get the calculated preferred network type.
4506 * Used for debugging incorrect network type.
4507 *
4508 * @return the preferred network type, defined in RILConstants.java.
4509 */
4510 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004511 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004512 final Phone defaultPhone = getDefaultPhone();
4513 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4514 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004515 return RILConstants.PREFERRED_NETWORK_MODE;
4516 }
4517
Malcolm Chend965c8b2018-02-28 15:00:40 -08004518 final long identity = Binder.clearCallingIdentity();
4519 try {
4520 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004521 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
Junda Liu84d15a22014-07-02 11:21:04 -07004525 }
4526
4527 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004528 * Get the preferred network type.
4529 * Used for device configuration by some CDMA operators.
4530 *
4531 * @return the preferred network type, defined in RILConstants.java.
4532 */
4533 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004534 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004535 TelephonyPermissions
4536 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4537 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004538
4539 final long identity = Binder.clearCallingIdentity();
4540 try {
4541 if (DBG) log("getPreferredNetworkType");
4542 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4543 int networkType = (result != null ? result[0] : -1);
4544 if (DBG) log("getPreferredNetworkType: " + networkType);
4545 return networkType;
4546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004549 }
4550
4551 /**
4552 * Set the preferred network type.
4553 * Used for device configuration by some CDMA operators.
4554 *
4555 * @param networkType the preferred network type, defined in RILConstants.java.
4556 * @return true on success; false on any failure.
4557 */
4558 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004559 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4561 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004562
4563 final long identity = Binder.clearCallingIdentity();
4564 try {
4565 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4566 Boolean success = (Boolean) sendRequest(
4567 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4568 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4569 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004570 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004571 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4572 }
4573 return success;
4574 } finally {
4575 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004576 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004577 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004578
4579 /**
Miaoa84611c2019-03-15 09:21:10 +08004580 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004581 *
Miaoa84611c2019-03-15 09:21:10 +08004582 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004583 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004584 * @hide
4585 */
4586 @Override
Miaoa84611c2019-03-15 09:21:10 +08004587 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004588 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004590 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004591 try {
Miaoa84611c2019-03-15 09:21:10 +08004592 if (phone != null) {
4593 return phone.hasMatchedTetherApnSetting();
4594 } else {
4595 return false;
4596 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004599 }
Junda Liu475951f2014-11-07 16:45:03 -08004600 }
4601
4602 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004603 * Set mobile data enabled
4604 * Used by the user through settings etc to turn on/off mobile data
4605 *
4606 * @param enable {@code true} turn turn data on, else {@code false}
4607 */
4608 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004609 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4611 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004612
4613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 int phoneId = mSubscriptionController.getPhoneId(subId);
4616 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4617 Phone phone = PhoneFactory.getPhone(phoneId);
4618 if (phone != null) {
4619 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004620 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004621 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004622 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004623 }
4624 } finally {
4625 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004626 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004627 }
4628
4629 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004630 * Get the user enabled state of Mobile Data.
4631 *
4632 * TODO: remove and use isUserDataEnabled.
4633 * This can't be removed now because some vendor codes
4634 * calls through ITelephony directly while they should
4635 * use TelephonyManager.
4636 *
4637 * @return true on enabled
4638 */
4639 @Override
4640 public boolean getDataEnabled(int subId) {
4641 return isUserDataEnabled(subId);
4642 }
4643
4644 /**
4645 * Get whether mobile data is enabled per user setting.
4646 *
4647 * There are other factors deciding whether mobile data is actually enabled, but they are
4648 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004649 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004650 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004651 *
4652 * @return {@code true} if data is enabled else {@code false}
4653 */
4654 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004655 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004656 try {
4657 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4658 null);
4659 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4661 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004662 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004663
4664 final long identity = Binder.clearCallingIdentity();
4665 try {
4666 int phoneId = mSubscriptionController.getPhoneId(subId);
4667 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4668 Phone phone = PhoneFactory.getPhone(phoneId);
4669 if (phone != null) {
4670 boolean retVal = phone.isUserDataEnabled();
4671 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4672 return retVal;
4673 } else {
4674 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4675 return false;
4676 }
4677 } finally {
4678 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004679 }
4680 }
4681
4682 /**
4683 * Get whether mobile data is enabled.
4684 *
4685 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4686 * whether mobile data is actually enabled.
4687 *
4688 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4689 *
4690 * @return {@code true} if data is enabled else {@code false}
4691 */
4692 @Override
4693 public boolean isDataEnabled(int subId) {
4694 try {
4695 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4696 null);
4697 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4699 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004700 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004701
4702 final long identity = Binder.clearCallingIdentity();
4703 try {
4704 int phoneId = mSubscriptionController.getPhoneId(subId);
4705 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4706 Phone phone = PhoneFactory.getPhone(phoneId);
4707 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004708 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004709 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4710 return retVal;
4711 } else {
4712 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4713 return false;
4714 }
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004717 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004718 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004719
4720 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004721 public int getCarrierPrivilegeStatus(int subId) {
4722 final Phone phone = getPhone(subId);
4723 if (phone == null) {
4724 loge("getCarrierPrivilegeStatus: Invalid subId");
4725 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4726 }
4727 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004728 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004729 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004730 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4731 }
4732 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004733 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004734 }
Junda Liu29340342014-07-10 15:23:27 -07004735
4736 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4738 final Phone phone = getPhone(subId);
4739 if (phone == null) {
4740 loge("getCarrierPrivilegeStatus: Invalid subId");
4741 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4742 }
4743 UiccProfile profile =
4744 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4745 if (profile == null) {
4746 loge("getCarrierPrivilegeStatus: No UICC");
4747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4748 }
4749 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4750 }
4751
4752 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004753 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004754 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004755 if (TextUtils.isEmpty(pkgName))
4756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004757 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004758 if (card == null) {
4759 loge("checkCarrierPrivilegesForPackage: No UICC");
4760 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4761 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004762 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4763 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004764 }
4765
4766 @Override
4767 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004768 if (TextUtils.isEmpty(pkgName))
4769 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004770 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4771 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4772 UiccCard card = UiccController.getInstance().getUiccCard(i);
4773 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004774 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004775 continue;
4776 }
4777
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004778 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004779 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4780 break;
4781 }
4782 }
4783
4784 return result;
Junda Liu29340342014-07-10 15:23:27 -07004785 }
Derek Tan89e89d42014-07-08 17:00:10 -07004786
4787 @Override
Junda Liue64de782015-04-16 17:19:16 -07004788 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4789 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4790 loge("phoneId " + phoneId + " is not valid.");
4791 return null;
4792 }
4793 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004794 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004795 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004796 return null ;
4797 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004798 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004799 }
4800
Amith Yamasani6e118872016-02-19 12:53:51 -08004801 @Override
4802 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004803 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004804 List<String> privilegedPackages = new ArrayList<>();
4805 List<PackageInfo> packages = null;
4806 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4807 UiccCard card = UiccController.getInstance().getUiccCard(i);
4808 if (card == null) {
4809 // No UICC in that slot.
4810 continue;
4811 }
4812 if (card.hasCarrierPrivilegeRules()) {
4813 if (packages == null) {
4814 // Only check packages in user 0 for now
4815 packages = pm.getInstalledPackagesAsUser(
4816 PackageManager.MATCH_DISABLED_COMPONENTS
4817 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4818 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4819 }
4820 for (int p = packages.size() - 1; p >= 0; p--) {
4821 PackageInfo pkgInfo = packages.get(p);
4822 if (pkgInfo != null && pkgInfo.packageName != null
4823 && card.getCarrierPrivilegeStatus(pkgInfo)
4824 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4825 privilegedPackages.add(pkgInfo.packageName);
4826 }
4827 }
4828 }
4829 }
4830 return privilegedPackages;
4831 }
4832
Wink Savilleb564aae2014-10-23 10:18:09 -07004833 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004834 final Phone phone = getPhone(subId);
4835 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004836 if (card == null) {
4837 loge("getIccId: No UICC");
4838 return null;
4839 }
4840 String iccId = card.getIccId();
4841 if (TextUtils.isEmpty(iccId)) {
4842 loge("getIccId: ICC ID is null or empty.");
4843 return null;
4844 }
4845 return iccId;
4846 }
4847
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004848 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004849 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4850 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004851 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4852 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004853
Malcolm Chend965c8b2018-02-28 15:00:40 -08004854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 final String iccId = getIccId(subId);
4857 final Phone phone = getPhone(subId);
4858 if (phone == null) {
4859 return false;
4860 }
4861 final String subscriberId = phone.getSubscriberId();
4862
4863 if (DBG_MERGE) {
4864 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4865 + subscriberId + " to " + number);
4866 }
4867
4868 if (TextUtils.isEmpty(iccId)) {
4869 return false;
4870 }
4871
4872 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4873
4874 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4875 if (alphaTag == null) {
4876 editor.remove(alphaTagPrefKey);
4877 } else {
4878 editor.putString(alphaTagPrefKey, alphaTag);
4879 }
4880
4881 // Record both the line number and IMSI for this ICCID, since we need to
4882 // track all merged IMSIs based on line number
4883 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4884 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4885 if (number == null) {
4886 editor.remove(numberPrefKey);
4887 editor.remove(subscriberPrefKey);
4888 } else {
4889 editor.putString(numberPrefKey, number);
4890 editor.putString(subscriberPrefKey, subscriberId);
4891 }
4892
4893 editor.commit();
4894 return true;
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004897 }
Derek Tan7226c842014-07-02 17:42:23 -07004898 }
4899
4900 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004901 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004902 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004904 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004905 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004906 return null;
4907 }
Derek Tan97ebb422014-09-05 16:55:38 -07004908
Malcolm Chend965c8b2018-02-28 15:00:40 -08004909 final long identity = Binder.clearCallingIdentity();
4910 try {
4911 String iccId = getIccId(subId);
4912 if (iccId != null) {
4913 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4914 if (DBG_MERGE) {
4915 log("getLine1NumberForDisplay returning "
4916 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4917 }
4918 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004919 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004920 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4921 return null;
4922 } finally {
4923 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004924 }
Derek Tan7226c842014-07-02 17:42:23 -07004925 }
4926
4927 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004928 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004930 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004931 return null;
4932 }
Derek Tan97ebb422014-09-05 16:55:38 -07004933
Malcolm Chend965c8b2018-02-28 15:00:40 -08004934 final long identity = Binder.clearCallingIdentity();
4935 try {
4936 String iccId = getIccId(subId);
4937 if (iccId != null) {
4938 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4939 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4940 }
4941 return null;
4942 } finally {
4943 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004944 }
Derek Tan7226c842014-07-02 17:42:23 -07004945 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004946
4947 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004948 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004949 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4950 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004952 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4953 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004954 return null;
4955 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004956
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004959 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004960 final TelephonyManager tele = TelephonyManager.from(context);
4961 final SubscriptionManager sub = SubscriptionManager.from(context);
4962
4963 // Figure out what subscribers are currently active
4964 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4965 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4966 // the process, where TelephonyManager was instantiated.
4967 // Otherwise AppOps check will fail.
4968
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004969 final int[] subIds = sub.getActiveSubscriptionIdList();
4970 for (int subId : subIds) {
4971 activeSubscriberIds.add(tele.getSubscriberId(subId));
4972 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004973
4974 // First pass, find a number override for an active subscriber
4975 String mergeNumber = null;
4976 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4977 for (String key : prefs.keySet()) {
4978 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4979 final String subscriberId = (String) prefs.get(key);
4980 if (activeSubscriberIds.contains(subscriberId)) {
4981 final String iccId = key.substring(
4982 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4983 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4984 mergeNumber = (String) prefs.get(numberKey);
4985 if (DBG_MERGE) {
4986 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4987 + " for active subscriber " + subscriberId);
4988 }
4989 if (!TextUtils.isEmpty(mergeNumber)) {
4990 break;
4991 }
4992 }
4993 }
4994 }
4995
4996 // Shortcut when no active merged subscribers
4997 if (TextUtils.isEmpty(mergeNumber)) {
4998 return null;
4999 }
5000
5001 // Second pass, find all subscribers under that line override
5002 final ArraySet<String> result = new ArraySet<>();
5003 for (String key : prefs.keySet()) {
5004 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5005 final String number = (String) prefs.get(key);
5006 if (mergeNumber.equals(number)) {
5007 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5008 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5009 final String subscriberId = (String) prefs.get(subscriberKey);
5010 if (!TextUtils.isEmpty(subscriberId)) {
5011 result.add(subscriberId);
5012 }
5013 }
5014 }
5015 }
5016
5017 final String[] resultArray = result.toArray(new String[result.size()]);
5018 Arrays.sort(resultArray);
5019 if (DBG_MERGE) {
5020 Slog.d(LOG_TAG,
5021 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5022 }
5023 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005026 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005027 }
5028
5029 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005030 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5032 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005033
5034 final long identity = Binder.clearCallingIdentity();
5035 try {
5036 final Phone phone = getPhone(subId);
5037 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
5040 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005041 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005042
5043 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005044 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005045 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5046 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005047 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005048
5049 final long identity = Binder.clearCallingIdentity();
5050 try {
5051 final Phone phone = getPhone(subId);
5052 if (phone == null) {
5053 return false;
5054 }
5055 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5056 cdmaNonRoamingList);
5057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005059 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005060 }
5061
5062 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005063 @Deprecated
5064 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5065 enforceModifyPermission();
5066
5067 int returnValue = 0;
5068 try {
vagdevie435a3e2018-08-15 16:01:53 -07005069 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005070 if(result.exception == null) {
5071 if (result.result != null) {
5072 byte[] responseData = (byte[])(result.result);
5073 if(responseData.length > oemResp.length) {
5074 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5075 responseData.length + "bytes. Buffer Size is " +
5076 oemResp.length + "bytes.");
5077 }
5078 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5079 returnValue = responseData.length;
5080 }
5081 } else {
5082 CommandException ex = (CommandException) result.exception;
5083 returnValue = ex.getCommandError().ordinal();
5084 if(returnValue > 0) returnValue *= -1;
5085 }
5086 } catch (RuntimeException e) {
5087 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5088 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5089 if(returnValue > 0) returnValue *= -1;
5090 }
5091
5092 return returnValue;
5093 }
5094
5095 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005096 public void setRadioCapability(RadioAccessFamily[] rafs) {
5097 try {
5098 ProxyController.getInstance().setRadioCapability(rafs);
5099 } catch (RuntimeException e) {
5100 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5101 }
5102 }
5103
5104 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005105 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005106 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005107 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005108 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005109 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005110 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
chen xufeeed752018-10-26 14:17:57 -07005113 TelephonyPermissions
5114 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5115 mApp, phone.getSubId(), "getRadioAccessFamily");
5116 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005117 } finally {
5118 Binder.restoreCallingIdentity(identity);
5119 }
chen xufeeed752018-10-26 14:17:57 -07005120 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005121 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005122
5123 @Override
5124 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005125 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005126 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005127
5128 final long identity = Binder.clearCallingIdentity();
5129 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005130 ImsManager.getInstance(defaultPhone.getContext(),
5131 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005132 } finally {
5133 Binder.restoreCallingIdentity(identity);
5134 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005135 }
5136
5137 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005138 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005139 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005141 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005142 return false;
5143 }
Svet Ganovb320e182015-04-16 12:30:10 -07005144
Malcolm Chend965c8b2018-02-28 15:00:40 -08005145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 // Check the user preference and the system-level IMS setting. Even if the user has
5148 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5149 // In the long run, we may instead need to check if there exists a connection service
5150 // which can support video calling.
5151 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005152 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005153 return imsManager.isVtEnabledByPlatform()
5154 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5155 && imsManager.isVtEnabledByUser();
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
5158 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005159 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005160
Andrew Leea1239f22015-03-02 17:44:07 -08005161 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005162 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5163 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5164 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5165 return false;
5166 }
5167
5168 final long identity = Binder.clearCallingIdentity();
5169 try {
5170 CarrierConfigManager configManager =
5171 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005172 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005173 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Andrew Leea1239f22015-03-02 17:44:07 -08005177 }
5178
5179 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005180 public boolean isWorldPhone(int subId, String callingPackage) {
5181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5182 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5183 return false;
5184 }
5185
5186 final long identity = Binder.clearCallingIdentity();
5187 try {
5188 CarrierConfigManager configManager =
5189 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005190 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005191 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Andrew Leea1239f22015-03-02 17:44:07 -08005195 }
5196
Andrew Lee9431b832015-03-09 18:46:45 -07005197 @Override
5198 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005199 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005200 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005201 }
5202
5203 @Override
5204 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005205 final long identity = Binder.clearCallingIdentity();
5206 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005207 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
Andrew Lee9431b832015-03-09 18:46:45 -07005211 }
5212
Hall Liuf6668912018-10-31 17:05:23 -07005213 /**
5214 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5215 * support for the feature and device firmware support.
5216 *
5217 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5218 */
5219 @Override
5220 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005222 final Phone phone = getPhone(subscriptionId);
5223 if (phone == null) {
5224 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5225 return false;
5226 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005227 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005228 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005229 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5230 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005231 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005232 return isCarrierSupported && isDeviceSupported;
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
Hall Liu98187582018-01-22 19:15:32 -08005236 }
5237
Hall Liuf6668912018-10-31 17:05:23 -07005238 /**
5239 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5240 * both also support RTT.
5241 */
5242 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005243 final long identity = Binder.clearCallingIdentity();
5244 try {
Hall Liuf6668912018-10-31 17:05:23 -07005245 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005246 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005250 }
5251
Sanket Padawe7310cc72015-01-14 09:53:20 -08005252 /**
5253 * Returns the unique device ID of phone, for example, the IMEI for
5254 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5255 *
5256 * <p>Requires Permission:
5257 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5258 */
5259 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005260 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005261 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005262 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005263 return null;
5264 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005265 int subId = phone.getSubId();
5266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5267 mApp, subId, callingPackage, "getDeviceId")) {
5268 return null;
5269 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005270
5271 final long identity = Binder.clearCallingIdentity();
5272 try {
5273 return phone.getDeviceId();
5274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005277 }
5278
Ping Sunc67b7c22016-03-02 19:16:45 +08005279 /**
5280 * {@hide}
5281 * Returns the IMS Registration Status on a particular subid
5282 *
5283 * @param subId
5284 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005285 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005286 Phone phone = getPhone(subId);
5287 if (phone != null) {
5288 return phone.isImsRegistered();
5289 } else {
5290 return false;
5291 }
5292 }
5293
Santos Cordon7a1885b2015-02-03 11:15:19 -08005294 @Override
5295 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005296 final long identity = Binder.clearCallingIdentity();
5297 try {
5298 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005302 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005303
Tyler Gunn327a9722019-04-03 15:28:53 -07005304 @Override
5305 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5306 final long identity = Binder.clearCallingIdentity();
5307 try {
5308 Phone phone = getPhone(subscriptionId);
5309 if (phone == null) {
5310 return null;
5311 }
5312 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
5316 }
5317
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005318 /**
5319 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005320 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005321 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005322 final long identity = Binder.clearCallingIdentity();
5323 try {
5324 Phone phone = getPhone(subId);
5325 if (phone != null) {
5326 return phone.isWifiCallingEnabled();
5327 } else {
5328 return false;
5329 }
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005332 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005333 }
5334
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005335 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005336 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005337 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005338 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005339 final long identity = Binder.clearCallingIdentity();
5340 try {
5341 Phone phone = getPhone(subId);
5342 if (phone != null) {
5343 return phone.isVideoEnabled();
5344 } else {
5345 return false;
5346 }
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005349 }
5350 }
5351
5352 /**
5353 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5354 * defined in {@link ImsRegistrationImplBase}.
5355 */
5356 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 Phone phone = getPhone(subId);
5360 if (phone != null) {
5361 return phone.getImsRegistrationTech();
5362 } else {
5363 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5364 }
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005367 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005368 }
5369
Stuart Scott8eef64f2015-04-08 15:13:54 -07005370 @Override
5371 public void factoryReset(int subId) {
5372 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005373 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5374 return;
5375 }
5376
Svet Ganovcc087f82015-05-12 20:35:54 -07005377 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005378
Svet Ganovcc087f82015-05-12 20:35:54 -07005379 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005380 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5381 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005382 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005383 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005384 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005385 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5386 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005387 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005388 // There has been issues when Sms raw table somehow stores orphan
5389 // fragments. They lead to garbled message when new fragments come
5390 // in and combined with those stale ones. In case this happens again,
5391 // user can reset all network settings which will clean up this table.
5392 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005393 } finally {
5394 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005395 }
5396 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005397
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005398 private void cleanUpSmsRawTable(Context context) {
5399 ContentResolver resolver = context.getContentResolver();
5400 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5401 resolver.delete(uri, null, null);
5402 }
5403
Narayan Kamath1c496c22015-04-16 14:40:19 +01005404 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005405 public String getSimLocaleForSubscriber(int subId) {
5406 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5407 final Phone phone = getPhone(subId);
5408 if (phone == null) {
5409 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005410 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005411 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005412 final long identity = Binder.clearCallingIdentity();
5413 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005414 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5415 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005416 // Try and fetch the locale from the carrier properties or from the SIM language
5417 // preferences (EF-PL and EF-LI)...
5418 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005419 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005420 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5421 if (localeFromDefaultSim != null) {
5422 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5423 if (DBG) log("Using locale from subId: " + subId + " locale: "
5424 + localeFromDefaultSim);
5425 return localeFromDefaultSim.toLanguageTag();
5426 } else {
5427 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005428 }
5429 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005430
Malcolm Chend965c8b2018-02-28 15:00:40 -08005431 // The SIM language preferences only store a language (e.g. fr = French), not an
5432 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5433 // the SIM and carrier preferences does not include a country we add the country
5434 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005435 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005436 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005437 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005438 return mccLocale.toLanguageTag();
5439 }
5440
5441 if (DBG) log("No locale found - returning null");
5442 return null;
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
5445 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005446 }
5447
5448 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005449 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005450 }
5451
Malcolm Chend965c8b2018-02-28 15:00:40 -08005452 /**
5453 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5454 */
5455 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005456 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005457 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005458
Chenjie Yu1ba97252018-01-11 18:16:20 -08005459 private final ModemActivityInfo mLastModemActivityInfo =
5460 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5461
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005462 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005463 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5464 * representing the state of the modem.
5465 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005466 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5467 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005468 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005469 */
5470 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005471 public void requestModemActivityInfo(ResultReceiver result) {
5472 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005473 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005474
5475 final long identity = Binder.clearCallingIdentity();
5476 try {
5477 ModemActivityInfo ret = null;
5478 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005479 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5480 CMD_GET_MODEM_ACTIVITY_INFO,
5481 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005482 if (isModemActivityInfoValid(info)) {
5483 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5484 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5485 mergedTxTimeMs[i] =
5486 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5487 }
5488 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5489 mLastModemActivityInfo.setSleepTimeMillis(
5490 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5491 mLastModemActivityInfo.setIdleTimeMillis(
5492 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5493 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5494 mLastModemActivityInfo.setRxTimeMillis(
5495 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5496 mLastModemActivityInfo.setEnergyUsed(
5497 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005498 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005499 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5500 mLastModemActivityInfo.getSleepTimeMillis(),
5501 mLastModemActivityInfo.getIdleTimeMillis(),
5502 mLastModemActivityInfo.getTxTimeMillis(),
5503 mLastModemActivityInfo.getRxTimeMillis(),
5504 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005505 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005506 Bundle bundle = new Bundle();
5507 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5508 result.send(0, bundle);
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005511 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005512 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005513
Siddharth Rayf5d29552018-06-17 15:02:38 -07005514 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5515 // less than total activity duration.
5516 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5517 if (info == null) {
5518 return false;
5519 }
5520 int activityDurationMs =
5521 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5522 int totalTxTimeMs = 0;
5523 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5524 totalTxTimeMs += info.getTxTimeMillis()[i];
5525 }
5526 return (info.isValid()
5527 && (info.getSleepTimeMillis() <= activityDurationMs)
5528 && (info.getIdleTimeMillis() <= activityDurationMs)
5529 && (info.getRxTimeMillis() <= activityDurationMs)
5530 && (totalTxTimeMs <= activityDurationMs));
5531 }
5532
Jack Yu85bd38a2015-11-09 11:34:32 -08005533 /**
5534 * {@hide}
5535 * Returns the service state information on specified subscription.
5536 */
5537 @Override
5538 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005540 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005541 return null;
5542 }
5543
Hall Liuf19c44f2018-11-27 14:38:17 -08005544 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5545 LocationAccessPolicy.checkLocationPermission(mApp,
5546 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5547 .setCallingPackage(callingPackage)
5548 .setCallingPid(Binder.getCallingPid())
5549 .setCallingUid(Binder.getCallingUid())
5550 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005551 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005552 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5553 .build());
5554
5555 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5556 LocationAccessPolicy.checkLocationPermission(mApp,
5557 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5558 .setCallingPackage(callingPackage)
5559 .setCallingPid(Binder.getCallingPid())
5560 .setCallingUid(Binder.getCallingUid())
5561 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005562 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005563 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5564 .build());
5565 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5566 boolean hasFinePermission =
5567 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5568 boolean hasCoarsePermission =
5569 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5570
Malcolm Chend965c8b2018-02-28 15:00:40 -08005571 final long identity = Binder.clearCallingIdentity();
5572 try {
5573 final Phone phone = getPhone(subId);
5574 if (phone == null) {
5575 return null;
5576 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005577
Hall Liuf19c44f2018-11-27 14:38:17 -08005578 ServiceState ss = phone.getServiceState();
5579
5580 // Scrub out the location info in ServiceState depending on what level of access
5581 // the caller has.
5582 if (hasFinePermission) return ss;
5583 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5584 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005588 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005589
5590 /**
5591 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5592 *
5593 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5594 * voicemail ringtone.
5595 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5596 * PhoneAccount.
5597 */
5598 @Override
5599 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005600 final long identity = Binder.clearCallingIdentity();
5601 try {
5602 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5603 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005604 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005605 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005606
Malcolm Chend965c8b2018-02-28 15:00:40 -08005607 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005611 }
5612
5613 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005614 * Sets the per-account voicemail ringtone.
5615 *
5616 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5617 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5618 *
5619 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5620 * voicemail ringtone.
5621 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5622 * PhoneAccount.
5623 */
5624 @Override
5625 public void setVoicemailRingtoneUri(String callingPackage,
5626 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005627 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005628 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5629 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005630 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5632 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5633 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005634 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5639 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005640 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005641 }
5642 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005645 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005646 }
5647
5648 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005649 * Returns whether vibration is set for voicemail notification in Phone settings.
5650 *
5651 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5652 * voicemail vibration setting.
5653 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5654 */
5655 @Override
5656 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005657 final long identity = Binder.clearCallingIdentity();
5658 try {
5659 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5660 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005661 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005662 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005663
Malcolm Chend965c8b2018-02-28 15:00:40 -08005664 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005668 }
5669
Youhan Wange64578a2016-05-02 15:32:42 -07005670 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005671 * Sets the per-account voicemail vibration.
5672 *
5673 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5674 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5675 *
5676 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5677 * voicemail vibration setting.
5678 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5679 * specific PhoneAccount.
5680 */
5681 @Override
5682 public void setVoicemailVibrationEnabled(String callingPackage,
5683 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005684 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005685 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5686 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005687 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5689 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5690 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005691 }
5692
Malcolm Chend965c8b2018-02-28 15:00:40 -08005693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5696 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005697 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005698 }
5699 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005702 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005703 }
5704
5705 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005706 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5707 *
5708 * @throws SecurityException if the caller does not have the required permission
5709 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005710 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005711 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005712 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005713 }
5714
5715 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005716 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5717 * permission.
5718 *
5719 * @throws SecurityException if the caller does not have the required permission
5720 */
5721 private void enforceSendSmsPermission() {
5722 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5723 }
5724
5725 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005726 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005727 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005728 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005729 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005730 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005734 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005735 if (componentName == null) {
5736 throw new SecurityException(
5737 "Caller not current active visual voicemail package[null]");
5738 }
5739 String vvmPackage = componentName.getPackageName();
5740 if (!callingPackage.equals(vvmPackage)) {
5741 throw new SecurityException("Caller not current active visual voicemail package["
5742 + vvmPackage + "]");
5743 }
5744 } finally {
5745 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005746 }
5747 }
5748
5749 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005750 * Return the application ID for the app type.
5751 *
5752 * @param subId the subscription ID that this request applies to.
5753 * @param appType the uicc app type.
5754 * @return Application ID for specificied app type, or null if no uicc.
5755 */
5756 @Override
5757 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005758 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005759 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005760
5761 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005762 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005763 if (phone == null) {
5764 return null;
5765 }
5766 String aid = null;
5767 try {
5768 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5769 .getApplicationByType(appType).getAid();
5770 } catch (Exception e) {
5771 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5772 }
5773 return aid;
5774 } finally {
5775 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005776 }
Youhan Wange64578a2016-05-02 15:32:42 -07005777 }
5778
Youhan Wang4001d252016-05-11 10:29:41 -07005779 /**
5780 * Return the Electronic Serial Number.
5781 *
5782 * @param subId the subscription ID that this request applies to.
5783 * @return ESN or null if error.
5784 */
5785 @Override
5786 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005787 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005788 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005789
5790 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005791 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005792 if (phone == null) {
5793 return null;
5794 }
5795 String esn = null;
5796 try {
5797 esn = phone.getEsn();
5798 } catch (Exception e) {
5799 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5800 }
5801 return esn;
5802 } finally {
5803 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005804 }
Youhan Wang4001d252016-05-11 10:29:41 -07005805 }
5806
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005807 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005808 * Return the Preferred Roaming List Version.
5809 *
5810 * @param subId the subscription ID that this request applies to.
5811 * @return PRLVersion or null if error.
5812 */
5813 @Override
5814 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005815 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005816 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005817
5818 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005819 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005820 if (phone == null) {
5821 return null;
5822 }
5823 String cdmaPrlVersion = null;
5824 try {
5825 cdmaPrlVersion = phone.getCdmaPrlVersion();
5826 } catch (Exception e) {
5827 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5828 }
5829 return cdmaPrlVersion;
5830 } finally {
5831 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005832 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005833 }
5834
5835 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005836 * Get snapshot of Telephony histograms
5837 * @return List of Telephony histograms
5838 * @hide
5839 */
5840 @Override
5841 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5843 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005844
5845 final long identity = Binder.clearCallingIdentity();
5846 try {
5847 return RIL.getTelephonyRILTimingHistograms();
5848 } finally {
5849 Binder.restoreCallingIdentity(identity);
5850 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005851 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005852
5853 /**
5854 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005855 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5856 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005857 * Require system privileges. In the future we may add this to carrier APIs.
5858 *
Michele Berionne0963c862018-11-27 18:57:59 -08005859 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005860 */
5861 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005862 @TelephonyManager.SetCarrierRestrictionResult
5863 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005864 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005865 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005866
Michele Berionne0963c862018-11-27 18:57:59 -08005867 if (carrierRestrictionRules == null) {
5868 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005869 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005870
Malcolm Chend965c8b2018-02-28 15:00:40 -08005871 final long identity = Binder.clearCallingIdentity();
5872 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005873 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005874 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005875 } finally {
5876 Binder.restoreCallingIdentity(identity);
5877 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005878 }
5879
5880 /**
5881 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005882 * Get the allowed carrier list and the excluded carrier list, including the priority between
5883 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005884 * Require system privileges. In the future we may add this to carrier APIs.
5885 *
Michele Berionne0963c862018-11-27 18:57:59 -08005886 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005887 */
5888 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005889 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005890 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005891 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005892
5893 final long identity = Binder.clearCallingIdentity();
5894 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005895 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5896 if (response instanceof CarrierRestrictionRules) {
5897 return (CarrierRestrictionRules) response;
5898 }
5899 // Response is an Exception of some kind,
5900 // which is signalled to the user as a NULL retval
5901 return null;
5902 } catch (Exception e) {
5903 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5904 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005905 } finally {
5906 Binder.restoreCallingIdentity(identity);
5907 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005908 }
5909
fionaxu59545b42016-05-25 15:53:37 -07005910 /**
5911 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5912 * @param subId the subscription ID that this action applies to.
5913 * @param enabled control enable or disable metered apns.
5914 * {@hide}
5915 */
5916 @Override
5917 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5918 enforceModifyPermission();
5919 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005920
5921 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005922 if (phone == null) {
5923 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5924 return;
5925 }
5926 try {
5927 phone.carrierActionSetMeteredApnsEnabled(enabled);
5928 } catch (Exception e) {
5929 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005930 } finally {
5931 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005932 }
5933 }
5934
5935 /**
5936 * Action set from carrier signalling broadcast receivers to enable/disable radio
5937 * @param subId the subscription ID that this action applies to.
5938 * @param enabled control enable or disable radio.
5939 * {@hide}
5940 */
5941 @Override
5942 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5943 enforceModifyPermission();
5944 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005945
5946 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005947 if (phone == null) {
5948 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5949 return;
5950 }
5951 try {
5952 phone.carrierActionSetRadioEnabled(enabled);
5953 } catch (Exception e) {
5954 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005957 }
5958 }
5959
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005960 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005961 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5962 * network status based on which carrier apps could apply actions accordingly,
5963 * enable/disable default url handler for example.
5964 *
5965 * @param subId the subscription ID that this action applies to.
5966 * @param report control start/stop reporting the default network status.
5967 * {@hide}
5968 */
5969 @Override
5970 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5971 enforceModifyPermission();
5972 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005973
5974 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005975 if (phone == null) {
5976 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5977 return;
5978 }
5979 try {
5980 phone.carrierActionReportDefaultNetworkStatus(report);
5981 } catch (Exception e) {
5982 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005983 } finally {
5984 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005985 }
5986 }
5987
5988 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005989 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5990 * bug report is being generated.
5991 */
5992 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005993 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005994 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5995 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005996 writer.println("Permission Denial: can't dump Phone from pid="
5997 + Binder.getCallingPid()
5998 + ", uid=" + Binder.getCallingUid()
5999 + "without permission "
6000 + android.Manifest.permission.DUMP);
6001 return;
6002 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006003 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006004 }
Jack Yueb89b242016-06-22 13:27:47 -07006005
Brad Ebingerdac2f002018-04-03 15:17:52 -07006006 @Override
6007 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6008 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6009 throws RemoteException {
6010 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6011 }
6012
Jack Yueb89b242016-06-22 13:27:47 -07006013 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006014 * Get aggregated video call data usage since boot.
6015 *
6016 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6017 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006018 * {@hide}
6019 */
6020 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006021 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006022 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6023 null);
6024
Malcolm Chend965c8b2018-02-28 15:00:40 -08006025 final long identity = Binder.clearCallingIdentity();
6026 try {
6027 // NetworkStatsService keeps tracking the active network interface and identity. It
6028 // records the delta with the corresponding network identity.
6029 // We just return the total video call data usage snapshot since boot.
6030 Phone phone = getPhone(subId);
6031 if (phone != null) {
6032 return phone.getVtDataUsage(perUidStats);
6033 }
6034 return null;
6035 } finally {
6036 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006037 }
Jack Yueb89b242016-06-22 13:27:47 -07006038 }
Jack Yu75ab2952016-07-08 14:29:33 -07006039
6040 /**
6041 * Policy control of data connection. Usually used when data limit is passed.
6042 * @param enabled True if enabling the data, otherwise disabling.
6043 * @param subId Subscription index
6044 * {@hide}
6045 */
6046 @Override
6047 public void setPolicyDataEnabled(boolean enabled, int subId) {
6048 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006049
6050 final long identity = Binder.clearCallingIdentity();
6051 try {
6052 Phone phone = getPhone(subId);
6053 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006054 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006055 }
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006058 }
6059 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006060
6061 /**
6062 * Get Client request stats
6063 * @return List of Client Request Stats
6064 * @hide
6065 */
6066 @Override
6067 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006069 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006070 return null;
6071 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006072 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006073
Malcolm Chend965c8b2018-02-28 15:00:40 -08006074 final long identity = Binder.clearCallingIdentity();
6075 try {
6076 if (phone != null) {
6077 return phone.getClientRequestStats();
6078 }
6079
6080 return null;
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006084 }
6085
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006086 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006087 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006088 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006089 }
Jack Yueb4124c2017-02-16 15:32:43 -08006090
6091 /**
Grace Chen70990072017-03-24 17:21:30 -07006092 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006093 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006094 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006095 * @param state State of SIM (power down, power up, pass through)
6096 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6097 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6098 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006099 *
6100 **/
6101 @Override
Grace Chen70990072017-03-24 17:21:30 -07006102 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006103 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006104 Phone phone = PhoneFactory.getPhone(slotIndex);
6105
vagdevie435a3e2018-08-15 16:01:53 -07006106 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6107
Malcolm Chend965c8b2018-02-28 15:00:40 -08006108 final long identity = Binder.clearCallingIdentity();
6109 try {
6110 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006111 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006112 }
6113 } finally {
6114 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006115 }
6116 }
Shuo Qiandd210312017-04-12 22:11:33 +00006117
Tyler Gunn65d45c22017-06-05 11:22:26 -07006118 private boolean isUssdApiAllowed(int subId) {
6119 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006120 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006121 if (configManager == null) {
6122 return false;
6123 }
6124 PersistableBundle pb = configManager.getConfigForSubId(subId);
6125 if (pb == null) {
6126 return false;
6127 }
6128 return pb.getBoolean(
6129 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6130 }
6131
Shuo Qiandd210312017-04-12 22:11:33 +00006132 /**
6133 * Check if phone is in emergency callback mode
6134 * @return true if phone is in emergency callback mode
6135 * @param subId sub id
6136 */
goneil9c5f4872017-12-05 14:07:56 -08006137 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006138 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006139 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006140 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006141
6142 final long identity = Binder.clearCallingIdentity();
6143 try {
6144 if (phone != null) {
6145 return phone.isInEcm();
6146 } else {
6147 return false;
6148 }
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006151 }
6152 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006153
6154 /**
6155 * Get the current signal strength information for the given subscription.
6156 * Because this information is not updated when the device is in a low power state
6157 * it should not be relied-upon to be current.
6158 * @param subId Subscription index
6159 * @return the most recent cached signal strength info from the modem
6160 */
6161 @Override
6162 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006163 final long identity = Binder.clearCallingIdentity();
6164 try {
6165 Phone p = getPhone(subId);
6166 if (p == null) {
6167 return null;
6168 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006169
Malcolm Chend965c8b2018-02-28 15:00:40 -08006170 return p.getSignalStrength();
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006174 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006175
Pengquan Meng9140aec2018-08-22 14:49:57 -07006176 /**
chen xu907e5a22018-10-11 13:21:04 -07006177 * Get the current modem radio state for the given slot.
6178 * @param slotIndex slot index.
6179 * @param callingPackage the name of the package making the call.
6180 * @return the current radio power state from the modem
6181 */
6182 @Override
6183 public int getRadioPowerState(int slotIndex, String callingPackage) {
6184 Phone phone = PhoneFactory.getPhone(slotIndex);
6185 if (phone != null) {
6186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6187 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6188 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6189 }
6190
6191 final long identity = Binder.clearCallingIdentity();
6192 try {
6193 return phone.getRadioPowerState();
6194 } finally {
6195 Binder.restoreCallingIdentity(identity);
6196 }
6197 }
6198 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6199 }
6200
6201 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006202 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6203 *
6204 * <p>Requires one of the following permissions:
6205 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6206 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6207 * privileges.
6208 *
6209 * @param subId subscription id
6210 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6211 * {@code false}.
6212 */
6213 @Override
6214 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006215 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6216 null /* message */);
6217
Pengquan Meng0c05b502018-09-06 09:59:22 -07006218 boolean isEnabled = false;
6219 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006220 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006221 Phone phone = getPhone(subId);
6222 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006223 } catch (Exception e) {
6224 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6225 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006226 } finally {
6227 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006228 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006229 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006230 }
6231
6232
6233 /**
6234 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6235 *
6236 * <p> Requires permission:
6237 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6238 * privileges.
6239 *
6240 * @param subId subscription id
6241 * @param isEnabled {@code true} means enable, {@code false} means disable.
6242 */
6243 @Override
6244 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6246 mApp, subId, "setDataRoamingEnabled");
6247
Pengquan Meng0c05b502018-09-06 09:59:22 -07006248 final long identity = Binder.clearCallingIdentity();
6249 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006250 Phone phone = getPhone(subId);
6251 if (phone != null) {
6252 phone.setDataRoamingEnabled(isEnabled);
6253 }
6254 } finally {
6255 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006256 }
6257 }
6258
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006259 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006260 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006261 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6262 mApp, subId, "isManualNetworkSelectionAllowed");
6263
Pengquan Meng312de0c2018-10-03 12:19:13 -07006264 boolean isAllowed = true;
6265 final long identity = Binder.clearCallingIdentity();
6266 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006267 Phone phone = getPhone(subId);
6268 if (phone != null) {
6269 isAllowed = phone.isCspPlmnEnabled();
6270 }
6271 } finally {
6272 Binder.restoreCallingIdentity(identity);
6273 }
6274 return isAllowed;
6275 }
6276
6277 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006278 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006279 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006280 try {
6281 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006282 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006283 } catch (SecurityException e) {
6284 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6285 // has carrier privileges on an active UICC
6286 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6287 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006288 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006289 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006290 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006291
6292 final long identity = Binder.clearCallingIdentity();
6293 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006294 UiccController uiccController = UiccController.getInstance();
6295 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006296 if (hasReadPermission) {
6297 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006298 }
Jordan Liu67997952019-04-22 15:10:43 -07006299
6300 // Remove private info if the caller doesn't have access
6301 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6302 for (UiccCardInfo cardInfo : cardInfos) {
6303 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6304 // is available
6305 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6306 if (card == null || card.getUiccProfile() == null) {
6307 // assume no access if the card or profile is unavailable
6308 filteredInfos.add(cardInfo.getUnprivileged());
6309 continue;
6310 }
6311 UiccProfile profile = card.getUiccProfile();
6312 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6313 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6314 filteredInfos.add(cardInfo);
6315 } else {
6316 filteredInfos.add(cardInfo.getUnprivileged());
6317 }
6318 }
6319 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006320 } finally {
6321 Binder.restoreCallingIdentity(identity);
6322 }
6323 }
6324
6325 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006326 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006327 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006328
Malcolm Chend965c8b2018-02-28 15:00:40 -08006329 final long identity = Binder.clearCallingIdentity();
6330 try {
6331 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6332 if (slots == null) {
6333 Rlog.i(LOG_TAG, "slots is null.");
6334 return null;
6335 }
6336
6337 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6338 for (int i = 0; i < slots.length; i++) {
6339 UiccSlot slot = slots[i];
6340 if (slot == null) {
6341 continue;
6342 }
6343
6344 String cardId;
6345 UiccCard card = slot.getUiccCard();
6346 if (card != null) {
6347 cardId = card.getCardId();
6348 } else {
6349 cardId = slot.getIccId();
6350 }
6351
6352 int cardState = 0;
6353 switch (slot.getCardState()) {
6354 case CARDSTATE_ABSENT:
6355 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6356 break;
6357 case CARDSTATE_PRESENT:
6358 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6359 break;
6360 case CARDSTATE_ERROR:
6361 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6362 break;
6363 case CARDSTATE_RESTRICTED:
6364 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6365 break;
6366 default:
6367 break;
6368
6369 }
6370
6371 infos[i] = new UiccSlotInfo(
6372 slot.isActive(),
6373 slot.isEuicc(),
6374 cardId,
6375 cardState,
6376 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006377 slot.isExtendedApduSupported(),
6378 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006379 }
6380 return infos;
6381 } finally {
6382 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006383 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006384 }
6385
6386 @Override
6387 public boolean switchSlots(int[] physicalSlots) {
6388 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006389
6390 final long identity = Binder.clearCallingIdentity();
6391 try {
6392 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6393 } finally {
6394 Binder.restoreCallingIdentity(identity);
6395 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006396 }
Jack Yu4c988042018-02-27 15:30:01 -08006397
6398 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006399 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006400 final long identity = Binder.clearCallingIdentity();
6401 try {
6402 return UiccController.getInstance().getCardIdForDefaultEuicc();
6403 } finally {
6404 Binder.restoreCallingIdentity(identity);
6405 }
6406 }
6407
6408 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006409 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6410 enforceModifyPermission();
6411 final Phone phone = getPhone(subId);
6412 if (phone == null) {
6413 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6414 return;
6415 }
6416
Malcolm Chend965c8b2018-02-28 15:00:40 -08006417 final long identity = Binder.clearCallingIdentity();
6418 try {
6419 phone.setRadioIndicationUpdateMode(filters, mode);
6420 } finally {
6421 Binder.restoreCallingIdentity(identity);
6422 }
Jack Yu4c988042018-02-27 15:30:01 -08006423 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006424
6425 /**
goneil47ffb6e2018-04-06 15:40:58 -07006426 * A test API to reload the UICC profile.
6427 *
6428 * <p>Requires that the calling app has permission
6429 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6430 * @hide
6431 */
6432 @Override
6433 public void refreshUiccProfile(int subId) {
6434 enforceModifyPermission();
6435
6436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 Phone phone = getPhone(subId);
6439 if (phone == null) {
6440 return;
6441 }
6442 UiccCard uiccCard = phone.getUiccCard();
6443 if (uiccCard == null) {
6444 return;
6445 }
6446 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6447 if (uiccProfile == null) {
6448 return;
6449 }
6450 uiccProfile.refresh();
6451 } finally {
6452 Binder.restoreCallingIdentity(identity);
6453 }
6454 }
6455
6456 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006457 * Returns false if the mobile data is disabled by default, otherwise return true.
6458 */
6459 private boolean getDefaultDataEnabled() {
6460 return "true".equalsIgnoreCase(
6461 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6462 }
6463
6464 /**
6465 * Returns true if the data roaming is enabled by default, i.e the system property
6466 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6467 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6468 */
6469 private boolean getDefaultDataRoamingEnabled(int subId) {
6470 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006471 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006472 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6473 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6474 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6475 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6476 return isDataRoamingEnabled;
6477 }
6478
6479 /**
6480 * Returns the default network type for the given {@code subId}, if the default network type is
6481 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6482 */
6483 private int getDefaultNetworkType(int subId) {
6484 return Integer.parseInt(
6485 TelephonyManager.getTelephonyProperty(
6486 mSubscriptionController.getPhoneId(subId),
6487 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6488 String.valueOf(Phone.PREFERRED_NT_MODE)));
6489 }
fionaxua13278b2018-03-21 00:08:13 -07006490
6491 @Override
6492 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6493 gid1, String gid2, String plmn, String spn) {
6494 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006495
6496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 final Phone phone = getPhone(subId);
6499 if (phone == null) {
6500 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6501 return;
6502 }
6503 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6504 } finally {
6505 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006506 }
fionaxua13278b2018-03-21 00:08:13 -07006507 }
6508
6509 @Override
6510 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006511 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006512
6513 final long identity = Binder.clearCallingIdentity();
6514 try {
6515 final Phone phone = getPhone(subId);
6516 if (phone == null) {
6517 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6518 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6519 }
6520 return phone.getCarrierIdListVersion();
6521 } finally {
6522 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006523 }
fionaxua13278b2018-03-21 00:08:13 -07006524 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006525
6526 @Override
6527 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6529 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6530 return -1;
6531 }
6532
6533 final long identity = Binder.clearCallingIdentity();
6534 try {
6535 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6536 } finally {
6537 Binder.restoreCallingIdentity(identity);
6538 }
6539 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006540
6541 @Override
6542 public int getCdmaRoamingMode(int subId) {
6543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6544 mApp, subId, "getCdmaRoamingMode");
6545
6546 final long identity = Binder.clearCallingIdentity();
6547 try {
6548 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
6552 }
6553
6554 @Override
6555 public boolean setCdmaRoamingMode(int subId, int mode) {
6556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6557 mApp, subId, "setCdmaRoamingMode");
6558
6559 final long identity = Binder.clearCallingIdentity();
6560 try {
6561 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
6565 }
6566
6567 @Override
6568 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6570 mApp, subId, "setCdmaSubscriptionMode");
6571
6572 final long identity = Binder.clearCallingIdentity();
6573 try {
6574 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6575 } finally {
6576 Binder.restoreCallingIdentity(identity);
6577 }
6578 }
chen xu7ee67862018-10-30 22:27:10 -07006579
sqian2fff4a32018-11-05 14:18:37 -08006580 private void ensureUserRunning(int userId) {
6581 if (!mUserManager.isUserRunning(userId)) {
6582 throw new IllegalStateException("User " + userId + " does not exist or not running");
6583 }
6584 }
6585
6586 /**
6587 * Returns a list of SMS apps on a given user.
6588 *
6589 * Only the shell user (UID 2000 or 0) can call it.
6590 * Target user must be running.
6591 */
6592 @Override
6593 public String[] getSmsApps(int userId) {
6594 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6595 ensureUserRunning(userId);
6596
6597 final Collection<SmsApplicationData> apps =
6598 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6599
6600 String[] ret = new String[apps.size()];
6601 int i = 0;
6602 for (SmsApplicationData app : apps) {
6603 ret[i++] = app.mPackageName;
6604 }
6605 return ret;
6606 }
6607
6608 /**
6609 * Returns the default SMS app package name on a given user.
6610 *
6611 * Only the shell user (UID 2000 or 0) can call it.
6612 * Target user must be running.
6613 */
6614 @Override
6615 public String getDefaultSmsApp(int userId) {
6616 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6617 ensureUserRunning(userId);
6618
6619 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6620 /* updateIfNeeded= */ true, userId);
6621 return cn == null ? null : cn.getPackageName();
6622 }
6623
6624 /**
6625 * Set a package as the default SMS app on a given user.
6626 *
6627 * Only the shell user (UID 2000 or 0) can call it.
6628 * Target user must be running.
6629 */
6630 @Override
6631 public void setDefaultSmsApp(int userId, String packageName) {
6632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6633 ensureUserRunning(userId);
6634
6635 boolean found = false;
6636 for (String pkg : getSmsApps(userId)) {
6637 if (TextUtils.equals(packageName, pkg)) {
6638 found = true;
6639 break;
6640 }
6641 }
6642 if (!found) {
6643 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6644 }
6645
6646 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6647 }
6648
chen xu7ee67862018-10-30 22:27:10 -07006649 @Override
sqian65eefe12019-02-22 15:55:18 -08006650 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006651 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006653 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006654 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6655 }
6656 final long identity = Binder.clearCallingIdentity();
6657 try {
sqian991b35e2018-12-12 16:48:18 -08006658 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6659 for (Phone phone: PhoneFactory.getPhones()) {
6660 if (phone.getEmergencyNumberTracker() != null
6661 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6662 emergencyNumberListInternal.put(
6663 phone.getSubId(),
6664 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6665 }
sqian03bca152018-12-05 18:48:28 -08006666 }
sqian991b35e2018-12-12 16:48:18 -08006667 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006668 } finally {
6669 Binder.restoreCallingIdentity(identity);
6670 }
sqian04b86072018-11-07 14:02:21 -08006671 }
6672
6673 @Override
sqian65eefe12019-02-22 15:55:18 -08006674 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006675 final Phone defaultPhone = getDefaultPhone();
6676 if (!exactMatch) {
6677 TelephonyPermissions
6678 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006679 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006680 }
6681 final long identity = Binder.clearCallingIdentity();
6682 try {
sqian991b35e2018-12-12 16:48:18 -08006683 for (Phone phone: PhoneFactory.getPhones()) {
6684 if (phone.getEmergencyNumberTracker() != null
6685 && phone.getEmergencyNumberTracker() != null) {
6686 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6687 number, exactMatch)) {
6688 return true;
sqian03bca152018-12-05 18:48:28 -08006689 }
6690 }
sqian03bca152018-12-05 18:48:28 -08006691 }
6692 return false;
6693 } finally {
6694 Binder.restoreCallingIdentity(identity);
6695 }
6696 }
6697
sqian9d4df8b2019-01-15 18:32:07 -08006698 /**
6699 * Update emergency number list for test mode.
6700 */
6701 @Override
6702 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6704 "updateEmergencyNumberListTestMode");
6705
6706 final long identity = Binder.clearCallingIdentity();
6707 try {
6708 for (Phone phone: PhoneFactory.getPhones()) {
6709 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6710 if (tracker != null) {
6711 tracker.executeEmergencyNumberTestModeCommand(action, num);
6712 }
6713 }
6714 } finally {
6715 Binder.restoreCallingIdentity(identity);
6716 }
6717 }
6718
6719 /**
6720 * Get the full emergency number list for test mode.
6721 */
6722 @Override
6723 public List<String> getEmergencyNumberListTestMode() {
6724 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6725 "getEmergencyNumberListTestMode");
6726
6727 final long identity = Binder.clearCallingIdentity();
6728 try {
6729 Set<String> emergencyNumbers = new HashSet<>();
6730 for (Phone phone: PhoneFactory.getPhones()) {
6731 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6732 if (tracker != null) {
6733 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6734 emergencyNumbers.add(num.getNumber());
6735 }
6736 }
6737 }
6738 return new ArrayList<>(emergencyNumbers);
6739 } finally {
6740 Binder.restoreCallingIdentity(identity);
6741 }
6742 }
6743
sqian04b86072018-11-07 14:02:21 -08006744 @Override
chen xu7ee67862018-10-30 22:27:10 -07006745 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6746 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6747 Phone phone = getPhone(subId);
6748 if (phone == null) {
6749 return null;
6750 }
6751 final long identity = Binder.clearCallingIdentity();
6752 try {
6753 UiccProfile profile = UiccController.getInstance()
6754 .getUiccProfileForPhone(phone.getPhoneId());
6755 if (profile != null) {
6756 return profile.getCertsFromCarrierPrivilegeAccessRules();
6757 }
6758 } finally {
6759 Binder.restoreCallingIdentity(identity);
6760 }
6761 return null;
6762 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006763
6764 /**
6765 * Enable or disable a modem stack.
6766 */
6767 @Override
6768 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6769 enforceModifyPermission();
6770
6771 final long identity = Binder.clearCallingIdentity();
6772 try {
6773 Phone phone = PhoneFactory.getPhone(slotIndex);
6774 if (phone == null) {
6775 return false;
6776 } else {
6777 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6778 }
6779 } finally {
6780 Binder.restoreCallingIdentity(identity);
6781 }
6782 }
Micheled3107c52018-12-21 15:00:11 -08006783
Malcolm Chen33f55e12019-03-27 18:34:05 -07006784 /**
6785 * Whether a modem stack is enabled or not.
6786 */
6787 @Override
6788 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6789 Phone phone = PhoneFactory.getPhone(slotIndex);
6790 if (phone == null) return false;
6791
6792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6793 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6794 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6795 }
6796
6797 final long identity = Binder.clearCallingIdentity();
6798 try {
6799 return PhoneConfigurationManager.getInstance().getPhoneStatus(phone);
6800 } finally {
6801 Binder.restoreCallingIdentity(identity);
6802 }
6803 }
6804
Micheled3107c52018-12-21 15:00:11 -08006805 @Override
Michele2fb0f222019-03-19 14:58:42 -07006806 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006807 enforceModifyPermission();
6808
6809 final long identity = Binder.clearCallingIdentity();
6810 try {
6811 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006812 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006813 .commit();
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
6816 }
6817 }
6818
6819 @Override
Michele2fb0f222019-03-19 14:58:42 -07006820 @TelephonyManager.IsMultiSimSupportedResult
6821 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006823 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6824 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006825 }
Micheled3107c52018-12-21 15:00:11 -08006826
6827 final long identity = Binder.clearCallingIdentity();
6828 try {
Michele2fb0f222019-03-19 14:58:42 -07006829 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006830 } finally {
6831 Binder.restoreCallingIdentity(identity);
6832 }
6833 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006834
Michele2fb0f222019-03-19 14:58:42 -07006835 @TelephonyManager.IsMultiSimSupportedResult
6836 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006837 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6838 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6839 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006840 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6841 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006842 }
6843 // Check if the hardware supports multisim functionality. If usage of multisim is not
6844 // supported by the modem, indicate that it is restricted.
6845 PhoneCapability staticCapability =
6846 mPhoneConfigurationManager.getStaticPhoneCapability();
6847 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006848 loge("isMultiSimSupportedInternal: no static configuration available");
6849 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006850 }
6851 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006852 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6853 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006854 }
6855 // Check if support of multiple SIMs is restricted by carrier
6856 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006857 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006858 }
6859
Michele2fb0f222019-03-19 14:58:42 -07006860 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006861 }
6862
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006863 /**
6864 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006865 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6866 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6867 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006868 * @param numOfSims number of active sims we want to switch to
6869 */
6870 @Override
6871 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006872 if (numOfSims == 1) {
6873 enforceModifyPermission();
6874 } else {
6875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6876 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6877 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006878 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006879
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006880 try {
Michele30b57b22019-03-01 12:01:14 -08006881 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006882 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006883 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6884 return;
6885 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006886 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6887 } finally {
6888 Binder.restoreCallingIdentity(identity);
6889 }
6890 }
6891
6892 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006893 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006894 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006895 */
6896 @Override
6897 public boolean isRebootRequiredForModemConfigChange() {
6898 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6899 final long identity = Binder.clearCallingIdentity();
6900 try {
6901 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6902 } finally {
6903 Binder.restoreCallingIdentity(identity);
6904 }
6905 }
6906
Pengquan Meng92d253b2019-02-06 11:12:53 -08006907 private void updateModemStateMetrics() {
6908 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6909 // TODO: check the state for each modem if the api is ready.
6910 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6911 }
6912
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006913 @Override
6914 public int[] getSlotsMapping() {
6915 enforceReadPrivilegedPermission("getSlotsMapping");
6916
6917 final long identity = Binder.clearCallingIdentity();
6918 try {
6919 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6920 // All logical slots should have a mapping to a physical slot.
6921 int[] logicalSlotsMapping = new int[phoneCount];
6922 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6923 for (int i = 0; i < slotInfos.length; i++) {
6924 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6925 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6926 }
6927 }
6928 return logicalSlotsMapping;
6929 } finally {
6930 Binder.restoreCallingIdentity(identity);
6931 }
6932 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006933
6934 /**
6935 * Get the IRadio HAL Version
6936 */
6937 @Override
6938 public int getRadioHalVersion() {
6939 Phone phone = getDefaultPhone();
6940 if (phone == null) return -1;
6941 HalVersion hv = phone.getHalVersion();
6942 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6943 return hv.major * 100 + hv.minor;
6944 }
Malcolm Chen460810d2019-04-10 18:25:07 -07006945
6946 /**
Malcolm Chen29739692019-04-18 13:51:02 -07006947 * Return whether data is enabled for certain APN type. This will tell if framework will accept
6948 * corresponding network requests on a subId.
6949 *
6950 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07006951 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07006952 * 2) APN is un-metered for this subscription, or
6953 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
6954 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
6955 *
6956 * @return whether data is allowed for a apn type.
6957 *
6958 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07006959 */
6960 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07006961 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07006962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07006963 mApp, subId, callingPackage, "isDataEnabledForApn")) {
6964 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07006965 }
6966
6967 // Now that all security checks passes, perform the operation as ourselves.
6968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 Phone phone = getPhone(subId);
6971 if (phone == null) return false;
6972
6973 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chen29739692019-04-18 13:51:02 -07006974 apnType), phone);
6975 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
6976 } finally {
6977 Binder.restoreCallingIdentity(identity);
6978 }
6979 }
6980
6981 @Override
6982 public boolean isApnMetered(int apnType, int subId) {
6983 enforceReadPrivilegedPermission("isApnMetered");
6984
6985 // Now that all security checks passes, perform the operation as ourselves.
6986 final long identity = Binder.clearCallingIdentity();
6987 try {
6988 Phone phone = getPhone(subId);
6989 if (phone == null) return true; // By default return true.
6990
6991 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
6992 apnType), phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07006993 } finally {
6994 Binder.restoreCallingIdentity(identity);
6995 }
6996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006997}