blob: 46c2847f6263984d04ff0c53afc20e8b3f96be69 [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 }
yinxu612a8192019-04-18 10:38:27 -07004452 final long identity = Binder.clearCallingIdentity();
4453 try {
4454 return mNetworkScanRequestTracker.startNetworkScan(
4455 request, messenger, binder, getPhone(subId),
4456 callingPackage);
4457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
yinxu504e1392017-04-12 16:03:22 -07004460 }
4461
Hall Liub2ac8ef2019-02-28 15:56:23 -08004462 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4463 NetworkScanRequest request) {
4464 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4465 != PERMISSION_GRANTED) {
4466 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4467 + " without location access.");
4468 }
4469
4470 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4471 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004472 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4473 return new SecurityException("Specific channels must not be"
4474 + " scanned without location access.");
4475 }
4476 }
4477 }
4478
Hall Liub2ac8ef2019-02-28 15:56:23 -08004479 return null;
4480 }
4481
yinxu504e1392017-04-12 16:03:22 -07004482 /**
4483 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004484 *
4485 * @param subId id of the subscription
4486 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004487 */
4488 @Override
4489 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4491 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004492
4493 final long identity = Binder.clearCallingIdentity();
4494 try {
4495 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4496 } finally {
4497 Binder.restoreCallingIdentity(identity);
4498 }
yinxu504e1392017-04-12 16:03:22 -07004499 }
4500
4501 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004502 * Get the calculated preferred network type.
4503 * Used for debugging incorrect network type.
4504 *
4505 * @return the preferred network type, defined in RILConstants.java.
4506 */
4507 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004508 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004509 final Phone defaultPhone = getDefaultPhone();
4510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4511 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004512 return RILConstants.PREFERRED_NETWORK_MODE;
4513 }
4514
Malcolm Chend965c8b2018-02-28 15:00:40 -08004515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004518 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004519 } finally {
4520 Binder.restoreCallingIdentity(identity);
4521 }
Junda Liu84d15a22014-07-02 11:21:04 -07004522 }
4523
4524 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004525 * Get the preferred network type.
4526 * Used for device configuration by some CDMA operators.
4527 *
4528 * @return the preferred network type, defined in RILConstants.java.
4529 */
4530 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004531 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004532 TelephonyPermissions
4533 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4534 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004535
4536 final long identity = Binder.clearCallingIdentity();
4537 try {
4538 if (DBG) log("getPreferredNetworkType");
4539 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4540 int networkType = (result != null ? result[0] : -1);
4541 if (DBG) log("getPreferredNetworkType: " + networkType);
4542 return networkType;
4543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004546 }
4547
4548 /**
4549 * Set the preferred network type.
4550 * Used for device configuration by some CDMA operators.
4551 *
4552 * @param networkType the preferred network type, defined in RILConstants.java.
4553 * @return true on success; false on any failure.
4554 */
4555 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004556 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4558 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004559
4560 final long identity = Binder.clearCallingIdentity();
4561 try {
4562 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4563 Boolean success = (Boolean) sendRequest(
4564 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4565 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4566 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004567 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004568 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4569 }
4570 return success;
4571 } finally {
4572 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004573 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004574 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004575
4576 /**
Miaoa84611c2019-03-15 09:21:10 +08004577 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004578 *
Miaoa84611c2019-03-15 09:21:10 +08004579 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004580 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004581 * @hide
4582 */
4583 @Override
Miaoa84611c2019-03-15 09:21:10 +08004584 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004585 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004586 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004587 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004588 try {
Miaoa84611c2019-03-15 09:21:10 +08004589 if (phone != null) {
4590 return phone.hasMatchedTetherApnSetting();
4591 } else {
4592 return false;
4593 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004594 } finally {
4595 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004596 }
Junda Liu475951f2014-11-07 16:45:03 -08004597 }
4598
4599 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004600 * Set mobile data enabled
4601 * Used by the user through settings etc to turn on/off mobile data
4602 *
4603 * @param enable {@code true} turn turn data on, else {@code false}
4604 */
4605 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004606 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4608 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004609
4610 final long identity = Binder.clearCallingIdentity();
4611 try {
4612 int phoneId = mSubscriptionController.getPhoneId(subId);
4613 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4614 Phone phone = PhoneFactory.getPhone(phoneId);
4615 if (phone != null) {
4616 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004617 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004618 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004619 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004620 }
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004623 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004624 }
4625
4626 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004627 * Get the user enabled state of Mobile Data.
4628 *
4629 * TODO: remove and use isUserDataEnabled.
4630 * This can't be removed now because some vendor codes
4631 * calls through ITelephony directly while they should
4632 * use TelephonyManager.
4633 *
4634 * @return true on enabled
4635 */
4636 @Override
4637 public boolean getDataEnabled(int subId) {
4638 return isUserDataEnabled(subId);
4639 }
4640
4641 /**
4642 * Get whether mobile data is enabled per user setting.
4643 *
4644 * There are other factors deciding whether mobile data is actually enabled, but they are
4645 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004646 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004647 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004648 *
4649 * @return {@code true} if data is enabled else {@code false}
4650 */
4651 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004652 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004653 try {
4654 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4655 null);
4656 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4658 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004659 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004660
4661 final long identity = Binder.clearCallingIdentity();
4662 try {
4663 int phoneId = mSubscriptionController.getPhoneId(subId);
4664 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4665 Phone phone = PhoneFactory.getPhone(phoneId);
4666 if (phone != null) {
4667 boolean retVal = phone.isUserDataEnabled();
4668 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4669 return retVal;
4670 } else {
4671 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4672 return false;
4673 }
4674 } finally {
4675 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004676 }
4677 }
4678
4679 /**
4680 * Get whether mobile data is enabled.
4681 *
4682 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4683 * whether mobile data is actually enabled.
4684 *
4685 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4686 *
4687 * @return {@code true} if data is enabled else {@code false}
4688 */
4689 @Override
4690 public boolean isDataEnabled(int subId) {
4691 try {
4692 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4693 null);
4694 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4696 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004697 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004698
4699 final long identity = Binder.clearCallingIdentity();
4700 try {
4701 int phoneId = mSubscriptionController.getPhoneId(subId);
4702 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4703 Phone phone = PhoneFactory.getPhone(phoneId);
4704 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004705 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004706 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4707 return retVal;
4708 } else {
4709 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4710 return false;
4711 }
4712 } finally {
4713 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004714 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004715 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004716
4717 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004718 public int getCarrierPrivilegeStatus(int subId) {
4719 final Phone phone = getPhone(subId);
4720 if (phone == null) {
4721 loge("getCarrierPrivilegeStatus: Invalid subId");
4722 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4723 }
4724 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004725 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004726 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004727 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4728 }
4729 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004730 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004731 }
Junda Liu29340342014-07-10 15:23:27 -07004732
4733 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4735 final Phone phone = getPhone(subId);
4736 if (phone == null) {
4737 loge("getCarrierPrivilegeStatus: Invalid subId");
4738 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4739 }
4740 UiccProfile profile =
4741 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4742 if (profile == null) {
4743 loge("getCarrierPrivilegeStatus: No UICC");
4744 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4745 }
4746 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4747 }
4748
4749 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004750 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004751 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004752 if (TextUtils.isEmpty(pkgName))
4753 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004754 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004755 if (card == null) {
4756 loge("checkCarrierPrivilegesForPackage: No UICC");
4757 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4758 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004759 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4760 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004761 }
4762
4763 @Override
4764 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004765 if (TextUtils.isEmpty(pkgName))
4766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004767 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4768 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4769 UiccCard card = UiccController.getInstance().getUiccCard(i);
4770 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004771 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004772 continue;
4773 }
4774
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004775 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004776 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4777 break;
4778 }
4779 }
4780
4781 return result;
Junda Liu29340342014-07-10 15:23:27 -07004782 }
Derek Tan89e89d42014-07-08 17:00:10 -07004783
4784 @Override
Junda Liue64de782015-04-16 17:19:16 -07004785 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4786 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4787 loge("phoneId " + phoneId + " is not valid.");
4788 return null;
4789 }
4790 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004791 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004792 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004793 return null ;
4794 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004795 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004796 }
4797
Amith Yamasani6e118872016-02-19 12:53:51 -08004798 @Override
4799 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004800 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004801 List<String> privilegedPackages = new ArrayList<>();
4802 List<PackageInfo> packages = null;
4803 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4804 UiccCard card = UiccController.getInstance().getUiccCard(i);
4805 if (card == null) {
4806 // No UICC in that slot.
4807 continue;
4808 }
4809 if (card.hasCarrierPrivilegeRules()) {
4810 if (packages == null) {
4811 // Only check packages in user 0 for now
4812 packages = pm.getInstalledPackagesAsUser(
4813 PackageManager.MATCH_DISABLED_COMPONENTS
4814 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4815 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4816 }
4817 for (int p = packages.size() - 1; p >= 0; p--) {
4818 PackageInfo pkgInfo = packages.get(p);
4819 if (pkgInfo != null && pkgInfo.packageName != null
4820 && card.getCarrierPrivilegeStatus(pkgInfo)
4821 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4822 privilegedPackages.add(pkgInfo.packageName);
4823 }
4824 }
4825 }
4826 }
4827 return privilegedPackages;
4828 }
4829
Wink Savilleb564aae2014-10-23 10:18:09 -07004830 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004831 final Phone phone = getPhone(subId);
4832 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004833 if (card == null) {
4834 loge("getIccId: No UICC");
4835 return null;
4836 }
4837 String iccId = card.getIccId();
4838 if (TextUtils.isEmpty(iccId)) {
4839 loge("getIccId: ICC ID is null or empty.");
4840 return null;
4841 }
4842 return iccId;
4843 }
4844
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004845 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004846 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4847 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004848 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4849 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004850
Malcolm Chend965c8b2018-02-28 15:00:40 -08004851 final long identity = Binder.clearCallingIdentity();
4852 try {
4853 final String iccId = getIccId(subId);
4854 final Phone phone = getPhone(subId);
4855 if (phone == null) {
4856 return false;
4857 }
4858 final String subscriberId = phone.getSubscriberId();
4859
4860 if (DBG_MERGE) {
4861 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4862 + subscriberId + " to " + number);
4863 }
4864
4865 if (TextUtils.isEmpty(iccId)) {
4866 return false;
4867 }
4868
4869 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4870
4871 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4872 if (alphaTag == null) {
4873 editor.remove(alphaTagPrefKey);
4874 } else {
4875 editor.putString(alphaTagPrefKey, alphaTag);
4876 }
4877
4878 // Record both the line number and IMSI for this ICCID, since we need to
4879 // track all merged IMSIs based on line number
4880 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4881 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4882 if (number == null) {
4883 editor.remove(numberPrefKey);
4884 editor.remove(subscriberPrefKey);
4885 } else {
4886 editor.putString(numberPrefKey, number);
4887 editor.putString(subscriberPrefKey, subscriberId);
4888 }
4889
4890 editor.commit();
4891 return true;
4892 } finally {
4893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004894 }
Derek Tan7226c842014-07-02 17:42:23 -07004895 }
4896
4897 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004898 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004899 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004901 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004902 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004903 return null;
4904 }
Derek Tan97ebb422014-09-05 16:55:38 -07004905
Malcolm Chend965c8b2018-02-28 15:00:40 -08004906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 String iccId = getIccId(subId);
4909 if (iccId != null) {
4910 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4911 if (DBG_MERGE) {
4912 log("getLine1NumberForDisplay returning "
4913 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4914 }
4915 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004916 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004917 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4918 return null;
4919 } finally {
4920 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004921 }
Derek Tan7226c842014-07-02 17:42:23 -07004922 }
4923
4924 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004925 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004927 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004928 return null;
4929 }
Derek Tan97ebb422014-09-05 16:55:38 -07004930
Malcolm Chend965c8b2018-02-28 15:00:40 -08004931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 String iccId = getIccId(subId);
4934 if (iccId != null) {
4935 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4936 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4937 }
4938 return null;
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004941 }
Derek Tan7226c842014-07-02 17:42:23 -07004942 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004943
4944 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004945 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004946 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4947 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004948 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004949 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4950 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004951 return null;
4952 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004953
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004954 final long identity = Binder.clearCallingIdentity();
4955 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004956 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004957 final TelephonyManager tele = TelephonyManager.from(context);
4958 final SubscriptionManager sub = SubscriptionManager.from(context);
4959
4960 // Figure out what subscribers are currently active
4961 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4962 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4963 // the process, where TelephonyManager was instantiated.
4964 // Otherwise AppOps check will fail.
4965
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004966 final int[] subIds = sub.getActiveSubscriptionIdList();
4967 for (int subId : subIds) {
4968 activeSubscriberIds.add(tele.getSubscriberId(subId));
4969 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004970
4971 // First pass, find a number override for an active subscriber
4972 String mergeNumber = null;
4973 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4974 for (String key : prefs.keySet()) {
4975 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4976 final String subscriberId = (String) prefs.get(key);
4977 if (activeSubscriberIds.contains(subscriberId)) {
4978 final String iccId = key.substring(
4979 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4980 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4981 mergeNumber = (String) prefs.get(numberKey);
4982 if (DBG_MERGE) {
4983 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4984 + " for active subscriber " + subscriberId);
4985 }
4986 if (!TextUtils.isEmpty(mergeNumber)) {
4987 break;
4988 }
4989 }
4990 }
4991 }
4992
4993 // Shortcut when no active merged subscribers
4994 if (TextUtils.isEmpty(mergeNumber)) {
4995 return null;
4996 }
4997
4998 // Second pass, find all subscribers under that line override
4999 final ArraySet<String> result = new ArraySet<>();
5000 for (String key : prefs.keySet()) {
5001 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5002 final String number = (String) prefs.get(key);
5003 if (mergeNumber.equals(number)) {
5004 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5005 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5006 final String subscriberId = (String) prefs.get(subscriberKey);
5007 if (!TextUtils.isEmpty(subscriberId)) {
5008 result.add(subscriberId);
5009 }
5010 }
5011 }
5012 }
5013
5014 final String[] resultArray = result.toArray(new String[result.size()]);
5015 Arrays.sort(resultArray);
5016 if (DBG_MERGE) {
5017 Slog.d(LOG_TAG,
5018 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5019 }
5020 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005021 } finally {
5022 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005023 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005024 }
5025
5026 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005027 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005028 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5029 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005030
5031 final long identity = Binder.clearCallingIdentity();
5032 try {
5033 final Phone phone = getPhone(subId);
5034 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005038 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005039
5040 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005041 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005042 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5043 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005044 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005045
5046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 final Phone phone = getPhone(subId);
5049 if (phone == null) {
5050 return false;
5051 }
5052 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5053 cdmaNonRoamingList);
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005056 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005057 }
5058
5059 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005060 @Deprecated
5061 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5062 enforceModifyPermission();
5063
5064 int returnValue = 0;
5065 try {
vagdevie435a3e2018-08-15 16:01:53 -07005066 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005067 if(result.exception == null) {
5068 if (result.result != null) {
5069 byte[] responseData = (byte[])(result.result);
5070 if(responseData.length > oemResp.length) {
5071 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5072 responseData.length + "bytes. Buffer Size is " +
5073 oemResp.length + "bytes.");
5074 }
5075 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5076 returnValue = responseData.length;
5077 }
5078 } else {
5079 CommandException ex = (CommandException) result.exception;
5080 returnValue = ex.getCommandError().ordinal();
5081 if(returnValue > 0) returnValue *= -1;
5082 }
5083 } catch (RuntimeException e) {
5084 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5085 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5086 if(returnValue > 0) returnValue *= -1;
5087 }
5088
5089 return returnValue;
5090 }
5091
5092 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005093 public void setRadioCapability(RadioAccessFamily[] rafs) {
5094 try {
5095 ProxyController.getInstance().setRadioCapability(rafs);
5096 } catch (RuntimeException e) {
5097 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5098 }
5099 }
5100
5101 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005102 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005103 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005104 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005105 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005106 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005107 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005108 final long identity = Binder.clearCallingIdentity();
5109 try {
chen xufeeed752018-10-26 14:17:57 -07005110 TelephonyPermissions
5111 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5112 mApp, phone.getSubId(), "getRadioAccessFamily");
5113 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
chen xufeeed752018-10-26 14:17:57 -07005117 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005118 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005119
5120 @Override
5121 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005122 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005123 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005124
5125 final long identity = Binder.clearCallingIdentity();
5126 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005127 ImsManager.getInstance(defaultPhone.getContext(),
5128 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005129 } finally {
5130 Binder.restoreCallingIdentity(identity);
5131 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005132 }
5133
5134 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005135 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005136 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005138 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005139 return false;
5140 }
Svet Ganovb320e182015-04-16 12:30:10 -07005141
Malcolm Chend965c8b2018-02-28 15:00:40 -08005142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 // Check the user preference and the system-level IMS setting. Even if the user has
5145 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5146 // In the long run, we may instead need to check if there exists a connection service
5147 // which can support video calling.
5148 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005149 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005150 return imsManager.isVtEnabledByPlatform()
5151 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5152 && imsManager.isVtEnabledByUser();
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005156 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005157
Andrew Leea1239f22015-03-02 17:44:07 -08005158 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005159 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5161 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5162 return false;
5163 }
5164
5165 final long identity = Binder.clearCallingIdentity();
5166 try {
5167 CarrierConfigManager configManager =
5168 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005169 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005170 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5171 } finally {
5172 Binder.restoreCallingIdentity(identity);
5173 }
Andrew Leea1239f22015-03-02 17:44:07 -08005174 }
5175
5176 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005177 public boolean isWorldPhone(int subId, String callingPackage) {
5178 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5179 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5180 return false;
5181 }
5182
5183 final long identity = Binder.clearCallingIdentity();
5184 try {
5185 CarrierConfigManager configManager =
5186 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005187 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005188 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
Andrew Leea1239f22015-03-02 17:44:07 -08005192 }
5193
Andrew Lee9431b832015-03-09 18:46:45 -07005194 @Override
5195 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005196 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005197 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005198 }
5199
5200 @Override
5201 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005202 final long identity = Binder.clearCallingIdentity();
5203 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005204 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
Andrew Lee9431b832015-03-09 18:46:45 -07005208 }
5209
Hall Liuf6668912018-10-31 17:05:23 -07005210 /**
5211 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5212 * support for the feature and device firmware support.
5213 *
5214 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5215 */
5216 @Override
5217 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005219 final Phone phone = getPhone(subscriptionId);
5220 if (phone == null) {
5221 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5222 return false;
5223 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005224 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005225 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005226 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5227 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005228 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005229 return isCarrierSupported && isDeviceSupported;
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
5232 }
Hall Liu98187582018-01-22 19:15:32 -08005233 }
5234
Hall Liuf6668912018-10-31 17:05:23 -07005235 /**
5236 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5237 * both also support RTT.
5238 */
5239 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005240 final long identity = Binder.clearCallingIdentity();
5241 try {
Hall Liuf6668912018-10-31 17:05:23 -07005242 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005243 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005247 }
5248
Sanket Padawe7310cc72015-01-14 09:53:20 -08005249 /**
5250 * Returns the unique device ID of phone, for example, the IMEI for
5251 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5252 *
5253 * <p>Requires Permission:
5254 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5255 */
5256 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005257 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005258 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005259 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005260 return null;
5261 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005262 int subId = phone.getSubId();
5263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5264 mApp, subId, callingPackage, "getDeviceId")) {
5265 return null;
5266 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005267
5268 final long identity = Binder.clearCallingIdentity();
5269 try {
5270 return phone.getDeviceId();
5271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005274 }
5275
Ping Sunc67b7c22016-03-02 19:16:45 +08005276 /**
5277 * {@hide}
5278 * Returns the IMS Registration Status on a particular subid
5279 *
5280 * @param subId
5281 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005282 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005283 Phone phone = getPhone(subId);
5284 if (phone != null) {
5285 return phone.isImsRegistered();
5286 } else {
5287 return false;
5288 }
5289 }
5290
Santos Cordon7a1885b2015-02-03 11:15:19 -08005291 @Override
5292 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005293 final long identity = Binder.clearCallingIdentity();
5294 try {
5295 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5296 } finally {
5297 Binder.restoreCallingIdentity(identity);
5298 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005299 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005300
Tyler Gunn327a9722019-04-03 15:28:53 -07005301 @Override
5302 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5303 final long identity = Binder.clearCallingIdentity();
5304 try {
5305 Phone phone = getPhone(subscriptionId);
5306 if (phone == null) {
5307 return null;
5308 }
5309 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
5312 }
5313 }
5314
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005315 /**
5316 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005317 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005318 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005319 final long identity = Binder.clearCallingIdentity();
5320 try {
5321 Phone phone = getPhone(subId);
5322 if (phone != null) {
5323 return phone.isWifiCallingEnabled();
5324 } else {
5325 return false;
5326 }
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005329 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005330 }
5331
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005332 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005333 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005334 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005335 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005336 final long identity = Binder.clearCallingIdentity();
5337 try {
5338 Phone phone = getPhone(subId);
5339 if (phone != null) {
5340 return phone.isVideoEnabled();
5341 } else {
5342 return false;
5343 }
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005346 }
5347 }
5348
5349 /**
5350 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5351 * defined in {@link ImsRegistrationImplBase}.
5352 */
5353 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005354 final long identity = Binder.clearCallingIdentity();
5355 try {
5356 Phone phone = getPhone(subId);
5357 if (phone != null) {
5358 return phone.getImsRegistrationTech();
5359 } else {
5360 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5361 }
5362 } finally {
5363 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005364 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005365 }
5366
Stuart Scott8eef64f2015-04-08 15:13:54 -07005367 @Override
5368 public void factoryReset(int subId) {
5369 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005370 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5371 return;
5372 }
5373
Svet Ganovcc087f82015-05-12 20:35:54 -07005374 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005375
Svet Ganovcc087f82015-05-12 20:35:54 -07005376 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005377 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5378 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005379 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005380 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005381 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005382 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5383 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005384 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005385 // There has been issues when Sms raw table somehow stores orphan
5386 // fragments. They lead to garbled message when new fragments come
5387 // in and combined with those stale ones. In case this happens again,
5388 // user can reset all network settings which will clean up this table.
5389 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005390 } finally {
5391 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005392 }
5393 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005394
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005395 private void cleanUpSmsRawTable(Context context) {
5396 ContentResolver resolver = context.getContentResolver();
5397 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5398 resolver.delete(uri, null, null);
5399 }
5400
Narayan Kamath1c496c22015-04-16 14:40:19 +01005401 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005402 public String getSimLocaleForSubscriber(int subId) {
5403 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5404 final Phone phone = getPhone(subId);
5405 if (phone == null) {
5406 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005407 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005408 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005409 final long identity = Binder.clearCallingIdentity();
5410 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005411 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5412 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005413 // Try and fetch the locale from the carrier properties or from the SIM language
5414 // preferences (EF-PL and EF-LI)...
5415 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005416 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005417 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5418 if (localeFromDefaultSim != null) {
5419 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5420 if (DBG) log("Using locale from subId: " + subId + " locale: "
5421 + localeFromDefaultSim);
5422 return localeFromDefaultSim.toLanguageTag();
5423 } else {
5424 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005425 }
5426 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005427
Malcolm Chend965c8b2018-02-28 15:00:40 -08005428 // The SIM language preferences only store a language (e.g. fr = French), not an
5429 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5430 // the SIM and carrier preferences does not include a country we add the country
5431 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005432 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005433 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005434 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005435 return mccLocale.toLanguageTag();
5436 }
5437
5438 if (DBG) log("No locale found - returning null");
5439 return null;
5440 } finally {
5441 Binder.restoreCallingIdentity(identity);
5442 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005443 }
5444
5445 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005446 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005447 }
5448
Malcolm Chend965c8b2018-02-28 15:00:40 -08005449 /**
5450 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5451 */
5452 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005453 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005454 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005455
Chenjie Yu1ba97252018-01-11 18:16:20 -08005456 private final ModemActivityInfo mLastModemActivityInfo =
5457 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5458
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005459 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005460 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5461 * representing the state of the modem.
5462 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005463 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5464 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005465 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005466 */
5467 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005468 public void requestModemActivityInfo(ResultReceiver result) {
5469 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005470 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005471
5472 final long identity = Binder.clearCallingIdentity();
5473 try {
5474 ModemActivityInfo ret = null;
5475 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005476 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5477 CMD_GET_MODEM_ACTIVITY_INFO,
5478 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005479 if (isModemActivityInfoValid(info)) {
5480 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5481 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5482 mergedTxTimeMs[i] =
5483 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5484 }
5485 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5486 mLastModemActivityInfo.setSleepTimeMillis(
5487 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5488 mLastModemActivityInfo.setIdleTimeMillis(
5489 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5490 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5491 mLastModemActivityInfo.setRxTimeMillis(
5492 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5493 mLastModemActivityInfo.setEnergyUsed(
5494 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005495 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005496 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5497 mLastModemActivityInfo.getSleepTimeMillis(),
5498 mLastModemActivityInfo.getIdleTimeMillis(),
5499 mLastModemActivityInfo.getTxTimeMillis(),
5500 mLastModemActivityInfo.getRxTimeMillis(),
5501 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005502 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005503 Bundle bundle = new Bundle();
5504 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5505 result.send(0, bundle);
5506 } finally {
5507 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005508 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005509 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005510
Siddharth Rayf5d29552018-06-17 15:02:38 -07005511 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5512 // less than total activity duration.
5513 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5514 if (info == null) {
5515 return false;
5516 }
5517 int activityDurationMs =
5518 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5519 int totalTxTimeMs = 0;
5520 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5521 totalTxTimeMs += info.getTxTimeMillis()[i];
5522 }
5523 return (info.isValid()
5524 && (info.getSleepTimeMillis() <= activityDurationMs)
5525 && (info.getIdleTimeMillis() <= activityDurationMs)
5526 && (info.getRxTimeMillis() <= activityDurationMs)
5527 && (totalTxTimeMs <= activityDurationMs));
5528 }
5529
Jack Yu85bd38a2015-11-09 11:34:32 -08005530 /**
5531 * {@hide}
5532 * Returns the service state information on specified subscription.
5533 */
5534 @Override
5535 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005536 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005537 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005538 return null;
5539 }
5540
Hall Liuf19c44f2018-11-27 14:38:17 -08005541 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5542 LocationAccessPolicy.checkLocationPermission(mApp,
5543 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5544 .setCallingPackage(callingPackage)
5545 .setCallingPid(Binder.getCallingPid())
5546 .setCallingUid(Binder.getCallingUid())
5547 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005548 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005549 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5550 .build());
5551
5552 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5553 LocationAccessPolicy.checkLocationPermission(mApp,
5554 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5555 .setCallingPackage(callingPackage)
5556 .setCallingPid(Binder.getCallingPid())
5557 .setCallingUid(Binder.getCallingUid())
5558 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005559 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005560 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5561 .build());
5562 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5563 boolean hasFinePermission =
5564 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5565 boolean hasCoarsePermission =
5566 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5567
Malcolm Chend965c8b2018-02-28 15:00:40 -08005568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 final Phone phone = getPhone(subId);
5571 if (phone == null) {
5572 return null;
5573 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005574
Hall Liuf19c44f2018-11-27 14:38:17 -08005575 ServiceState ss = phone.getServiceState();
5576
5577 // Scrub out the location info in ServiceState depending on what level of access
5578 // the caller has.
5579 if (hasFinePermission) return ss;
5580 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5581 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005582 } finally {
5583 Binder.restoreCallingIdentity(identity);
5584 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005585 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005586
5587 /**
5588 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5589 *
5590 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5591 * voicemail ringtone.
5592 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5593 * PhoneAccount.
5594 */
5595 @Override
5596 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005597 final long identity = Binder.clearCallingIdentity();
5598 try {
5599 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5600 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005601 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005602 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005603
Malcolm Chend965c8b2018-02-28 15:00:40 -08005604 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005608 }
5609
5610 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005611 * Sets the per-account voicemail ringtone.
5612 *
5613 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5614 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5615 *
5616 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5617 * voicemail ringtone.
5618 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5619 * PhoneAccount.
5620 */
5621 @Override
5622 public void setVoicemailRingtoneUri(String callingPackage,
5623 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005624 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005625 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5626 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005627 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5629 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5630 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005631 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005632
5633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5636 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005637 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005638 }
5639 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005642 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005643 }
5644
5645 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005646 * Returns whether vibration is set for voicemail notification in Phone settings.
5647 *
5648 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5649 * voicemail vibration setting.
5650 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5651 */
5652 @Override
5653 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5657 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005658 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005659 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005660
Malcolm Chend965c8b2018-02-28 15:00:40 -08005661 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005665 }
5666
Youhan Wange64578a2016-05-02 15:32:42 -07005667 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005668 * Sets the per-account voicemail vibration.
5669 *
5670 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5671 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5672 *
5673 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5674 * voicemail vibration setting.
5675 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5676 * specific PhoneAccount.
5677 */
5678 @Override
5679 public void setVoicemailVibrationEnabled(String callingPackage,
5680 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005681 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5683 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005684 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5686 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5687 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005688 }
5689
Malcolm Chend965c8b2018-02-28 15:00:40 -08005690 final long identity = Binder.clearCallingIdentity();
5691 try {
5692 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5693 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005694 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005695 }
5696 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005699 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005700 }
5701
5702 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005703 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5704 *
5705 * @throws SecurityException if the caller does not have the required permission
5706 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005707 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005708 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005709 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005710 }
5711
5712 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005713 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5714 * permission.
5715 *
5716 * @throws SecurityException if the caller does not have the required permission
5717 */
5718 private void enforceSendSmsPermission() {
5719 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5720 }
5721
5722 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005723 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005724 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005725 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005726 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005727 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005731 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005732 if (componentName == null) {
5733 throw new SecurityException(
5734 "Caller not current active visual voicemail package[null]");
5735 }
5736 String vvmPackage = componentName.getPackageName();
5737 if (!callingPackage.equals(vvmPackage)) {
5738 throw new SecurityException("Caller not current active visual voicemail package["
5739 + vvmPackage + "]");
5740 }
5741 } finally {
5742 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005743 }
5744 }
5745
5746 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005747 * Return the application ID for the app type.
5748 *
5749 * @param subId the subscription ID that this request applies to.
5750 * @param appType the uicc app type.
5751 * @return Application ID for specificied app type, or null if no uicc.
5752 */
5753 @Override
5754 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005755 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005756 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005757
5758 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005759 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005760 if (phone == null) {
5761 return null;
5762 }
5763 String aid = null;
5764 try {
5765 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5766 .getApplicationByType(appType).getAid();
5767 } catch (Exception e) {
5768 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5769 }
5770 return aid;
5771 } finally {
5772 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005773 }
Youhan Wange64578a2016-05-02 15:32:42 -07005774 }
5775
Youhan Wang4001d252016-05-11 10:29:41 -07005776 /**
5777 * Return the Electronic Serial Number.
5778 *
5779 * @param subId the subscription ID that this request applies to.
5780 * @return ESN or null if error.
5781 */
5782 @Override
5783 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005784 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005785 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005786
5787 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005788 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005789 if (phone == null) {
5790 return null;
5791 }
5792 String esn = null;
5793 try {
5794 esn = phone.getEsn();
5795 } catch (Exception e) {
5796 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5797 }
5798 return esn;
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005801 }
Youhan Wang4001d252016-05-11 10:29:41 -07005802 }
5803
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005804 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005805 * Return the Preferred Roaming List Version.
5806 *
5807 * @param subId the subscription ID that this request applies to.
5808 * @return PRLVersion or null if error.
5809 */
5810 @Override
5811 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005812 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005813 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005814
5815 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005816 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005817 if (phone == null) {
5818 return null;
5819 }
5820 String cdmaPrlVersion = null;
5821 try {
5822 cdmaPrlVersion = phone.getCdmaPrlVersion();
5823 } catch (Exception e) {
5824 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5825 }
5826 return cdmaPrlVersion;
5827 } finally {
5828 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005829 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005830 }
5831
5832 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005833 * Get snapshot of Telephony histograms
5834 * @return List of Telephony histograms
5835 * @hide
5836 */
5837 @Override
5838 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5840 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005841
5842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 return RIL.getTelephonyRILTimingHistograms();
5845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005848 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005849
5850 /**
5851 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005852 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5853 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005854 * Require system privileges. In the future we may add this to carrier APIs.
5855 *
Michele Berionne0963c862018-11-27 18:57:59 -08005856 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005857 */
5858 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005859 @TelephonyManager.SetCarrierRestrictionResult
5860 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005861 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005862 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005863
Michele Berionne0963c862018-11-27 18:57:59 -08005864 if (carrierRestrictionRules == null) {
5865 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005866 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005867
Malcolm Chend965c8b2018-02-28 15:00:40 -08005868 final long identity = Binder.clearCallingIdentity();
5869 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005870 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005871 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005872 } finally {
5873 Binder.restoreCallingIdentity(identity);
5874 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005875 }
5876
5877 /**
5878 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005879 * Get the allowed carrier list and the excluded carrier list, including the priority between
5880 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005881 * Require system privileges. In the future we may add this to carrier APIs.
5882 *
Michele Berionne0963c862018-11-27 18:57:59 -08005883 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005884 */
5885 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005886 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005887 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005889
5890 final long identity = Binder.clearCallingIdentity();
5891 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005892 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5893 if (response instanceof CarrierRestrictionRules) {
5894 return (CarrierRestrictionRules) response;
5895 }
5896 // Response is an Exception of some kind,
5897 // which is signalled to the user as a NULL retval
5898 return null;
5899 } catch (Exception e) {
5900 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5901 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005905 }
5906
fionaxu59545b42016-05-25 15:53:37 -07005907 /**
5908 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5909 * @param subId the subscription ID that this action applies to.
5910 * @param enabled control enable or disable metered apns.
5911 * {@hide}
5912 */
5913 @Override
5914 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5915 enforceModifyPermission();
5916 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005917
5918 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005919 if (phone == null) {
5920 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5921 return;
5922 }
5923 try {
5924 phone.carrierActionSetMeteredApnsEnabled(enabled);
5925 } catch (Exception e) {
5926 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005927 } finally {
5928 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005929 }
5930 }
5931
5932 /**
5933 * Action set from carrier signalling broadcast receivers to enable/disable radio
5934 * @param subId the subscription ID that this action applies to.
5935 * @param enabled control enable or disable radio.
5936 * {@hide}
5937 */
5938 @Override
5939 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5940 enforceModifyPermission();
5941 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005942
5943 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005944 if (phone == null) {
5945 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5946 return;
5947 }
5948 try {
5949 phone.carrierActionSetRadioEnabled(enabled);
5950 } catch (Exception e) {
5951 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005952 } finally {
5953 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005954 }
5955 }
5956
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005957 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005958 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5959 * network status based on which carrier apps could apply actions accordingly,
5960 * enable/disable default url handler for example.
5961 *
5962 * @param subId the subscription ID that this action applies to.
5963 * @param report control start/stop reporting the default network status.
5964 * {@hide}
5965 */
5966 @Override
5967 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5968 enforceModifyPermission();
5969 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005970
5971 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005972 if (phone == null) {
5973 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5974 return;
5975 }
5976 try {
5977 phone.carrierActionReportDefaultNetworkStatus(report);
5978 } catch (Exception e) {
5979 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005980 } finally {
5981 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005982 }
5983 }
5984
5985 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005986 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5987 * bug report is being generated.
5988 */
5989 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005990 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005991 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5992 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005993 writer.println("Permission Denial: can't dump Phone from pid="
5994 + Binder.getCallingPid()
5995 + ", uid=" + Binder.getCallingUid()
5996 + "without permission "
5997 + android.Manifest.permission.DUMP);
5998 return;
5999 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006000 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006001 }
Jack Yueb89b242016-06-22 13:27:47 -07006002
Brad Ebingerdac2f002018-04-03 15:17:52 -07006003 @Override
6004 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6005 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6006 throws RemoteException {
6007 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6008 }
6009
Jack Yueb89b242016-06-22 13:27:47 -07006010 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006011 * Get aggregated video call data usage since boot.
6012 *
6013 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6014 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006015 * {@hide}
6016 */
6017 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006018 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006019 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6020 null);
6021
Malcolm Chend965c8b2018-02-28 15:00:40 -08006022 final long identity = Binder.clearCallingIdentity();
6023 try {
6024 // NetworkStatsService keeps tracking the active network interface and identity. It
6025 // records the delta with the corresponding network identity.
6026 // We just return the total video call data usage snapshot since boot.
6027 Phone phone = getPhone(subId);
6028 if (phone != null) {
6029 return phone.getVtDataUsage(perUidStats);
6030 }
6031 return null;
6032 } finally {
6033 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006034 }
Jack Yueb89b242016-06-22 13:27:47 -07006035 }
Jack Yu75ab2952016-07-08 14:29:33 -07006036
6037 /**
6038 * Policy control of data connection. Usually used when data limit is passed.
6039 * @param enabled True if enabling the data, otherwise disabling.
6040 * @param subId Subscription index
6041 * {@hide}
6042 */
6043 @Override
6044 public void setPolicyDataEnabled(boolean enabled, int subId) {
6045 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006046
6047 final long identity = Binder.clearCallingIdentity();
6048 try {
6049 Phone phone = getPhone(subId);
6050 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006051 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006052 }
6053 } finally {
6054 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006055 }
6056 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006057
6058 /**
6059 * Get Client request stats
6060 * @return List of Client Request Stats
6061 * @hide
6062 */
6063 @Override
6064 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006066 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006067 return null;
6068 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006069 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006070
Malcolm Chend965c8b2018-02-28 15:00:40 -08006071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 if (phone != null) {
6074 return phone.getClientRequestStats();
6075 }
6076
6077 return null;
6078 } finally {
6079 Binder.restoreCallingIdentity(identity);
6080 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006081 }
6082
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006083 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006084 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006085 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006086 }
Jack Yueb4124c2017-02-16 15:32:43 -08006087
6088 /**
Grace Chen70990072017-03-24 17:21:30 -07006089 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006090 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006091 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006092 * @param state State of SIM (power down, power up, pass through)
6093 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6094 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6095 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006096 *
6097 **/
6098 @Override
Grace Chen70990072017-03-24 17:21:30 -07006099 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006100 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006101 Phone phone = PhoneFactory.getPhone(slotIndex);
6102
vagdevie435a3e2018-08-15 16:01:53 -07006103 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6104
Malcolm Chend965c8b2018-02-28 15:00:40 -08006105 final long identity = Binder.clearCallingIdentity();
6106 try {
6107 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006108 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006109 }
6110 } finally {
6111 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006112 }
6113 }
Shuo Qiandd210312017-04-12 22:11:33 +00006114
Tyler Gunn65d45c22017-06-05 11:22:26 -07006115 private boolean isUssdApiAllowed(int subId) {
6116 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006117 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006118 if (configManager == null) {
6119 return false;
6120 }
6121 PersistableBundle pb = configManager.getConfigForSubId(subId);
6122 if (pb == null) {
6123 return false;
6124 }
6125 return pb.getBoolean(
6126 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6127 }
6128
Shuo Qiandd210312017-04-12 22:11:33 +00006129 /**
6130 * Check if phone is in emergency callback mode
6131 * @return true if phone is in emergency callback mode
6132 * @param subId sub id
6133 */
goneil9c5f4872017-12-05 14:07:56 -08006134 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006135 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006136 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006137 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006138
6139 final long identity = Binder.clearCallingIdentity();
6140 try {
6141 if (phone != null) {
6142 return phone.isInEcm();
6143 } else {
6144 return false;
6145 }
6146 } finally {
6147 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006148 }
6149 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006150
6151 /**
6152 * Get the current signal strength information for the given subscription.
6153 * Because this information is not updated when the device is in a low power state
6154 * it should not be relied-upon to be current.
6155 * @param subId Subscription index
6156 * @return the most recent cached signal strength info from the modem
6157 */
6158 @Override
6159 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006160 final long identity = Binder.clearCallingIdentity();
6161 try {
6162 Phone p = getPhone(subId);
6163 if (p == null) {
6164 return null;
6165 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006166
Malcolm Chend965c8b2018-02-28 15:00:40 -08006167 return p.getSignalStrength();
6168 } finally {
6169 Binder.restoreCallingIdentity(identity);
6170 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006171 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006172
Pengquan Meng9140aec2018-08-22 14:49:57 -07006173 /**
chen xu907e5a22018-10-11 13:21:04 -07006174 * Get the current modem radio state for the given slot.
6175 * @param slotIndex slot index.
6176 * @param callingPackage the name of the package making the call.
6177 * @return the current radio power state from the modem
6178 */
6179 @Override
6180 public int getRadioPowerState(int slotIndex, String callingPackage) {
6181 Phone phone = PhoneFactory.getPhone(slotIndex);
6182 if (phone != null) {
6183 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6184 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6185 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6186 }
6187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 return phone.getRadioPowerState();
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
6193 }
6194 }
6195 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6196 }
6197
6198 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006199 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6200 *
6201 * <p>Requires one of the following permissions:
6202 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6203 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6204 * privileges.
6205 *
6206 * @param subId subscription id
6207 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6208 * {@code false}.
6209 */
6210 @Override
6211 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006212 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6213 null /* message */);
6214
Pengquan Meng0c05b502018-09-06 09:59:22 -07006215 boolean isEnabled = false;
6216 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006217 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006218 Phone phone = getPhone(subId);
6219 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006220 } catch (Exception e) {
6221 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6222 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006223 } finally {
6224 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006225 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006226 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006227 }
6228
6229
6230 /**
6231 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6232 *
6233 * <p> Requires permission:
6234 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6235 * privileges.
6236 *
6237 * @param subId subscription id
6238 * @param isEnabled {@code true} means enable, {@code false} means disable.
6239 */
6240 @Override
6241 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6243 mApp, subId, "setDataRoamingEnabled");
6244
Pengquan Meng0c05b502018-09-06 09:59:22 -07006245 final long identity = Binder.clearCallingIdentity();
6246 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006247 Phone phone = getPhone(subId);
6248 if (phone != null) {
6249 phone.setDataRoamingEnabled(isEnabled);
6250 }
6251 } finally {
6252 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006253 }
6254 }
6255
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006256 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006257 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006258 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6259 mApp, subId, "isManualNetworkSelectionAllowed");
6260
Pengquan Meng312de0c2018-10-03 12:19:13 -07006261 boolean isAllowed = true;
6262 final long identity = Binder.clearCallingIdentity();
6263 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006264 Phone phone = getPhone(subId);
6265 if (phone != null) {
6266 isAllowed = phone.isCspPlmnEnabled();
6267 }
6268 } finally {
6269 Binder.restoreCallingIdentity(identity);
6270 }
6271 return isAllowed;
6272 }
6273
6274 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006275 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006276 try {
6277 enforceReadPrivilegedPermission("getUiccCardsInfo");
6278 } catch (SecurityException e) {
6279 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6280 // has carrier privileges on an active UICC
6281 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6282 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6283 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6284 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006285 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006286
6287 final long identity = Binder.clearCallingIdentity();
6288 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006289 UiccController uiccController = UiccController.getInstance();
6290 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6291
6292 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6293 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6294 // Remove private info if the caller doesn't have access
6295 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6296 for (UiccCardInfo cardInfo : cardInfos) {
6297 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6298 UiccProfile profile = card.getUiccProfile();
6299 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6300 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6301 filteredInfos.add(cardInfo.getUnprivileged());
6302 } else {
6303 filteredInfos.add(cardInfo);
6304 }
6305 }
6306 return filteredInfos;
6307 }
6308 return cardInfos;
6309 } catch (PackageManager.NameNotFoundException e) {
6310 // This should not happen since we pass the package info in from TelephonyManager
6311 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006312 } finally {
6313 Binder.restoreCallingIdentity(identity);
6314 }
6315 }
6316
6317 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006318 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006319 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006320
Malcolm Chend965c8b2018-02-28 15:00:40 -08006321 final long identity = Binder.clearCallingIdentity();
6322 try {
6323 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6324 if (slots == null) {
6325 Rlog.i(LOG_TAG, "slots is null.");
6326 return null;
6327 }
6328
6329 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6330 for (int i = 0; i < slots.length; i++) {
6331 UiccSlot slot = slots[i];
6332 if (slot == null) {
6333 continue;
6334 }
6335
6336 String cardId;
6337 UiccCard card = slot.getUiccCard();
6338 if (card != null) {
6339 cardId = card.getCardId();
6340 } else {
6341 cardId = slot.getIccId();
6342 }
6343
6344 int cardState = 0;
6345 switch (slot.getCardState()) {
6346 case CARDSTATE_ABSENT:
6347 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6348 break;
6349 case CARDSTATE_PRESENT:
6350 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6351 break;
6352 case CARDSTATE_ERROR:
6353 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6354 break;
6355 case CARDSTATE_RESTRICTED:
6356 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6357 break;
6358 default:
6359 break;
6360
6361 }
6362
6363 infos[i] = new UiccSlotInfo(
6364 slot.isActive(),
6365 slot.isEuicc(),
6366 cardId,
6367 cardState,
6368 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006369 slot.isExtendedApduSupported(),
6370 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006371 }
6372 return infos;
6373 } finally {
6374 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006375 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006376 }
6377
6378 @Override
6379 public boolean switchSlots(int[] physicalSlots) {
6380 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006381
6382 final long identity = Binder.clearCallingIdentity();
6383 try {
6384 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006388 }
Jack Yu4c988042018-02-27 15:30:01 -08006389
6390 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006391 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006392 final long identity = Binder.clearCallingIdentity();
6393 try {
6394 return UiccController.getInstance().getCardIdForDefaultEuicc();
6395 } finally {
6396 Binder.restoreCallingIdentity(identity);
6397 }
6398 }
6399
6400 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006401 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6402 enforceModifyPermission();
6403 final Phone phone = getPhone(subId);
6404 if (phone == null) {
6405 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6406 return;
6407 }
6408
Malcolm Chend965c8b2018-02-28 15:00:40 -08006409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 phone.setRadioIndicationUpdateMode(filters, mode);
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Jack Yu4c988042018-02-27 15:30:01 -08006415 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006416
6417 /**
goneil47ffb6e2018-04-06 15:40:58 -07006418 * A test API to reload the UICC profile.
6419 *
6420 * <p>Requires that the calling app has permission
6421 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6422 * @hide
6423 */
6424 @Override
6425 public void refreshUiccProfile(int subId) {
6426 enforceModifyPermission();
6427
6428 final long identity = Binder.clearCallingIdentity();
6429 try {
6430 Phone phone = getPhone(subId);
6431 if (phone == null) {
6432 return;
6433 }
6434 UiccCard uiccCard = phone.getUiccCard();
6435 if (uiccCard == null) {
6436 return;
6437 }
6438 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6439 if (uiccProfile == null) {
6440 return;
6441 }
6442 uiccProfile.refresh();
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
6446 }
6447
6448 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006449 * Returns false if the mobile data is disabled by default, otherwise return true.
6450 */
6451 private boolean getDefaultDataEnabled() {
6452 return "true".equalsIgnoreCase(
6453 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6454 }
6455
6456 /**
6457 * Returns true if the data roaming is enabled by default, i.e the system property
6458 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6459 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6460 */
6461 private boolean getDefaultDataRoamingEnabled(int subId) {
6462 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006463 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006464 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6465 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6466 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6467 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6468 return isDataRoamingEnabled;
6469 }
6470
6471 /**
6472 * Returns the default network type for the given {@code subId}, if the default network type is
6473 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6474 */
6475 private int getDefaultNetworkType(int subId) {
6476 return Integer.parseInt(
6477 TelephonyManager.getTelephonyProperty(
6478 mSubscriptionController.getPhoneId(subId),
6479 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6480 String.valueOf(Phone.PREFERRED_NT_MODE)));
6481 }
fionaxua13278b2018-03-21 00:08:13 -07006482
6483 @Override
6484 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6485 gid1, String gid2, String plmn, String spn) {
6486 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006487
6488 final long identity = Binder.clearCallingIdentity();
6489 try {
6490 final Phone phone = getPhone(subId);
6491 if (phone == null) {
6492 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6493 return;
6494 }
6495 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006498 }
fionaxua13278b2018-03-21 00:08:13 -07006499 }
6500
6501 @Override
6502 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006503 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006504
6505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 final Phone phone = getPhone(subId);
6508 if (phone == null) {
6509 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6510 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6511 }
6512 return phone.getCarrierIdListVersion();
6513 } finally {
6514 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006515 }
fionaxua13278b2018-03-21 00:08:13 -07006516 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006517
6518 @Override
6519 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6521 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6522 return -1;
6523 }
6524
6525 final long identity = Binder.clearCallingIdentity();
6526 try {
6527 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
6531 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006532
6533 @Override
6534 public int getCdmaRoamingMode(int subId) {
6535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6536 mApp, subId, "getCdmaRoamingMode");
6537
6538 final long identity = Binder.clearCallingIdentity();
6539 try {
6540 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
6544 }
6545
6546 @Override
6547 public boolean setCdmaRoamingMode(int subId, int mode) {
6548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6549 mApp, subId, "setCdmaRoamingMode");
6550
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
6553 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6554 } finally {
6555 Binder.restoreCallingIdentity(identity);
6556 }
6557 }
6558
6559 @Override
6560 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6562 mApp, subId, "setCdmaSubscriptionMode");
6563
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6567 } finally {
6568 Binder.restoreCallingIdentity(identity);
6569 }
6570 }
chen xu7ee67862018-10-30 22:27:10 -07006571
sqian2fff4a32018-11-05 14:18:37 -08006572 private void ensureUserRunning(int userId) {
6573 if (!mUserManager.isUserRunning(userId)) {
6574 throw new IllegalStateException("User " + userId + " does not exist or not running");
6575 }
6576 }
6577
6578 /**
6579 * Returns a list of SMS apps on a given user.
6580 *
6581 * Only the shell user (UID 2000 or 0) can call it.
6582 * Target user must be running.
6583 */
6584 @Override
6585 public String[] getSmsApps(int userId) {
6586 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6587 ensureUserRunning(userId);
6588
6589 final Collection<SmsApplicationData> apps =
6590 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6591
6592 String[] ret = new String[apps.size()];
6593 int i = 0;
6594 for (SmsApplicationData app : apps) {
6595 ret[i++] = app.mPackageName;
6596 }
6597 return ret;
6598 }
6599
6600 /**
6601 * Returns the default SMS app package name on a given user.
6602 *
6603 * Only the shell user (UID 2000 or 0) can call it.
6604 * Target user must be running.
6605 */
6606 @Override
6607 public String getDefaultSmsApp(int userId) {
6608 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6609 ensureUserRunning(userId);
6610
6611 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6612 /* updateIfNeeded= */ true, userId);
6613 return cn == null ? null : cn.getPackageName();
6614 }
6615
6616 /**
6617 * Set a package as the default SMS app on a given user.
6618 *
6619 * Only the shell user (UID 2000 or 0) can call it.
6620 * Target user must be running.
6621 */
6622 @Override
6623 public void setDefaultSmsApp(int userId, String packageName) {
6624 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6625 ensureUserRunning(userId);
6626
6627 boolean found = false;
6628 for (String pkg : getSmsApps(userId)) {
6629 if (TextUtils.equals(packageName, pkg)) {
6630 found = true;
6631 break;
6632 }
6633 }
6634 if (!found) {
6635 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6636 }
6637
6638 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6639 }
6640
chen xu7ee67862018-10-30 22:27:10 -07006641 @Override
sqian65eefe12019-02-22 15:55:18 -08006642 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006643 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006645 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006646 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6647 }
6648 final long identity = Binder.clearCallingIdentity();
6649 try {
sqian991b35e2018-12-12 16:48:18 -08006650 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6651 for (Phone phone: PhoneFactory.getPhones()) {
6652 if (phone.getEmergencyNumberTracker() != null
6653 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6654 emergencyNumberListInternal.put(
6655 phone.getSubId(),
6656 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6657 }
sqian03bca152018-12-05 18:48:28 -08006658 }
sqian991b35e2018-12-12 16:48:18 -08006659 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006660 } finally {
6661 Binder.restoreCallingIdentity(identity);
6662 }
sqian04b86072018-11-07 14:02:21 -08006663 }
6664
6665 @Override
sqian65eefe12019-02-22 15:55:18 -08006666 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006667 final Phone defaultPhone = getDefaultPhone();
6668 if (!exactMatch) {
6669 TelephonyPermissions
6670 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006671 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006672 }
6673 final long identity = Binder.clearCallingIdentity();
6674 try {
sqian991b35e2018-12-12 16:48:18 -08006675 for (Phone phone: PhoneFactory.getPhones()) {
6676 if (phone.getEmergencyNumberTracker() != null
6677 && phone.getEmergencyNumberTracker() != null) {
6678 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6679 number, exactMatch)) {
6680 return true;
sqian03bca152018-12-05 18:48:28 -08006681 }
6682 }
sqian03bca152018-12-05 18:48:28 -08006683 }
6684 return false;
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
6688 }
6689
sqian9d4df8b2019-01-15 18:32:07 -08006690 /**
6691 * Update emergency number list for test mode.
6692 */
6693 @Override
6694 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6696 "updateEmergencyNumberListTestMode");
6697
6698 final long identity = Binder.clearCallingIdentity();
6699 try {
6700 for (Phone phone: PhoneFactory.getPhones()) {
6701 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6702 if (tracker != null) {
6703 tracker.executeEmergencyNumberTestModeCommand(action, num);
6704 }
6705 }
6706 } finally {
6707 Binder.restoreCallingIdentity(identity);
6708 }
6709 }
6710
6711 /**
6712 * Get the full emergency number list for test mode.
6713 */
6714 @Override
6715 public List<String> getEmergencyNumberListTestMode() {
6716 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6717 "getEmergencyNumberListTestMode");
6718
6719 final long identity = Binder.clearCallingIdentity();
6720 try {
6721 Set<String> emergencyNumbers = new HashSet<>();
6722 for (Phone phone: PhoneFactory.getPhones()) {
6723 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6724 if (tracker != null) {
6725 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6726 emergencyNumbers.add(num.getNumber());
6727 }
6728 }
6729 }
6730 return new ArrayList<>(emergencyNumbers);
6731 } finally {
6732 Binder.restoreCallingIdentity(identity);
6733 }
6734 }
6735
sqian04b86072018-11-07 14:02:21 -08006736 @Override
chen xu7ee67862018-10-30 22:27:10 -07006737 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6738 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6739 Phone phone = getPhone(subId);
6740 if (phone == null) {
6741 return null;
6742 }
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
6745 UiccProfile profile = UiccController.getInstance()
6746 .getUiccProfileForPhone(phone.getPhoneId());
6747 if (profile != null) {
6748 return profile.getCertsFromCarrierPrivilegeAccessRules();
6749 }
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
6753 return null;
6754 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006755
6756 /**
6757 * Enable or disable a modem stack.
6758 */
6759 @Override
6760 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6761 enforceModifyPermission();
6762
6763 final long identity = Binder.clearCallingIdentity();
6764 try {
6765 Phone phone = PhoneFactory.getPhone(slotIndex);
6766 if (phone == null) {
6767 return false;
6768 } else {
6769 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6770 }
6771 } finally {
6772 Binder.restoreCallingIdentity(identity);
6773 }
6774 }
Micheled3107c52018-12-21 15:00:11 -08006775
Malcolm Chen33f55e12019-03-27 18:34:05 -07006776 /**
6777 * Whether a modem stack is enabled or not.
6778 */
6779 @Override
6780 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6781 Phone phone = PhoneFactory.getPhone(slotIndex);
6782 if (phone == null) return false;
6783
6784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6785 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6786 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6787 }
6788
6789 final long identity = Binder.clearCallingIdentity();
6790 try {
6791 return PhoneConfigurationManager.getInstance().getPhoneStatus(phone);
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
6794 }
6795 }
6796
Micheled3107c52018-12-21 15:00:11 -08006797 @Override
Michele2fb0f222019-03-19 14:58:42 -07006798 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006799 enforceModifyPermission();
6800
6801 final long identity = Binder.clearCallingIdentity();
6802 try {
6803 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006804 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006805 .commit();
6806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
6809 }
6810
6811 @Override
Michele2fb0f222019-03-19 14:58:42 -07006812 @TelephonyManager.IsMultiSimSupportedResult
6813 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006815 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6816 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006817 }
Micheled3107c52018-12-21 15:00:11 -08006818
6819 final long identity = Binder.clearCallingIdentity();
6820 try {
Michele2fb0f222019-03-19 14:58:42 -07006821 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006822 } finally {
6823 Binder.restoreCallingIdentity(identity);
6824 }
6825 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006826
Michele2fb0f222019-03-19 14:58:42 -07006827 @TelephonyManager.IsMultiSimSupportedResult
6828 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006829 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6830 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6831 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006832 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6833 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006834 }
6835 // Check if the hardware supports multisim functionality. If usage of multisim is not
6836 // supported by the modem, indicate that it is restricted.
6837 PhoneCapability staticCapability =
6838 mPhoneConfigurationManager.getStaticPhoneCapability();
6839 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006840 loge("isMultiSimSupportedInternal: no static configuration available");
6841 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006842 }
6843 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006844 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6845 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006846 }
6847 // Check if support of multiple SIMs is restricted by carrier
6848 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006849 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006850 }
6851
Michele2fb0f222019-03-19 14:58:42 -07006852 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006853 }
6854
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006855 /**
6856 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006857 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6858 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6859 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006860 * @param numOfSims number of active sims we want to switch to
6861 */
6862 @Override
6863 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006864 if (numOfSims == 1) {
6865 enforceModifyPermission();
6866 } else {
6867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6868 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6869 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006870 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006871
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006872 try {
Michele30b57b22019-03-01 12:01:14 -08006873 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006874 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006875 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6876 return;
6877 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006878 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6879 } finally {
6880 Binder.restoreCallingIdentity(identity);
6881 }
6882 }
6883
6884 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006885 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006886 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006887 */
6888 @Override
6889 public boolean isRebootRequiredForModemConfigChange() {
6890 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6891 final long identity = Binder.clearCallingIdentity();
6892 try {
6893 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6894 } finally {
6895 Binder.restoreCallingIdentity(identity);
6896 }
6897 }
6898
Pengquan Meng92d253b2019-02-06 11:12:53 -08006899 private void updateModemStateMetrics() {
6900 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6901 // TODO: check the state for each modem if the api is ready.
6902 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6903 }
6904
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006905 @Override
6906 public int[] getSlotsMapping() {
6907 enforceReadPrivilegedPermission("getSlotsMapping");
6908
6909 final long identity = Binder.clearCallingIdentity();
6910 try {
6911 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6912 // All logical slots should have a mapping to a physical slot.
6913 int[] logicalSlotsMapping = new int[phoneCount];
6914 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6915 for (int i = 0; i < slotInfos.length; i++) {
6916 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6917 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6918 }
6919 }
6920 return logicalSlotsMapping;
6921 } finally {
6922 Binder.restoreCallingIdentity(identity);
6923 }
6924 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006925
6926 /**
6927 * Get the IRadio HAL Version
6928 */
6929 @Override
6930 public int getRadioHalVersion() {
6931 Phone phone = getDefaultPhone();
6932 if (phone == null) return -1;
6933 HalVersion hv = phone.getHalVersion();
6934 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6935 return hv.major * 100 + hv.minor;
6936 }
Malcolm Chen460810d2019-04-10 18:25:07 -07006937
6938 /**
Malcolm Chen29739692019-04-18 13:51:02 -07006939 * Return whether data is enabled for certain APN type. This will tell if framework will accept
6940 * corresponding network requests on a subId.
6941 *
6942 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07006943 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07006944 * 2) APN is un-metered for this subscription, or
6945 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
6946 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
6947 *
6948 * @return whether data is allowed for a apn type.
6949 *
6950 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07006951 */
6952 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07006953 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07006954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07006955 mApp, subId, callingPackage, "isDataEnabledForApn")) {
6956 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07006957 }
6958
6959 // Now that all security checks passes, perform the operation as ourselves.
6960 final long identity = Binder.clearCallingIdentity();
6961 try {
6962 Phone phone = getPhone(subId);
6963 if (phone == null) return false;
6964
6965 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chen29739692019-04-18 13:51:02 -07006966 apnType), phone);
6967 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
6968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
6971 }
6972
6973 @Override
6974 public boolean isApnMetered(int apnType, int subId) {
6975 enforceReadPrivilegedPermission("isApnMetered");
6976
6977 // Now that all security checks passes, perform the operation as ourselves.
6978 final long identity = Binder.clearCallingIdentity();
6979 try {
6980 Phone phone = getPhone(subId);
6981 if (phone == null) return true; // By default return true.
6982
6983 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
6984 apnType), phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07006985 } finally {
6986 Binder.restoreCallingIdentity(identity);
6987 }
6988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006989}