blob: 2cd63ae983876acc51874ecb91e4fdc373bcae3e [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;
Jack Yu40306fc2019-05-13 16:54:09 -070094import android.telephony.data.ApnSetting.ApnType;
calvinpaneed9ae82018-11-01 19:43:06 +080095import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080097import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070098import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080099import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700100import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800101import android.telephony.ims.aidl.IImsMmTelFeature;
102import android.telephony.ims.aidl.IImsRcsFeature;
103import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800105import android.telephony.ims.feature.MmTelFeature;
106import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800107import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800109import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800111import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800112import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800113
Brad Ebinger4c460712018-10-01 10:40:55 -0700114import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700115import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800116import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700118import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700119import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800120import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700121import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800124import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800125import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800127import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100129import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700130import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700131import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700133import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800134import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700135import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700136import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700137import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700138import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700139import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700140import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800141import com.android.internal.telephony.SmsApplication;
142import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800143import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800144import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chen460810d2019-04-10 18:25:07 -0700145import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqian9d4df8b2019-01-15 18:32:07 -0800146import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700147import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800148import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800149import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.uicc.IccIoResult;
151import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800152import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700153import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800154import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800156import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000157import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700158import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800159import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700160import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800161import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700162import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700163import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800164
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700165import java.io.FileDescriptor;
166import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800167import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800169import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800170import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800171import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800172import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800173import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100174import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800175import java.util.Map;
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -0700176import java.util.NoSuchElementException;
sqian9d4df8b2019-01-15 18:32:07 -0800177import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178
179/**
180 * Implementation of the ITelephony interface.
181 */
Santos Cordon117fee72014-05-16 17:56:12 -0700182public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183 private static final String LOG_TAG = "PhoneInterfaceManager";
184 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
185 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188 // Message codes used with mMainThreadHandler
189 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700190 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
191 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700192 private static final int CMD_OPEN_CHANNEL = 9;
193 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
194 private static final int CMD_CLOSE_CHANNEL = 11;
195 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800196 private static final int CMD_NV_READ_ITEM = 13;
197 private static final int EVENT_NV_READ_ITEM_DONE = 14;
198 private static final int CMD_NV_WRITE_ITEM = 15;
199 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
200 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
201 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700202 private static final int CMD_RESET_MODEM_CONFIG = 19;
203 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800204 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
205 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
206 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
207 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800208 private static final int CMD_SEND_ENVELOPE = 25;
209 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000210 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
211 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700212 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
213 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
214 private static final int CMD_EXCHANGE_SIM_IO = 31;
215 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800216 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
217 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700218 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
219 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700220 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
221 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700222 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
223 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
224 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
225 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700226 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
227 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
228 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
229 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700230 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800231 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
232 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000233 private static final int CMD_SWITCH_SLOTS = 50;
234 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700235 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
236 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
237 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
238 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
239 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
240 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
241 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
242 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700243 private static final int CMD_GET_ALL_CELL_INFO = 60;
244 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
245 private static final int CMD_GET_CELL_LOCATION = 62;
246 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700247 private static final int CMD_MODEM_REBOOT = 64;
248 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700249 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
250 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800251 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
252 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -0700253 private static final int CMD_GET_MODEM_STATUS = 70;
254 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800256 // Parameters of select command.
257 private static final int SELECT_COMMAND = 0xA4;
258 private static final int SELECT_P1 = 0x04;
259 private static final int SELECT_P2 = 0;
260 private static final int SELECT_P3 = 0x10;
261
Pengquan Meng85728fb2018-03-12 16:31:21 -0700262 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
263 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
264 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
265
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266 /** The singleton instance. */
267 private static PhoneInterfaceManager sInstance;
268
Wink Saville3ab207e2014-11-20 13:07:20 -0800269 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800270 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700271 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800272 private AppOpsManager mAppOps;
273 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800274 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700276 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277
Derek Tan97ebb422014-09-05 16:55:38 -0700278 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
279 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800280 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800281 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700282
Micheled3107c52018-12-21 15:00:11 -0800283 // String to store multi SIM allowed
284 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
285
Derek Tan740e1672017-06-27 14:56:27 -0700286 // The AID of ISD-R.
287 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
288
yinxub1bed742017-04-17 11:45:04 -0700289 private NetworkScanRequestTracker mNetworkScanRequestTracker;
290
David Kelly5e06a7f2018-03-12 14:10:59 +0000291 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
292 private static final int MANUFACTURER_CODE_LENGTH = 8;
293
Derek Tan89e89d42014-07-08 17:00:10 -0700294 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700295 * A request object to use for transmitting data to an ICC.
296 */
297 private static final class IccAPDUArgument {
298 public int channel, cla, command, p1, p2, p3;
299 public String data;
300
301 public IccAPDUArgument(int channel, int cla, int command,
302 int p1, int p2, int p3, String data) {
303 this.channel = channel;
304 this.cla = cla;
305 this.command = command;
306 this.p1 = p1;
307 this.p2 = p2;
308 this.p3 = p3;
309 this.data = data;
310 }
311 }
312
313 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700314 * A request object to use for transmitting data to an ICC.
315 */
316 private static final class ManualNetworkSelectionArgument {
317 public OperatorInfo operatorInfo;
318 public boolean persistSelection;
319
320 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
321 this.operatorInfo = operatorInfo;
322 this.persistSelection = persistSelection;
323 }
324 }
325
326 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
328 * request after sending. The main thread will notify the request when it is complete.
329 */
330 private static final class MainThreadRequest {
331 /** The argument to use for the request */
332 public Object argument;
333 /** The result of the request that is run on the main thread */
334 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800335 // The subscriber id that this request applies to. Defaults to
336 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
337 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338
Nathan Harold92bed182018-10-12 18:16:49 -0700339 // In cases where subId is unavailable, the caller needs to specify the phone.
340 public Phone phone;
341
vagdevie435a3e2018-08-15 16:01:53 -0700342 public WorkSource workSource;
343
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 public MainThreadRequest(Object argument) {
345 this.argument = argument;
346 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800347
Nathan Harold92bed182018-10-12 18:16:49 -0700348 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
349 this.argument = argument;
350 if (phone != null) {
351 this.phone = phone;
352 }
353 this.workSource = workSource;
354 }
355
vagdevie435a3e2018-08-15 16:01:53 -0700356 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800357 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800358 if (subId != null) {
359 this.subId = subId;
360 }
vagdevie435a3e2018-08-15 16:01:53 -0700361 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 }
364
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800365 private static final class IncomingThirdPartyCallArgs {
366 public final ComponentName component;
367 public final String callId;
368 public final String callerDisplayName;
369
370 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
371 String callerDisplayName) {
372 this.component = component;
373 this.callId = callId;
374 this.callerDisplayName = callerDisplayName;
375 }
376 }
377
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 /**
379 * A handler that processes messages on the main thread in the phone process. Since many
380 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
381 * inbound binder threads to the main thread in the phone process. The Binder thread
382 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
383 * on, which will be notified when the operation completes and will contain the result of the
384 * request.
385 *
386 * <p>If a MainThreadRequest object is provided in the msg.obj field,
387 * note that request.result must be set to something non-null for the calling thread to
388 * unblock.
389 */
390 private final class MainThreadHandler extends Handler {
391 @Override
392 public void handleMessage(Message msg) {
393 MainThreadRequest request;
394 Message onCompleted;
395 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800396 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700397 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800398 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399
400 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700401 case CMD_HANDLE_USSD_REQUEST: {
402 request = (MainThreadRequest) msg.obj;
403 final Phone phone = getPhoneFromRequest(request);
404 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
405 String ussdRequest = ussdObject.first;
406 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700407
Pengquan Meng0c05b502018-09-06 09:59:22 -0700408 if (!isUssdApiAllowed(request.subId)) {
409 // Carrier does not support use of this API, return failure.
410 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
411 UssdResponse response = new UssdResponse(ussdRequest, null);
412 Bundle returnData = new Bundle();
413 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
414 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700415
Pengquan Meng0c05b502018-09-06 09:59:22 -0700416 request.result = true;
417 notifyRequester(request);
418 return;
419 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700420
Pengquan Meng0c05b502018-09-06 09:59:22 -0700421 try {
422 request.result = phone != null
423 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
424 } catch (CallStateException cse) {
425 request.result = false;
426 }
427 // Wake up the requesting thread
428 notifyRequester(request);
429 break;
pkanwar32d516d2016-10-14 19:37:38 -0700430 }
431
Yorke Lee716f67e2015-06-17 15:39:16 -0700432 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700434 final Phone phone = getPhoneFromRequest(request);
435 request.result = phone != null ?
436 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
437 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700439 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800446 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700447 if (uiccCard == null) {
448 loge("iccTransmitApduLogicalChannel: No UICC");
449 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700450 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700451 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
453 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700454 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 iccArgument.channel, iccArgument.cla, iccArgument.command,
456 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700457 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700458 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 break;
460
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 ar = (AsyncResult) msg.obj;
463 request = (MainThreadRequest) ar.userObj;
464 if (ar.exception == null && ar.result != null) {
465 request.result = ar.result;
466 } else {
467 request.result = new IccIoResult(0x6F, 0, (byte[])null);
468 if (ar.result == null) {
469 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800470 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700471 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800472 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 } else {
474 loge("iccTransmitApduLogicalChannel: Unknown exception");
475 }
476 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700477 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 break;
479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
481 request = (MainThreadRequest) msg.obj;
482 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800483 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 if (uiccCard == null) {
485 loge("iccTransmitApduBasicChannel: No UICC");
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700487 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 } else {
489 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
490 request);
491 uiccCard.iccTransmitApduBasicChannel(
492 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
493 iccArgument.p3, iccArgument.data, onCompleted);
494 }
495 break;
496
497 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
498 ar = (AsyncResult) msg.obj;
499 request = (MainThreadRequest) ar.userObj;
500 if (ar.exception == null && ar.result != null) {
501 request.result = ar.result;
502 } else {
503 request.result = new IccIoResult(0x6F, 0, (byte[])null);
504 if (ar.result == null) {
505 loge("iccTransmitApduBasicChannel: Empty response");
506 } else if (ar.exception instanceof CommandException) {
507 loge("iccTransmitApduBasicChannel: CommandException: " +
508 ar.exception);
509 } else {
510 loge("iccTransmitApduBasicChannel: Unknown exception");
511 }
512 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700513 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 break;
515
516 case CMD_EXCHANGE_SIM_IO:
517 request = (MainThreadRequest) msg.obj;
518 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800519 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 if (uiccCard == null) {
521 loge("iccExchangeSimIO: No UICC");
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 } else {
525 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
526 request);
527 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
528 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
529 iccArgument.data, onCompleted);
530 }
531 break;
532
533 case EVENT_EXCHANGE_SIM_IO_DONE:
534 ar = (AsyncResult) msg.obj;
535 request = (MainThreadRequest) ar.userObj;
536 if (ar.exception == null && ar.result != null) {
537 request.result = ar.result;
538 } else {
539 request.result = new IccIoResult(0x6f, 0, (byte[])null);
540 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 break;
543
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 case CMD_SEND_ENVELOPE:
545 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800546 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 if (uiccCard == null) {
548 loge("sendEnvelopeWithStatus: No UICC");
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700550 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 } else {
552 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
553 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
554 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800555 break;
556
557 case EVENT_SEND_ENVELOPE_DONE:
558 ar = (AsyncResult) msg.obj;
559 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700560 if (ar.exception == null && ar.result != null) {
561 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800562 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700563 request.result = new IccIoResult(0x6F, 0, (byte[])null);
564 if (ar.result == null) {
565 loge("sendEnvelopeWithStatus: Empty response");
566 } else if (ar.exception instanceof CommandException) {
567 loge("sendEnvelopeWithStatus: CommandException: " +
568 ar.exception);
569 } else {
570 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
571 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800572 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700573 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 break;
575
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 case CMD_OPEN_CHANNEL:
577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800578 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800579 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 if (uiccCard == null) {
581 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800582 request.result = new IccOpenLogicalChannelResponse(-1,
583 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700585 } else {
586 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800587 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
588 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
592 case EVENT_OPEN_CHANNEL_DONE:
593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 int[] result = (int[]) ar.result;
598 int channelId = result[0];
599 byte[] selectResponse = null;
600 if (result.length > 1) {
601 selectResponse = new byte[result.length - 1];
602 for (int i = 1; i < result.length; ++i) {
603 selectResponse[i - 1] = (byte) result[i];
604 }
605 }
606 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700607 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 if (ar.result == null) {
610 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 if (ar.exception != null) {
613 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
614 }
615
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700616 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700617 if (ar.exception instanceof CommandException) {
618 CommandException.Error error =
619 ((CommandException) (ar.exception)).getCommandError();
620 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700621 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700622 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 }
625 }
626 openChannelResp = new IccOpenLogicalChannelResponse(
627 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700629 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 break;
632
633 case CMD_CLOSE_CHANNEL:
634 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800635 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 if (uiccCard == null) {
637 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900638 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700639 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 } else {
641 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
642 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
643 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 break;
645
646 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800647 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
648 break;
649
650 case CMD_NV_READ_ITEM:
651 request = (MainThreadRequest) msg.obj;
652 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800653 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
654 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800655 break;
656
657 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 ar = (AsyncResult) msg.obj;
659 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800660 if (ar.exception == null && ar.result != null) {
661 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800663 request.result = "";
664 if (ar.result == null) {
665 loge("nvReadItem: Empty response");
666 } else if (ar.exception instanceof CommandException) {
667 loge("nvReadItem: CommandException: " +
668 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800670 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 }
672 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
Jake Hambye994d462014-02-03 13:10:13 -0800676 case CMD_NV_WRITE_ITEM:
677 request = (MainThreadRequest) msg.obj;
678 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
679 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800680 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700681 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800682 break;
683
684 case EVENT_NV_WRITE_ITEM_DONE:
685 handleNullReturnEvent(msg, "nvWriteItem");
686 break;
687
688 case CMD_NV_WRITE_CDMA_PRL:
689 request = (MainThreadRequest) msg.obj;
690 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800691 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800692 break;
693
694 case EVENT_NV_WRITE_CDMA_PRL_DONE:
695 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
696 break;
697
chen xu1cc0abe2018-10-26 17:39:23 -0700698 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800699 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700700 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800701 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800702 break;
703
chen xu1cc0abe2018-10-26 17:39:23 -0700704 case EVENT_RESET_MODEM_CONFIG_DONE:
705 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800706 break;
707
Jake Hamby7c27be32014-03-03 13:25:59 -0800708 case CMD_GET_PREFERRED_NETWORK_TYPE:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700711 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800712 break;
713
714 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
715 ar = (AsyncResult) msg.obj;
716 request = (MainThreadRequest) ar.userObj;
717 if (ar.exception == null && ar.result != null) {
718 request.result = ar.result; // Integer
719 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800720 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800721 if (ar.result == null) {
722 loge("getPreferredNetworkType: Empty response");
723 } else if (ar.exception instanceof CommandException) {
724 loge("getPreferredNetworkType: CommandException: " +
725 ar.exception);
726 } else {
727 loge("getPreferredNetworkType: Unknown exception");
728 }
729 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700730 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case CMD_SET_PREFERRED_NETWORK_TYPE:
734 request = (MainThreadRequest) msg.obj;
735 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
736 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700737 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800738 break;
739
740 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
741 handleNullReturnEvent(msg, "setPreferredNetworkType");
742 break;
743
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000744 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
745 request = (MainThreadRequest)msg.obj;
746 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800747 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000748 break;
749
750 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
751 ar = (AsyncResult)msg.obj;
752 request = (MainThreadRequest)ar.userObj;
753 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700754 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000755 break;
756
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800757 case CMD_SET_VOICEMAIL_NUMBER:
758 request = (MainThreadRequest) msg.obj;
759 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
760 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800761 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
762 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800763 break;
764
765 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
766 handleNullReturnEvent(msg, "setVoicemailNumber");
767 break;
768
Stuart Scott54788802015-03-30 13:18:01 -0700769 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
772 request);
773 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
774 break;
775
776 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
777 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
778 break;
779
Shishir Agrawal302c8692015-06-19 13:49:39 -0700780 case CMD_PERFORM_NETWORK_SCAN:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
783 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
784 break;
785
786 case EVENT_PERFORM_NETWORK_SCAN_DONE:
787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
789 CellNetworkScanResult cellScanResult;
790 if (ar.exception == null && ar.result != null) {
791 cellScanResult = new CellNetworkScanResult(
792 CellNetworkScanResult.STATUS_SUCCESS,
793 (List<OperatorInfo>) ar.result);
794 } else {
795 if (ar.result == null) {
796 loge("getCellNetworkScanResults: Empty response");
797 }
798 if (ar.exception != null) {
799 loge("getCellNetworkScanResults: Exception: " + ar.exception);
800 }
801 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
802 if (ar.exception instanceof CommandException) {
803 CommandException.Error error =
804 ((CommandException) (ar.exception)).getCommandError();
805 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
806 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
807 } else if (error == CommandException.Error.GENERIC_FAILURE) {
808 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
809 }
810 }
811 cellScanResult = new CellNetworkScanResult(errorCode, null);
812 }
813 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700814 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 break;
816
817 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
818 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700819 ManualNetworkSelectionArgument selArg =
820 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700821 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
822 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700823 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
824 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700825 break;
826
827 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700828 ar = (AsyncResult) msg.obj;
829 request = (MainThreadRequest) ar.userObj;
830 if (ar.exception == null) {
831 request.result = true;
832 } else {
833 request.result = false;
834 loge("setNetworkSelectionModeManual " + ar.exception);
835 }
836 notifyRequester(request);
837 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700838 break;
839
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700840 case CMD_GET_MODEM_ACTIVITY_INFO:
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisc56281c2019-04-03 14:18:34 -0700843 if (defaultPhone != null) {
844 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
845 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700846 break;
847
848 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
849 ar = (AsyncResult) msg.obj;
850 request = (MainThreadRequest) ar.userObj;
851 if (ar.exception == null && ar.result != null) {
852 request.result = ar.result;
853 } else {
854 if (ar.result == null) {
855 loge("queryModemActivityInfo: Empty response");
856 } else if (ar.exception instanceof CommandException) {
857 loge("queryModemActivityInfo: CommandException: " +
858 ar.exception);
859 } else {
860 loge("queryModemActivityInfo: Unknown exception");
861 }
862 }
Amit Mahajand4766222016-01-28 15:28:28 -0800863 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
864 if (request.result == null) {
865 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
866 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700867 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700868 break;
869
Meng Wang1a7c35a2016-05-05 20:56:15 -0700870 case CMD_SET_ALLOWED_CARRIERS:
871 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800872 CarrierRestrictionRules argument =
873 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700874 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800875 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 break;
877
878 case EVENT_SET_ALLOWED_CARRIERS_DONE:
879 ar = (AsyncResult) msg.obj;
880 request = (MainThreadRequest) ar.userObj;
881 if (ar.exception == null && ar.result != null) {
882 request.result = ar.result;
883 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800884 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
885 if (ar.exception instanceof CommandException) {
886 loge("setAllowedCarriers: CommandException: " + ar.exception);
887 CommandException.Error error =
888 ((CommandException) (ar.exception)).getCommandError();
889 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
890 request.result =
891 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
892 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 } else {
894 loge("setAllowedCarriers: Unknown exception");
895 }
896 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700897 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700898 break;
899
900 case CMD_GET_ALLOWED_CARRIERS:
901 request = (MainThreadRequest) msg.obj;
902 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800903 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700904 break;
905
906 case EVENT_GET_ALLOWED_CARRIERS_DONE:
907 ar = (AsyncResult) msg.obj;
908 request = (MainThreadRequest) ar.userObj;
909 if (ar.exception == null && ar.result != null) {
910 request.result = ar.result;
911 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800912 request.result = new IllegalStateException(
913 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 if (ar.result == null) {
915 loge("getAllowedCarriers: Empty response");
916 } else if (ar.exception instanceof CommandException) {
917 loge("getAllowedCarriers: CommandException: " +
918 ar.exception);
919 } else {
920 loge("getAllowedCarriers: Unknown exception");
921 }
922 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700923 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700924 break;
925
Nathan Haroldb3014052017-01-25 15:57:32 -0800926 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
927 ar = (AsyncResult) msg.obj;
928 request = (MainThreadRequest) ar.userObj;
929 if (ar.exception == null && ar.result != null) {
930 request.result = ar.result;
931 } else {
932 request.result = new IllegalArgumentException(
933 "Failed to retrieve Forbidden Plmns");
934 if (ar.result == null) {
935 loge("getForbiddenPlmns: Empty response");
936 } else {
937 loge("getForbiddenPlmns: Unknown exception");
938 }
939 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700940 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800941 break;
942
943 case CMD_GET_FORBIDDEN_PLMNS:
944 request = (MainThreadRequest) msg.obj;
945 uiccCard = getUiccCardFromRequest(request);
946 if (uiccCard == null) {
947 loge("getForbiddenPlmns() UiccCard is null");
948 request.result = new IllegalArgumentException(
949 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700950 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800951 break;
952 }
953 Integer appType = (Integer) request.argument;
954 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
955 if (uiccApp == null) {
956 loge("getForbiddenPlmns() no app with specified type -- "
957 + appType);
958 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700959 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800960 break;
961 } else {
962 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
963 + " specified type -- " + appType);
964 }
965 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
966 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
967 onCompleted);
968 break;
969
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000970 case CMD_SWITCH_SLOTS:
971 request = (MainThreadRequest) msg.obj;
972 int[] physicalSlots = (int[]) request.argument;
973 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
974 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
975 break;
976
977 case EVENT_SWITCH_SLOTS_DONE:
978 ar = (AsyncResult) msg.obj;
979 request = (MainThreadRequest) ar.userObj;
980 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700981 notifyRequester(request);
982 break;
983 case CMD_GET_NETWORK_SELECTION_MODE:
984 request = (MainThreadRequest) msg.obj;
985 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
986 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
987 break;
988
989 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 if (ar.exception != null) {
993 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
994 } else {
995 int mode = ((int[]) ar.result)[0];
996 if (mode == 0) {
997 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
998 } else {
999 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1000 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001001 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001002 notifyRequester(request);
1003 break;
1004 case CMD_GET_CDMA_ROAMING_MODE:
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1007 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1008 break;
1009 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1010 ar = (AsyncResult) msg.obj;
1011 request = (MainThreadRequest) ar.userObj;
1012 if (ar.exception != null) {
1013 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1014 } else {
1015 request.result = ((int[]) ar.result)[0];
1016 }
1017 notifyRequester(request);
1018 break;
1019 case CMD_SET_CDMA_ROAMING_MODE:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1022 int mode = (int) request.argument;
1023 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1024 break;
1025 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 request.result = ar.exception == null;
1029 notifyRequester(request);
1030 break;
1031 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1032 request = (MainThreadRequest) msg.obj;
1033 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1034 int subscriptionMode = (int) request.argument;
1035 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1036 break;
1037 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
1040 request.result = ar.exception == null;
1041 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001042 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001043 case CMD_GET_ALL_CELL_INFO:
1044 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001045 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001046 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 case EVENT_GET_ALL_CELL_INFO_DONE:
1049 ar = (AsyncResult) msg.obj;
1050 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001051 // If a timeout occurs, the response will be null
1052 request.result = (ar.exception == null && ar.result != null)
1053 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 synchronized (request) {
1055 request.notifyAll();
1056 }
1057 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001058 case CMD_REQUEST_CELL_INFO_UPDATE:
1059 request = (MainThreadRequest) msg.obj;
1060 request.phone.requestCellInfoUpdate(request.workSource,
1061 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1062 break;
1063 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
1066 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1067 try {
1068 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001069 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001070 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1071 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001074 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 } else {
1076 // use the result as returned
1077 cb.onCellInfo((List<CellInfo>) ar.result);
1078 }
1079 } catch (RemoteException re) {
1080 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1081 }
1082 break;
1083 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001084 request = (MainThreadRequest) msg.obj;
1085 WorkSource ws = (WorkSource) request.argument;
1086 Phone phone = getPhoneFromRequest(request);
1087 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1088 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001089 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001090 ar = (AsyncResult) msg.obj;
1091 request = (MainThreadRequest) ar.userObj;
1092 if (ar.exception == null) {
1093 request.result = ar.result;
1094 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001095 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001096 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1097 ? new CdmaCellLocation() : new GsmCellLocation();
1098 }
1099
1100 synchronized (request) {
1101 request.notifyAll();
1102 }
1103 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001104 case CMD_MODEM_REBOOT:
1105 request = (MainThreadRequest) msg.obj;
1106 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001107 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001108 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001109 case EVENT_CMD_MODEM_REBOOT_DONE:
1110 handleNullReturnEvent(msg, "rebootModem");
1111 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001112 case CMD_REQUEST_ENABLE_MODEM:
1113 request = (MainThreadRequest) msg.obj;
1114 boolean enable = (boolean) request.argument;
1115 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001116 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001117 PhoneConfigurationManager.getInstance()
1118 .enablePhone(request.phone, enable, onCompleted);
1119 break;
1120 case EVENT_ENABLE_MODEM_DONE:
1121 ar = (AsyncResult) msg.obj;
1122 request = (MainThreadRequest) ar.userObj;
1123 request.result = (ar.exception == null);
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07001124 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001125 //update the cache as modem status has changed
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07001126 if ((boolean) request.result) {
1127 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1128 updateModemStateMetrics();
1129 } else {
1130 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1131 + ar.exception);
1132 }
1133 notifyRequester(request);
1134 break;
1135 case CMD_GET_MODEM_STATUS:
1136 request = (MainThreadRequest) msg.obj;
1137 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1138 PhoneConfigurationManager.getInstance()
1139 .getPhoneStatusFromModem(request.phone, onCompleted);
1140 break;
1141 case EVENT_GET_MODEM_STATUS_DONE:
1142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 int id = request.phone.getPhoneId();
1145 if (ar.exception == null && ar.result != null) {
1146 request.result = ar.result;
1147 //update the cache as modem status has changed
1148 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1149 (boolean) request.result);
1150 } else {
1151 // Return true if modem status cannot be retrieved. For most cases,
1152 // modem status is on. And for older version modems, GET_MODEM_STATUS
1153 // and disable modem are not supported. Modem is always on.
1154 // TODO: this should be fixed in R to support a third
1155 // status UNKNOWN b/131631629
1156 request.result = true;
1157 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1158 + ar.exception);
1159 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08001160 notifyRequester(request);
1161 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 default:
1163 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1164 break;
1165 }
1166 }
Jake Hambye994d462014-02-03 13:10:13 -08001167
Pengquan Meng0c05b502018-09-06 09:59:22 -07001168 private void notifyRequester(MainThreadRequest request) {
1169 synchronized (request) {
1170 request.notifyAll();
1171 }
1172 }
1173
Jake Hambye994d462014-02-03 13:10:13 -08001174 private void handleNullReturnEvent(Message msg, String command) {
1175 AsyncResult ar = (AsyncResult) msg.obj;
1176 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1177 if (ar.exception == null) {
1178 request.result = true;
1179 } else {
1180 request.result = false;
1181 if (ar.exception instanceof CommandException) {
1182 loge(command + ": CommandException: " + ar.exception);
1183 } else {
1184 loge(command + ": Unknown exception");
1185 }
1186 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001187 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189 }
1190
1191 /**
1192 * Posts the specified command to be executed on the main thread,
1193 * waits for the request to complete, and returns the result.
1194 * @see #sendRequestAsync
1195 */
1196 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001197 return sendRequest(
1198 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001199 }
1200
1201 /**
1202 * Posts the specified command to be executed on the main thread,
1203 * waits for the request to complete, and returns the result.
1204 * @see #sendRequestAsync
1205 */
1206 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1207 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001208 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001209 }
1210
1211 /**
1212 * Posts the specified command to be executed on the main thread,
1213 * waits for the request to complete, and returns the result.
1214 * @see #sendRequestAsync
1215 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001216 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001217 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001218 }
1219
1220 /**
1221 * Posts the specified command to be executed on the main thread,
1222 * waits for the request to complete, and returns the result.
1223 * @see #sendRequestAsync
1224 */
Nathan Harold92bed182018-10-12 18:16:49 -07001225 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1226 return sendRequest(command, argument, subId, null, workSource);
1227 }
1228
1229 /**
1230 * Posts the specified command to be executed on the main thread,
1231 * waits for the request to complete, and returns the result.
1232 * @see #sendRequestAsync
1233 */
1234 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1235 return sendRequest(
1236 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1237 }
1238
1239 /**
1240 * Posts the specified command to be executed on the main thread,
1241 * waits for the request to complete, and returns the result.
1242 * @see #sendRequestAsync
1243 */
1244 private Object sendRequest(
1245 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1247 throw new RuntimeException("This method will deadlock if called from the main thread.");
1248 }
1249
Nathan Harold92bed182018-10-12 18:16:49 -07001250 MainThreadRequest request = null;
1251 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1252 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1253 } else if (phone != null) {
1254 request = new MainThreadRequest(argument, phone, workSource);
1255 } else {
1256 request = new MainThreadRequest(argument, subId, workSource);
1257 }
1258
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 Message msg = mMainThreadHandler.obtainMessage(command, request);
1260 msg.sendToTarget();
1261
1262 // Wait for the request to complete
1263 synchronized (request) {
1264 while (request.result == null) {
1265 try {
1266 request.wait();
1267 } catch (InterruptedException e) {
1268 // Do nothing, go back and wait until the request is complete
1269 }
1270 }
1271 }
1272 return request.result;
1273 }
1274
1275 /**
1276 * Asynchronous ("fire and forget") version of sendRequest():
1277 * Posts the specified command to be executed on the main thread, and
1278 * returns immediately.
1279 * @see #sendRequest
1280 */
1281 private void sendRequestAsync(int command) {
1282 mMainThreadHandler.sendEmptyMessage(command);
1283 }
1284
1285 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001286 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001287 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001288 */
1289 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001290 sendRequestAsync(command, argument, null, null);
1291 }
1292
1293 /**
1294 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1295 * @see {@link #sendRequest(int,Object)}
1296 */
1297 private void sendRequestAsync(
1298 int command, Object argument, Phone phone, WorkSource workSource) {
1299 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001300 Message msg = mMainThreadHandler.obtainMessage(command, request);
1301 msg.sendToTarget();
1302 }
1303
1304 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 * Initialize the singleton PhoneInterfaceManager instance.
1306 * This is only done once, at startup, from PhoneApp.onCreate().
1307 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001308 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 synchronized (PhoneInterfaceManager.class) {
1310 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001311 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 } else {
1313 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1314 }
1315 return sInstance;
1316 }
1317 }
1318
1319 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001320 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001323 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1325 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001326 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001327 mTelephonySharedPreferences =
1328 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001329 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001330 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001331
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 publish();
1333 }
1334
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001335 private Phone getDefaultPhone() {
1336 Phone thePhone = getPhone(getDefaultSubscription());
1337 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1338 }
1339
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001340 private void publish() {
1341 if (DBG) log("publish: " + this);
1342
1343 ServiceManager.addService("phone", this);
1344 }
1345
Stuart Scott584921c2015-01-15 17:10:34 -08001346 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001347 if (request.phone != null) {
1348 return request.phone;
1349 } else {
1350 return getPhoneFromSubId(request.subId);
1351 }
1352 }
1353
1354 private Phone getPhoneFromSubId(int subId) {
1355 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1356 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001357 }
1358
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001359 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1360 Phone phone = getPhoneFromRequest(request);
1361 return phone == null ? null :
1362 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1363 }
1364
Wink Saville36469e72014-06-11 15:17:00 -07001365 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001366 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001367 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001369
1370 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001371 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
1373
Wink Savilleb564aae2014-10-23 10:18:09 -07001374 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 if (DBG) log("dial: " + number);
1376 // No permission check needed here: This is just a wrapper around the
1377 // ACTION_DIAL intent, which is available to any app since it puts up
1378 // the UI before it does anything.
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 // PENDING: should we just silently fail if phone is offhook or ringing?
1388 PhoneConstants.State state = mCM.getState(subId);
1389 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1390 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1391 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1392 mApp.startActivity(intent);
1393 }
1394 } finally {
1395 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 }
1397 }
1398
1399 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001400 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001401 }
1402
Wink Savilleb564aae2014-10-23 10:18:09 -07001403 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 if (DBG) log("call: " + number);
1405
1406 // This is just a wrapper around the ACTION_CALL intent, but we still
1407 // need to do a permission check since we're calling startActivity()
1408 // from the context of the phone app.
1409 enforceCallPermission();
1410
1411 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1412 != AppOpsManager.MODE_ALLOWED) {
1413 return;
1414 }
1415
Malcolm Chend965c8b2018-02-28 15:00:40 -08001416 final long identity = Binder.clearCallingIdentity();
1417 try {
1418 String url = createTelUrl(number);
1419 if (url == null) {
1420 return;
1421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001422
Malcolm Chend965c8b2018-02-28 15:00:40 -08001423 boolean isValid = false;
1424 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1425 if (slist != null) {
1426 for (SubscriptionInfo subInfoRecord : slist) {
1427 if (subInfoRecord.getSubscriptionId() == subId) {
1428 isValid = true;
1429 break;
1430 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001431 }
Wink Saville08874612014-08-31 19:19:58 -07001432 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001433 if (!isValid) {
1434 return;
1435 }
Wink Saville08874612014-08-31 19:19:58 -07001436
Malcolm Chend965c8b2018-02-28 15:00:40 -08001437 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1438 intent.putExtra(SUBSCRIPTION_KEY, subId);
1439 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1440 mApp.startActivity(intent);
1441 } finally {
1442 Binder.restoreCallingIdentity(identity);
1443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001444 }
1445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001447 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001448 }
1449
Wink Savilleb564aae2014-10-23 10:18:09 -07001450 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001451 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001452 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1453 }
1454
1455 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001460 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001461 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1462 }
1463
1464 /** {@hide} */
1465 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001466 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001467 }
1468
Wink Savilleb564aae2014-10-23 10:18:09 -07001469 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001471
1472 final long identity = Binder.clearCallingIdentity();
1473 try {
1474 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1475 checkSimPin.start();
1476 return checkSimPin.unlockSim(null, pin);
1477 } finally {
1478 Binder.restoreCallingIdentity(identity);
1479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 }
1481
Wink Saville9de0f752013-10-22 19:04:03 -07001482 /** {@hide} */
1483 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001484 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001485 }
1486
Wink Savilleb564aae2014-10-23 10:18:09 -07001487 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001489
1490 final long identity = Binder.clearCallingIdentity();
1491 try {
1492 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1493 checkSimPuk.start();
1494 return checkSimPuk.unlockSim(puk, pin);
1495 } finally {
1496 Binder.restoreCallingIdentity(identity);
1497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 }
1499
1500 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001501 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 * a synchronous one.
1503 */
1504 private static class UnlockSim extends Thread {
1505
1506 private final IccCard mSimCard;
1507
1508 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001509 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1510 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511
1512 // For replies from SimCard interface
1513 private Handler mHandler;
1514
1515 // For async handler to identify request type
1516 private static final int SUPPLY_PIN_COMPLETE = 100;
1517
1518 public UnlockSim(IccCard simCard) {
1519 mSimCard = simCard;
1520 }
1521
1522 @Override
1523 public void run() {
1524 Looper.prepare();
1525 synchronized (UnlockSim.this) {
1526 mHandler = new Handler() {
1527 @Override
1528 public void handleMessage(Message msg) {
1529 AsyncResult ar = (AsyncResult) msg.obj;
1530 switch (msg.what) {
1531 case SUPPLY_PIN_COMPLETE:
1532 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1533 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001534 mRetryCount = msg.arg1;
1535 if (ar.exception != null) {
1536 if (ar.exception instanceof CommandException &&
1537 ((CommandException)(ar.exception)).getCommandError()
1538 == CommandException.Error.PASSWORD_INCORRECT) {
1539 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1540 } else {
1541 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1542 }
1543 } else {
1544 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 mDone = true;
1547 UnlockSim.this.notifyAll();
1548 }
1549 break;
1550 }
1551 }
1552 };
1553 UnlockSim.this.notifyAll();
1554 }
1555 Looper.loop();
1556 }
1557
1558 /*
1559 * Use PIN or PUK to unlock SIM card
1560 *
1561 * If PUK is null, unlock SIM card with PIN
1562 *
1563 * If PUK is not null, unlock SIM card with PUK and set PIN code
1564 */
Wink Saville9de0f752013-10-22 19:04:03 -07001565 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566
1567 while (mHandler == null) {
1568 try {
1569 wait();
1570 } catch (InterruptedException e) {
1571 Thread.currentThread().interrupt();
1572 }
1573 }
1574 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1575
1576 if (puk == null) {
1577 mSimCard.supplyPin(pin, callback);
1578 } else {
1579 mSimCard.supplyPuk(puk, pin, callback);
1580 }
1581
1582 while (!mDone) {
1583 try {
1584 Log.d(LOG_TAG, "wait for done");
1585 wait();
1586 } catch (InterruptedException e) {
1587 // Restore the interrupted status
1588 Thread.currentThread().interrupt();
1589 }
1590 }
1591 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001592 int[] resultArray = new int[2];
1593 resultArray[0] = mResult;
1594 resultArray[1] = mRetryCount;
1595 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 }
1597 }
1598
1599 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001600 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001601
1602 }
1603
Wink Savilleb564aae2014-10-23 10:18:09 -07001604 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 // No permission check needed here: this call is harmless, and it's
1606 // needed for the ServiceState.requestStateUpdate() call (which is
1607 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001608 final long identity = Binder.clearCallingIdentity();
1609 try {
1610 final Phone phone = getPhone(subId);
1611 if (phone != null) {
1612 phone.updateServiceLocation();
1613 }
1614 } finally {
1615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 }
1618
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001619 @Override
1620 public boolean isRadioOn(String callingPackage) {
1621 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001622 }
1623
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001624 @Override
1625 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001627 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001628 return false;
1629 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001630
1631 final long identity = Binder.clearCallingIdentity();
1632 try {
1633 return isRadioOnForSubscriber(subId);
1634 } finally {
1635 Binder.restoreCallingIdentity(identity);
1636 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001637 }
1638
1639 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001640 final long identity = Binder.clearCallingIdentity();
1641 try {
1642 final Phone phone = getPhone(subId);
1643 if (phone != null) {
1644 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1645 } else {
1646 return false;
1647 }
1648 } finally {
1649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652
1653 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001654 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 }
Wink Saville36469e72014-06-11 15:17:00 -07001656
Wink Savilleb564aae2014-10-23 10:18:09 -07001657 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001659
1660 final long identity = Binder.clearCallingIdentity();
1661 try {
1662 final Phone phone = getPhone(subId);
1663 if (phone != null) {
1664 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1665 }
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 }
Wink Saville36469e72014-06-11 15:17:00 -07001669 }
1670
1671 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001672 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
1674
Wink Savilleb564aae2014-10-23 10:18:09 -07001675 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001676 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001677
1678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 final Phone phone = getPhone(subId);
1681 if (phone == null) {
1682 return false;
1683 }
1684 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1685 toggleRadioOnOffForSubscriber(subId);
1686 }
1687 return true;
1688 } finally {
1689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 }
Wink Saville36469e72014-06-11 15:17:00 -07001692
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001693 public boolean needMobileRadioShutdown() {
1694 /*
1695 * If any of the Radios are available, it will need to be
1696 * shutdown. So return true if any Radio is available.
1697 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001698 final long identity = Binder.clearCallingIdentity();
1699 try {
1700 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1701 Phone phone = PhoneFactory.getPhone(i);
1702 if (phone != null && phone.isRadioAvailable()) return true;
1703 }
1704 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1705 return false;
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001708 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001709 }
1710
Malcolm Chend965c8b2018-02-28 15:00:40 -08001711 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001712 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001713 enforceModifyPermission();
1714
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1718 logv("Shutting down Phone " + i);
1719 shutdownRadioUsingPhoneId(i);
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001723 }
1724 }
1725
1726 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001727 Phone phone = PhoneFactory.getPhone(phoneId);
1728 if (phone != null && phone.isRadioAvailable()) {
1729 phone.shutdownRadio();
1730 }
1731 }
1732
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001734 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001735
1736 final long identity = Binder.clearCallingIdentity();
1737 try {
1738 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1739 if (defaultPhone != null) {
1740 defaultPhone.setRadioPower(turnOn);
1741 return true;
1742 } else {
1743 loge("There's no default phone.");
1744 return false;
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001748 }
Wink Saville36469e72014-06-11 15:17:00 -07001749 }
1750
Wink Savilleb564aae2014-10-23 10:18:09 -07001751 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001753
1754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 final Phone phone = getPhone(subId);
1757 if (phone != null) {
1758 phone.setRadioPower(turnOn);
1759 return true;
1760 } else {
1761 return false;
1762 }
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 }
1767
Wink Saville36469e72014-06-11 15:17:00 -07001768 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001769 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 public boolean enableDataConnectivity() {
1771 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001772
1773 final long identity = Binder.clearCallingIdentity();
1774 try {
1775 int subId = mSubscriptionController.getDefaultDataSubId();
1776 final Phone phone = getPhone(subId);
1777 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001778 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001779 return true;
1780 } else {
1781 return false;
1782 }
1783 } finally {
1784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 }
1787
Wink Saville36469e72014-06-11 15:17:00 -07001788 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 public boolean disableDataConnectivity() {
1791 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001792
1793 final long identity = Binder.clearCallingIdentity();
1794 try {
1795 int subId = mSubscriptionController.getDefaultDataSubId();
1796 final Phone phone = getPhone(subId);
1797 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001798 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001799 return true;
1800 } else {
1801 return false;
1802 }
1803 } finally {
1804 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001805 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 }
1807
Sanket Padawe356d7632015-06-22 14:03:32 -07001808 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001809 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001810 final long identity = Binder.clearCallingIdentity();
1811 try {
1812 final Phone phone = getPhone(subId);
1813 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001814 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001815 } else {
1816 return false;
1817 }
1818 } finally {
1819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 }
1822
1823 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001824 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001825 }
1826
pkanwarae03a6b2016-11-06 20:37:09 -08001827 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001828 enforceCallPermission();
1829
1830 final long identity = Binder.clearCallingIdentity();
1831 try {
1832 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1833 return;
1834 }
1835 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1836 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1837 } finally {
1838 Binder.restoreCallingIdentity(identity);
1839 }
pkanwar32d516d2016-10-14 19:37:38 -07001840 };
1841
Wink Savilleb564aae2014-10-23 10:18:09 -07001842 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001844
1845 final long identity = Binder.clearCallingIdentity();
1846 try {
1847 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1848 return false;
1849 }
1850 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1851 } finally {
1852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 }
1855
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001857 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001858 }
1859
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001860 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001861 final long identity = Binder.clearCallingIdentity();
1862 try {
1863 Phone phone = PhoneFactory.getPhone(slotIndex);
1864 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1865 PhoneConstantConversions.convertCallState(phone.getState());
1866 } finally {
1867 Binder.restoreCallingIdentity(identity);
1868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 }
1870
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001873 final long identity = Binder.clearCallingIdentity();
1874 try {
1875 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1876 if (phone != null) {
1877 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1878 } else {
1879 return PhoneConstantConversions.convertDataState(
1880 PhoneConstants.DataState.DISCONNECTED);
1881 }
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
Sanket Padawe356d7632015-06-22 14:03:32 -07001887 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001889 final long identity = Binder.clearCallingIdentity();
1890 try {
1891 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1892 if (phone != null) {
1893 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1894 } else {
1895 return TelephonyManager.DATA_ACTIVITY_NONE;
1896 }
1897 } finally {
1898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 }
1901
1902 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001903 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001904 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001905 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001906
1907 LocationAccessPolicy.LocationPermissionResult locationResult =
1908 LocationAccessPolicy.checkLocationPermission(mApp,
1909 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1910 .setCallingPackage(callingPackage)
1911 .setCallingPid(Binder.getCallingPid())
1912 .setCallingUid(Binder.getCallingUid())
1913 .setMethod("getCellLocation")
1914 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1915 .build());
1916 switch (locationResult) {
1917 case DENIED_HARD:
1918 throw new SecurityException("Not allowed to access cell location");
1919 case DENIED_SOFT:
1920 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001924 final long identity = Binder.clearCallingIdentity();
1925 try {
1926 if (DBG_LOC) log("getCellLocation: is active user");
1927 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001928 int subId = mSubscriptionController.getDefaultDataSubId();
1929 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1930 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001931 return data;
1932 } finally {
1933 Binder.restoreCallingIdentity(identity);
1934 }
Svetoslav64fad262015-04-14 14:35:21 -07001935 }
1936
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001938 public String getNetworkCountryIsoForPhone(int phoneId) {
1939 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1940 // registered cell info, so return a NULL country instead.
1941 final long identity = Binder.clearCallingIdentity();
1942 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001943 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1944 // Get default phone in this case.
1945 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1946 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001947 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001948 // Todo: fix this when we can get the actual cellular network info when the device
1949 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001950 if (TelephonyManager.NETWORK_TYPE_IWLAN
1951 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1952 return "";
1953 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001954 Phone phone = PhoneFactory.getPhone(phoneId);
1955 if (phone != null) {
1956 ServiceStateTracker sst = phone.getServiceStateTracker();
1957 if (sst != null) {
1958 LocaleTracker lt = sst.getLocaleTracker();
1959 if (lt != null) {
1960 return lt.getCurrentCountry();
1961 }
1962 }
1963 }
1964 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001965 } finally {
1966 Binder.restoreCallingIdentity(identity);
1967 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001968 }
1969
1970 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001972 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001973 }
1974
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001976 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 mApp.enforceCallingOrSelfPermission(
1978 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001979
1980 final long identity = Binder.clearCallingIdentity();
1981 try {
1982 final Phone phone = getPhone(subId);
1983 if (phone != null) {
1984 phone.enableLocationUpdates();
1985 }
1986 } finally {
1987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
1991 @Override
1992 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001993 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001994 }
1995
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001997 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 mApp.enforceCallingOrSelfPermission(
1999 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002000
2001 final long identity = Binder.clearCallingIdentity();
2002 try {
2003 final Phone phone = getPhone(subId);
2004 if (phone != null) {
2005 phone.disableLocationUpdates();
2006 }
2007 } finally {
2008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010 }
2011
Nathan Harold31d7ff32018-10-15 20:20:30 -07002012 /**
2013 * Returns the target SDK version number for a given package name.
2014 *
2015 * @return target SDK if the package is found or INT_MAX.
2016 */
2017 private int getTargetSdk(String packageName) {
2018 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002019 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2020 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002021 if (ai != null) return ai.targetSdkVersion;
2022 } catch (PackageManager.NameNotFoundException unexpected) {
2023 }
2024 return Integer.MAX_VALUE;
2025 }
2026
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 @Override
2028 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002029 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2030 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002031 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2032 throw new SecurityException(
2033 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2034 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002035
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2037 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2038 return null;
2039 }
Svetoslav64fad262015-04-14 14:35:21 -07002040
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002041 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042
Nathan Haroldf180aac2018-06-01 18:43:55 -07002043 List<CellInfo> info = getAllCellInfo(callingPackage);
2044 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045
Nathan Haroldf180aac2018-06-01 18:43:55 -07002046 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2047 for (CellInfo ci : info) {
2048 if (ci instanceof CellInfoGsm) {
2049 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2050 } else if (ci instanceof CellInfoWcdma) {
2051 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002054 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 }
2056
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002057 private List<CellInfo> getCachedCellInfo() {
2058 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2059 for (Phone phone : PhoneFactory.getPhones()) {
2060 List<CellInfo> info = phone.getAllCellInfo();
2061 if (info != null) cellInfos.addAll(info);
2062 }
2063 return cellInfos;
2064 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065
2066 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002067 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002068 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002069 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002070
2071 LocationAccessPolicy.LocationPermissionResult locationResult =
2072 LocationAccessPolicy.checkLocationPermission(mApp,
2073 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2074 .setCallingPackage(callingPackage)
2075 .setCallingPid(Binder.getCallingPid())
2076 .setCallingUid(Binder.getCallingUid())
2077 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002078 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002079 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2080 .build());
2081 switch (locationResult) {
2082 case DENIED_HARD:
2083 throw new SecurityException("Not allowed to access cell info");
2084 case DENIED_SOFT:
2085 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 }
2087
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002088 final int targetSdk = getTargetSdk(callingPackage);
2089 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2090 return getCachedCellInfo();
2091 }
2092
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002093 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002094 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002095 final long identity = Binder.clearCallingIdentity();
2096 try {
2097 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2098 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002099 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002100 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002101 if (info != null) cellInfos.addAll(info);
2102 }
2103 return cellInfos;
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 }
2107 }
2108
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002109 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002110 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2111 requestCellInfoUpdateInternal(
2112 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2113 }
2114
2115 @Override
2116 public void requestCellInfoUpdateWithWorkSource(
2117 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2118 enforceModifyPermission();
2119 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2120 }
2121
2122 private void requestCellInfoUpdateInternal(
2123 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002124 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002125 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002126
2127 LocationAccessPolicy.LocationPermissionResult locationResult =
2128 LocationAccessPolicy.checkLocationPermission(mApp,
2129 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2130 .setCallingPackage(callingPackage)
2131 .setCallingPid(Binder.getCallingPid())
2132 .setCallingUid(Binder.getCallingUid())
2133 .setMethod("requestCellInfoUpdate")
2134 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2135 .build());
2136 switch (locationResult) {
2137 case DENIED_HARD:
2138 throw new SecurityException("Not allowed to access cell info");
2139 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002140 try {
2141 cb.onCellInfo(new ArrayList<CellInfo>());
2142 } catch (RemoteException re) {
2143 // Drop without consequences
2144 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002145 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002146 }
2147
Nathan Harolda939a962019-05-09 10:13:47 -07002148
2149 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002150 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2151
2152 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2153 }
2154
2155 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002157 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002158 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002159
2160 final long identity = Binder.clearCallingIdentity();
2161 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002162 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002163 } finally {
2164 Binder.restoreCallingIdentity(identity);
2165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
2167
Shishir Agrawala9f32182016-04-12 12:00:16 -07002168 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002169 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002170 Phone phone = PhoneFactory.getPhone(slotIndex);
2171 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002172 return null;
2173 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002174 int subId = phone.getSubId();
2175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2176 mApp, subId, callingPackage, "getImeiForSlot")) {
2177 return null;
2178 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002179
2180 final long identity = Binder.clearCallingIdentity();
2181 try {
2182 return phone.getImei();
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
2185 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002186 }
2187
2188 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002189 public String getTypeAllocationCodeForSlot(int slotIndex) {
2190 Phone phone = PhoneFactory.getPhone(slotIndex);
2191 String tac = null;
2192 if (phone != null) {
2193 String imei = phone.getImei();
2194 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2195 }
2196 return tac;
2197 }
2198
2199 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002200 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002201 Phone phone = PhoneFactory.getPhone(slotIndex);
2202 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002203 return null;
2204 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002205
Jeff Davidson913390f2018-02-23 17:11:49 -08002206 int subId = phone.getSubId();
2207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2208 mApp, subId, callingPackage, "getMeidForSlot")) {
2209 return null;
2210 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002211
2212 final long identity = Binder.clearCallingIdentity();
2213 try {
2214 return phone.getMeid();
2215 } finally {
2216 Binder.restoreCallingIdentity(identity);
2217 }
Jack Yu2af8d712017-03-15 17:14:14 -07002218 }
2219
2220 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002221 public String getManufacturerCodeForSlot(int slotIndex) {
2222 Phone phone = PhoneFactory.getPhone(slotIndex);
2223 String manufacturerCode = null;
2224 if (phone != null) {
2225 String meid = phone.getMeid();
2226 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2227 }
2228 return manufacturerCode;
2229 }
2230
2231 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002232 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002233 Phone phone = PhoneFactory.getPhone(slotIndex);
2234 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002235 return null;
2236 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002237 int subId = phone.getSubId();
2238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2239 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2240 return null;
2241 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002242
2243 final long identity = Binder.clearCallingIdentity();
2244 try {
2245 return phone.getDeviceSvn();
2246 } finally {
2247 Binder.restoreCallingIdentity(identity);
2248 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002249 }
2250
fionaxu43304da2017-11-27 22:51:16 -08002251 @Override
2252 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002253 final long identity = Binder.clearCallingIdentity();
2254 try {
2255 final Phone phone = getPhone(subId);
2256 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2257 } finally {
2258 Binder.restoreCallingIdentity(identity);
2259 }
fionaxu43304da2017-11-27 22:51:16 -08002260 }
2261
2262 @Override
2263 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 final Phone phone = getPhone(subId);
2267 return phone == null ? null : phone.getCarrierName();
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
2270 }
fionaxu43304da2017-11-27 22:51:16 -08002271 }
2272
calvinpaneed9ae82018-11-01 19:43:06 +08002273 @Override
chen xua31f22b2019-03-06 15:28:50 -08002274 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 final Phone phone = getPhone(subId);
2278 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002279 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002280 } finally {
2281 Binder.restoreCallingIdentity(identity);
2282 }
2283 }
2284
2285 @Override
chen xua31f22b2019-03-06 15:28:50 -08002286 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002290 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002291 } finally {
2292 Binder.restoreCallingIdentity(identity);
2293 }
2294 }
2295
chen xu02581692018-11-11 19:03:44 -08002296 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002297 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2298 if (!isSubscriptionMccMnc) {
2299 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2300 }
chen xu02581692018-11-11 19:03:44 -08002301 final Phone phone = PhoneFactory.getPhone(slotIndex);
2302 if (phone == null) {
2303 return TelephonyManager.UNKNOWN_CARRIER_ID;
2304 }
2305 final long identity = Binder.clearCallingIdentity();
2306 try {
2307 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2308 } finally {
2309 Binder.restoreCallingIdentity(identity);
2310 }
2311 }
2312
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 //
2314 // Internal helper methods.
2315 //
2316
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002317 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2319 *
2320 * @throws SecurityException if the caller does not have the required permission
2321 */
2322 private void enforceModifyPermission() {
2323 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2324 }
2325
2326 /**
2327 * Make sure the caller has the CALL_PHONE permission.
2328 *
2329 * @throws SecurityException if the caller does not have the required permission
2330 */
2331 private void enforceCallPermission() {
2332 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2333 }
2334
Stuart Scott8eef64f2015-04-08 15:13:54 -07002335 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002336 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002337 "ConnectivityService");
2338 }
2339
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 private String createTelUrl(String number) {
2341 if (TextUtils.isEmpty(number)) {
2342 return null;
2343 }
2344
Jake Hambye994d462014-02-03 13:10:13 -08002345 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 }
2347
Ihab Awadf9e92732013-12-05 18:02:52 -08002348 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2350 }
2351
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002352 private static void logv(String msg) {
2353 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2354 }
2355
Ihab Awadf9e92732013-12-05 18:02:52 -08002356 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2358 }
2359
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002360 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002362 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002363 }
2364
Sanket Padawe356d7632015-06-22 14:03:32 -07002365 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002366 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 final Phone phone = PhoneFactory.getPhone(slotIndex);
2370 if (phone == null) {
2371 return PhoneConstants.PHONE_TYPE_NONE;
2372 } else {
2373 return phone.getPhoneType();
2374 }
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 }
2379
2380 /**
2381 * Returns the CDMA ERI icon index to display
2382 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002383 @Override
2384 public int getCdmaEriIconIndex(String callingPackage) {
2385 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002386 }
2387
Sanket Padawe356d7632015-06-22 14:03:32 -07002388 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002389 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002391 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002392 return -1;
2393 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002394
2395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 final Phone phone = getPhone(subId);
2398 if (phone != null) {
2399 return phone.getCdmaEriIconIndex();
2400 } else {
2401 return -1;
2402 }
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 }
2407
2408 /**
2409 * Returns the CDMA ERI icon mode,
2410 * 0 - ON
2411 * 1 - FLASHING
2412 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002413 @Override
2414 public int getCdmaEriIconMode(String callingPackage) {
2415 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002416 }
2417
Sanket Padawe356d7632015-06-22 14:03:32 -07002418 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002419 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002421 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002422 return -1;
2423 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002424
2425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 final Phone phone = getPhone(subId);
2428 if (phone != null) {
2429 return phone.getCdmaEriIconMode();
2430 } else {
2431 return -1;
2432 }
2433 } finally {
2434 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 }
2437
2438 /**
2439 * Returns the CDMA ERI text,
2440 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002441 @Override
2442 public String getCdmaEriText(String callingPackage) {
2443 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002444 }
2445
Sanket Padawe356d7632015-06-22 14:03:32 -07002446 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002447 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002449 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002450 return null;
2451 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 final Phone phone = getPhone(subId);
2456 if (phone != null) {
2457 return phone.getCdmaEriText();
2458 } else {
2459 return null;
2460 }
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
2466 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002467 * Returns the CDMA MDN.
2468 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002469 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002470 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2472 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002473
2474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002477 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002478 return phone.getLine1Number();
2479 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002480 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002481 return null;
2482 }
2483 } finally {
2484 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002485 }
2486 }
2487
2488 /**
2489 * Returns the CDMA MIN.
2490 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002491 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002492 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2494 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002495
2496 final long identity = Binder.clearCallingIdentity();
2497 try {
2498 final Phone phone = getPhone(subId);
2499 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2500 return phone.getCdmaMin();
2501 } else {
2502 return null;
2503 }
2504 } finally {
2505 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002506 }
2507 }
2508
Hall Liud892bec2018-11-30 14:51:45 -08002509 @Override
2510 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2511 INumberVerificationCallback callback, String callingPackage) {
2512 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2513 != PERMISSION_GRANTED) {
2514 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2515 }
2516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2517
2518 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2519 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2520 throw new SecurityException("Calling package must be configured in the device config");
2521 }
2522
2523 if (range == null) {
2524 throw new NullPointerException("Range must be non-null");
2525 }
2526
2527 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002528 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002529
2530 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2531 }
2532
Junda Liuca05d5d2014-08-14 22:36:34 -07002533 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 * Returns true if CDMA provisioning needs to run.
2535 */
2536 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002537 final long identity = Binder.clearCallingIdentity();
2538 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002539 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002540 } finally {
2541 Binder.restoreCallingIdentity(identity);
2542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543 }
2544
2545 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002546 * Sets the voice mail number of a given subId.
2547 */
2548 @Override
2549 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002550 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002551
2552 final long identity = Binder.clearCallingIdentity();
2553 try {
2554 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2555 new Pair<String, String>(alphaTag, number), new Integer(subId));
2556 return success;
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
2559 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002560 }
2561
Ta-wei Yen87c49842016-05-13 21:19:52 -07002562 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002563 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2564 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002565 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002566 if (!TextUtils.equals(callingPackage, systemDialer)) {
2567 throw new SecurityException("caller must be system dialer");
2568 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2573 if (phoneAccountHandle == null) {
2574 return null;
2575 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002576 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002577 } finally {
2578 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002579 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002580 }
2581
2582 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002583 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002584 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002586 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002587 return null;
2588 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002589
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002590 final long identity = Binder.clearCallingIdentity();
2591 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002592 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002593 } finally {
2594 Binder.restoreCallingIdentity(identity);
2595 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002596 }
2597
2598 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002599 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2600 VisualVoicemailSmsFilterSettings settings) {
2601 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002602
2603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002606 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002607 } finally {
2608 Binder.restoreCallingIdentity(identity);
2609 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002610 }
2611
2612 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002613 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2614 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002615
2616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002619 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002620 } finally {
2621 Binder.restoreCallingIdentity(identity);
2622 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002623 }
2624
2625 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002626 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2627 String callingPackage, int subId) {
2628 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002629
2630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002633 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002634 } finally {
2635 Binder.restoreCallingIdentity(identity);
2636 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002637 }
2638
2639 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002640 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002641 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002646 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002647 } finally {
2648 Binder.restoreCallingIdentity(identity);
2649 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002650 }
2651
2652 @Override
2653 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2654 String number, int port, String text, PendingIntent sentIntent) {
2655 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002656 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002657 enforceSendSmsPermission();
2658 // Make the calls as the phone process.
2659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2662 if (port == 0) {
2663 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2664 sentIntent, null, false);
2665 } else {
2666 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2667 smsManager.sendDataMessageWithSelfPermissions(number, null,
2668 (short) port, data, sentIntent, null);
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002673 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002674 /**
fionaxu0152e512016-11-14 13:36:14 -08002675 * Sets the voice activation state of a given subId.
2676 */
2677 @Override
2678 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2680 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 final Phone phone = getPhone(subId);
2685 if (phone != null) {
2686 phone.setVoiceActivationState(activationState);
2687 } else {
2688 loge("setVoiceActivationState fails with invalid subId: " + subId);
2689 }
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002692 }
2693 }
2694
2695 /**
2696 * Sets the data activation state of a given subId.
2697 */
2698 @Override
2699 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2701 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = getPhone(subId);
2706 if (phone != null) {
2707 phone.setDataActivationState(activationState);
2708 } else {
2709 loge("setVoiceActivationState fails with invalid subId: " + subId);
2710 }
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002713 }
2714 }
2715
2716 /**
2717 * Returns the voice activation state of a given subId.
2718 */
2719 @Override
2720 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002721 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002722
fionaxu0152e512016-11-14 13:36:14 -08002723 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 if (phone != null) {
2727 return phone.getVoiceActivationState();
2728 } else {
2729 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2730 }
2731 } finally {
2732 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002733 }
2734 }
2735
2736 /**
2737 * Returns the data activation state of a given subId.
2738 */
2739 @Override
2740 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002741 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002742
fionaxu0152e512016-11-14 13:36:14 -08002743 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 if (phone != null) {
2747 return phone.getDataActivationState();
2748 } else {
2749 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2750 }
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002753 }
2754 }
2755
2756 /**
Wink Saville36469e72014-06-11 15:17:00 -07002757 * Returns the unread count of voicemails for a subId
2758 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002759 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002760 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2762 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2763 return 0;
2764 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 final Phone phone = getPhone(subId);
2768 if (phone != null) {
2769 return phone.getVoiceMessageCount();
2770 } else {
2771 return 0;
2772 }
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 }
2777
2778 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002779 * returns true, if the device is in a state where both voice and data
2780 * are supported simultaneously. This can change based on location or network condition.
2781 */
2782 @Override
2783 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 final Phone phone = getPhone(subId);
2787 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
2790 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002791 }
2792
2793 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002794 * Send the dialer code if called from the current default dialer or the caller has
2795 * carrier privilege.
2796 * @param inputCode The dialer code to send
2797 */
2798 @Override
2799 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002800 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002801 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002802 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2803 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002804 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002805 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2806 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002807 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002808
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002811 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002812 } finally {
2813 Binder.restoreCallingIdentity(identity);
2814 }
fionaxu235cc5e2017-03-06 22:25:57 -08002815 }
2816
2817 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002818 * Returns the data network type.
2819 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 *
2821 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2822 */
2823 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002824 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 final Phone phone = getPhone(getDefaultSubscription());
2828 if (phone != null) {
2829 return phone.getServiceState().getDataNetworkType();
2830 } else {
2831 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2832 }
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002835 }
Wink Saville36469e72014-06-11 15:17:00 -07002836 }
2837
Pengquan Meng0c05b502018-09-06 09:59:22 -07002838 @Override
2839 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002840 if (!isActiveSubscription(subId)) {
2841 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2842 }
2843
Pengquan Meng0c05b502018-09-06 09:59:22 -07002844 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2845 }
2846
Brad Ebinger4c460712018-10-01 10:40:55 -07002847 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002848 public boolean isInEmergencySmsMode() {
2849 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 for (Phone phone : PhoneFactory.getPhones()) {
2853 if (phone.isInEmergencySmsMode()) {
2854 return true;
2855 }
2856 }
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
2859 }
2860 return false;
2861 }
2862
2863 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002864 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2865 throws RemoteException {
2866 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002867 final long token = Binder.clearCallingIdentity();
2868 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002870 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002871 .addRegistrationCallbackForSubscription(c, subId);
2872 } finally {
2873 Binder.restoreCallingIdentity(token);
2874 }
2875 }
2876
2877 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002878 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2879 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002880 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2881 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2882 }
2883 Binder.withCleanCallingIdentity(() -> {
2884 try {
2885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002886 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002887 .removeRegistrationCallbackForSubscription(c, subId);
2888 } catch (IllegalArgumentException e) {
2889 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2890 + "is inactive, ignoring unregister.");
2891 // If the subscription is no longer active, just return, since the callback
2892 // will already have been removed internally.
2893 }
2894 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002895 }
2896
2897 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002898 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2899 throws RemoteException {
2900 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2902 final long token = Binder.clearCallingIdentity();
2903 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002904 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002905 .addCapabilitiesCallbackForSubscription(c, subId);
2906 } finally {
2907 Binder.restoreCallingIdentity(token);
2908 }
2909 }
2910
2911 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002912 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2913 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002914
2915 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2916 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2917 }
2918 Binder.withCleanCallingIdentity(() -> {
2919 try {
2920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002921 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002922 .removeCapabilitiesCallbackForSubscription(c, subId);
2923 } catch (IllegalArgumentException e) {
2924 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2925 + "is inactive, ignoring unregister.");
2926 // If the subscription is no longer active, just return, since the callback
2927 // will already have been removed internally.
2928 }
2929 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002930 }
2931
2932 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002933 public boolean isCapable(int subId, int capability, int regTech) {
2934 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2936 final long token = Binder.clearCallingIdentity();
2937 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002938 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002939 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2940 } catch (ImsException e) {
2941 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2942 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002943 } catch (IllegalArgumentException e) {
2944 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2945 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002946 } finally {
2947 Binder.restoreCallingIdentity(token);
2948 }
2949 }
2950
2951 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002952 public boolean isAvailable(int subId, int capability, int regTech) {
2953 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002954 final long token = Binder.clearCallingIdentity();
2955 try {
2956 Phone phone = getPhone(subId);
2957 if (phone == null) return false;
2958 return phone.isImsCapabilityAvailable(capability, regTech);
2959 } finally {
2960 Binder.restoreCallingIdentity(token);
2961 }
2962 }
2963
2964 @Override
2965 public boolean isAdvancedCallingSettingEnabled(int subId) {
2966 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2968 final long token = Binder.clearCallingIdentity();
2969 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002970 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002971 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2972 } finally {
2973 Binder.restoreCallingIdentity(token);
2974 }
2975 }
2976
2977 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002978 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002980 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002984 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002985 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
2989 }
2990
2991 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002992 public boolean isVtSettingEnabled(int subId) {
2993 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002997 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002998 getSlotIndexOrException(subId)).isVtEnabledByUser();
2999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
3002 }
3003
3004 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003005 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003007 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07003012 } finally {
3013 Binder.restoreCallingIdentity(identity);
3014 }
3015 }
3016
3017 @Override
3018 public boolean isVoWiFiSettingEnabled(int subId) {
3019 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003023 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003024 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
3028 }
3029
3030 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003031 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003033 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003037 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07003038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
3041 }
3042
3043 @Override
3044 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3045 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003049 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003050 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
3054 }
3055
3056 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003057 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003059 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003063 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003064 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
3071 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3073 "setVoWiFiNonPersistent");
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 ImsManager.getInstance(mApp,
Brad Ebinger2bc95702019-05-07 18:33:46 -07003078 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger4c460712018-10-01 10:40:55 -07003079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
3082 }
3083
3084 @Override
3085 public int getVoWiFiModeSetting(int subId) {
3086 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003090 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003091 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
3095 }
3096
3097 @Override
3098 public void setVoWiFiModeSetting(int subId, int mode) {
3099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3100 "setVoWiFiModeSetting");
3101 final long identity = Binder.clearCallingIdentity();
3102 try {
3103 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003104 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003105 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
3109 }
3110
3111 @Override
3112 public int getVoWiFiRoamingModeSetting(int subId) {
3113 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003117 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003118 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 @Override
3125 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3127 "setVoWiFiRoamingModeSetting");
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,
Brad Ebinger4c460712018-10-01 10:40:55 -07003132 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
3136 }
3137
3138 @Override
3139 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3141 "setRttCapabilityEnabled");
3142 final long identity = Binder.clearCallingIdentity();
3143 try {
3144 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003145 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003146 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
3149 }
3150 }
3151
3152 @Override
3153 public boolean isTtyOverVolteEnabled(int subId) {
3154 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3155 final long identity = Binder.clearCallingIdentity();
3156 try {
3157 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003158 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003159 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
3162 }
3163 }
3164
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003165 @Override
3166 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3167 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3168 final long identity = Binder.clearCallingIdentity();
3169 try {
3170 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003171 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003172 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003173 } finally {
3174 Binder.restoreCallingIdentity(identity);
3175 }
3176 }
3177
3178 @Override
3179 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3180 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3181 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003182 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3183 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3184 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003185 try {
3186 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003187 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003188 .removeProvisioningCallbackForSubscription(callback, subId);
3189 } catch (IllegalArgumentException e) {
3190 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3191 + "is inactive, ignoring unregister.");
3192 // If the subscription is no longer active, just return, since the callback will already
3193 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
3197 }
3198
3199 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003200 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3201 boolean isProvisioned) {
3202 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3203 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3204 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3205 }
3206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3207 "setProvisioningStatusForCapability");
3208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3211 Phone phone = getPhone(subId);
3212 if (phone == null) {
3213 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3214 + subId);
3215 return;
3216 }
3217 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3218 return;
3219 }
3220
3221 // this capability requires provisioning, route to the correct API.
3222 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3223 switch (capability) {
3224 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3225 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3226 ims.setVolteProvisioned(isProvisioned);
3227 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3228 ims.setWfcProvisioned(isProvisioned);
3229 }
3230 break;
3231 }
3232 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3233 // There is currently no difference in VT provisioning type.
3234 ims.setVtProvisioned(isProvisioned);
3235 break;
3236 }
3237 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3238 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3239 // change the capability of the feature instead if needed.
3240 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3241 == isProvisioned) {
3242 // No change in provisioning.
3243 return;
3244 }
3245 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3246 try {
3247 ims.changeMmTelCapability(capability, tech, isProvisioned);
3248 } catch (ImsException e) {
3249 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3250 + ", Exception" + e.getMessage());
3251 }
3252 break;
3253 }
3254 default: {
3255 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3256 + capability + "', which does not require provisioning.");
3257 }
3258 }
3259
3260 } finally {
3261 Binder.restoreCallingIdentity(identity);
3262 }
3263 }
3264
3265 @Override
3266 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3267 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3268 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3269 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3270 }
3271 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3272 final long identity = Binder.clearCallingIdentity();
3273 try {
3274 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3275 Phone phone = getPhone(subId);
3276 if (phone == null) {
3277 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3278 + subId);
3279 // We will fail with "true" as the provisioning status because this is the default
3280 // if we do not require provisioning.
3281 return true;
3282 }
3283
3284 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3285 return true;
3286 }
3287
3288 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3289 switch (capability) {
3290 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3291 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3292 return ims.isVolteProvisionedOnDevice();
3293 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3294 return ims.isWfcProvisionedOnDevice();
3295 }
3296 // This should never happen, since we are checking tech above to make sure it
3297 // is either LTE or IWLAN.
3298 throw new IllegalArgumentException("Invalid radio technology for voice "
3299 + "capability.");
3300 }
3301 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3302 // There is currently no difference in VT provisioning type.
3303 return ims.isVtProvisionedOnDevice();
3304 }
3305 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3306 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3307 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3308 }
3309 default: {
3310 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3311 + capability + "', which does not require provisioning.");
3312 }
3313 }
3314
3315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
3318 }
3319
3320 @Override
3321 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3322 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3323 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3324 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3325 }
3326 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3327 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3328 return (provisionedBits & capability) > 0;
3329 }
3330
3331 @Override
3332 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3333 boolean isProvisioned) {
3334 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3335 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3336 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3337 }
3338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3339 "setProvisioningStatusForCapability");
3340 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3341 // If the current provisioning status for capability already matches isProvisioned,
3342 // do nothing.
3343 if (((provisionedBits & capability) > 0) == isProvisioned) {
3344 return;
3345 }
3346 if (isProvisioned) {
3347 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3348 } else {
3349 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3350 }
3351 }
3352
3353 /**
3354 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3355 * technology. The bitfield should mirror the bitfield defined by
3356 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3357 */
3358 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3359 String key = getMmTelProvisioningKey(subId, tech);
3360 // Default is no capabilities are provisioned.
3361 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3362 }
3363
3364 /**
3365 * Sets the MmTel capability provisioning bitfield (defined by
3366 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3367 * technology specified.
3368 *
3369 * Note: This is a synchronous command and should not be called on UI thread.
3370 */
3371 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3372 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3373 String key = getMmTelProvisioningKey(subId, tech);
3374 editor.putInt(key, newField);
3375 editor.commit();
3376 }
3377
3378 private static String getMmTelProvisioningKey(int subId, int tech) {
3379 // resulting key is provision_ims_mmtel_{subId}_{tech}
3380 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3381 }
3382
3383 /**
3384 * Query CarrierConfig to see if the specified capability requires provisioning for the
3385 * carrier associated with the subscription id.
3386 */
3387 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3388 int capability) {
3389 CarrierConfigManager configManager = new CarrierConfigManager(context);
3390 PersistableBundle c = configManager.getConfigForSubId(subId);
3391 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003392 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003393 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3394 false);
3395 boolean requireVoiceVtProvisioning = c.getBoolean(
3396 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3397
3398 // First check to make sure that the capability requires provisioning.
3399 switch (capability) {
3400 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3401 // intentional fallthrough
3402 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3403 if (requireVoiceVtProvisioning) {
3404 // Voice and Video requires provisioning
3405 return true;
3406 }
3407 break;
3408 }
3409 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3410 if (requireUtProvisioning) {
3411 // UT requires provisioning
3412 return true;
3413 }
3414 break;
3415 }
3416 }
3417 return false;
3418 }
3419
3420 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003421 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003422 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3423 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3424 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003425 enforceReadPrivilegedPermission("getImsProvisioningInt");
3426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003429 int slotId = getSlotIndex(subId);
3430 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3431 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3432 + subId + "' for key:" + key);
3433 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3434 }
3435 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003436 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003437 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3438 + subId + "' for key:" + key);
3439 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
3443 }
3444
3445 @Override
3446 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003447 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3448 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3449 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003450 enforceReadPrivilegedPermission("getImsProvisioningString");
3451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003454 int slotId = getSlotIndex(subId);
3455 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3456 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3457 + subId + "' for key:" + key);
3458 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3459 }
3460 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003461 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003462 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3463 + subId + "' for key:" + key);
3464 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
3468 }
3469
3470 @Override
3471 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003472 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3473 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3474 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3476 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003480 int slotId = getSlotIndex(subId);
3481 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3482 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3483 + subId + "' for key:" + key);
3484 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3485 }
3486 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003487 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003488 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3489 + "' for key:" + key);
3490 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003491 } finally {
3492 Binder.restoreCallingIdentity(identity);
3493 }
3494 }
3495
3496 @Override
3497 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003498 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3499 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3500 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3502 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003503 final long identity = Binder.clearCallingIdentity();
3504 try {
3505 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003506 int slotId = getSlotIndex(subId);
3507 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3508 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3509 + subId + "' for key:" + key);
3510 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3511 }
3512 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003513 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003514 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3515 + "' for key:" + key);
3516 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003517 } finally {
3518 Binder.restoreCallingIdentity(identity);
3519 }
3520 }
3521
Brad Ebinger4c460712018-10-01 10:40:55 -07003522 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3523 int slotId = SubscriptionManager.getSlotIndex(subId);
3524 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003525 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003526 }
3527 return slotId;
3528 }
3529
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003530 private int getSlotIndex(int subId) {
3531 int slotId = SubscriptionManager.getSlotIndex(subId);
3532 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3533 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3534 }
3535 return slotId;
3536 }
3537
Wink Saville36469e72014-06-11 15:17:00 -07003538 /**
3539 * Returns the network type for a subId
3540 */
3541 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003542 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003544 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003545 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3546 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003547
Malcolm Chend965c8b2018-02-28 15:00:40 -08003548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 final Phone phone = getPhone(subId);
3551 if (phone != null) {
3552 return phone.getServiceState().getDataNetworkType();
3553 } else {
3554 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3555 }
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003559 }
3560
3561 /**
3562 * Returns the data network type
3563 */
3564 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003565 public int getDataNetworkType(String callingPackage) {
3566 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003567 }
3568
3569 /**
3570 * Returns the data network type for a subId
3571 */
3572 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003573 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003575 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003576 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3577 }
3578
Malcolm Chend965c8b2018-02-28 15:00:40 -08003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 final Phone phone = getPhone(subId);
3582 if (phone != null) {
3583 return phone.getServiceState().getDataNetworkType();
3584 } else {
3585 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3586 }
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003590 }
3591
3592 /**
Wink Saville36469e72014-06-11 15:17:00 -07003593 * Returns the Voice network type for a subId
3594 */
3595 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003596 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003598 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003599 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3600 }
3601
Malcolm Chend965c8b2018-02-28 15:00:40 -08003602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 final Phone phone = getPhone(subId);
3605 if (phone != null) {
3606 return phone.getServiceState().getVoiceNetworkType();
3607 } else {
3608 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3609 }
3610 } finally {
3611 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003613 }
3614
3615 /**
3616 * @return true if a ICC card is present
3617 */
3618 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003619 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003620 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3621 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003622 }
3623
3624 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003625 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003626 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003627 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003628 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 final Phone phone = PhoneFactory.getPhone(slotIndex);
3632 if (phone != null) {
3633 return phone.getIccCard().hasIccCard();
3634 } else {
3635 return false;
3636 }
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003640 }
3641
3642 /**
3643 * Return if the current radio is LTE on CDMA. This
3644 * is a tri-state return value as for a period of time
3645 * the mode may be unknown.
3646 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003647 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003649 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003650 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003651 @Override
3652 public int getLteOnCdmaMode(String callingPackage) {
3653 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003654 }
3655
Sanket Padawe356d7632015-06-22 14:03:32 -07003656 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003657 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003658 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003659 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003660 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3661 }
3662
Malcolm Chend965c8b2018-02-28 15:00:40 -08003663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 final Phone phone = getPhone(subId);
3666 if (phone == null) {
3667 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3668 } else {
3669 return phone.getLteOnCdmaMode();
3670 }
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003673 }
Wink Saville36469e72014-06-11 15:17:00 -07003674 }
3675
Wink Saville36469e72014-06-11 15:17:00 -07003676 /**
3677 * {@hide}
3678 * Returns Default subId, 0 in the case of single standby.
3679 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003680 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003681 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003682 }
3683
Shishir Agrawala9f32182016-04-12 12:00:16 -07003684 private int getSlotForDefaultSubscription() {
3685 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3686 }
3687
Wink Savilleb564aae2014-10-23 10:18:09 -07003688 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003689 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003690 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003691
Pengquan Meng466e2482018-09-21 15:54:48 -07003692 private boolean isActiveSubscription(int subId) {
3693 return mSubscriptionController.isActiveSubId(subId);
3694 }
3695
Ihab Awadf2177b72013-11-25 13:33:23 -08003696 /**
3697 * @see android.telephony.TelephonyManager.WifiCallingChoices
3698 */
3699 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003700 final long identity = Binder.clearCallingIdentity();
3701 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003702 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003703 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3704 getWhenToMakeWifiCallsDefaultPreference());
3705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003708 }
3709
3710 /**
3711 * @see android.telephony.TelephonyManager.WifiCallingChoices
3712 */
3713 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003717 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003718 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003722 }
3723
Sailesh Nepald1e68152013-12-12 19:08:02 -08003724 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003725 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003726 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003727 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003728
Jordan Liu73b078d2019-02-28 12:03:40 -08003729 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3730 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3731 if (phoneId == -1) {
3732 throw new IllegalArgumentException("Given slot index: " + slotIndex
3733 + " does not correspond to an active phone");
3734 }
3735 return PhoneFactory.getPhone(phoneId);
3736 }
3737
Shishir Agrawal566b7612013-10-28 14:41:00 -07003738 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003739 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3740 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3742 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003743 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003744 if (DBG) {
3745 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3746 }
3747 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3748 p2);
3749 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003750
Jordan Liu73b078d2019-02-28 12:03:40 -08003751
3752 @Override
3753 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3754 int slotIndex, String callingPackage, String aid, int p2) {
3755 enforceModifyPermission();
3756 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3757 if (DBG) {
3758 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3759 }
3760 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3761 callingPackage, aid, p2);
3762 }
3763
3764 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3765 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 if (TextUtils.equals(ISDR_AID, aid)) {
3769 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003770 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3771 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003772 if (bestComponent == null
3773 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3774 loge("The calling package is not allowed to access ISD-R.");
3775 throw new SecurityException(
3776 "The calling package is not allowed to access ISD-R.");
3777 }
Derek Tan740e1672017-06-27 14:56:27 -07003778 }
Derek Tan740e1672017-06-27 14:56:27 -07003779
Malcolm Chend965c8b2018-02-28 15:00:40 -08003780 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003781 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3782 null /* workSource */);
3783 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003784 return response;
3785 } finally {
3786 Binder.restoreCallingIdentity(identity);
3787 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003788 }
3789
3790 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003791 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3793 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003794 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3795 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3796 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003797
Jordan Liu73b078d2019-02-28 12:03:40 -08003798 @Override
3799 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3800 enforceModifyPermission();
3801 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3802 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3803 channel);
3804 }
3805
3806 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003807 final long identity = Binder.clearCallingIdentity();
3808 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003809 if (channel < 0) {
3810 return false;
3811 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003812 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3813 null /* workSource */);
3814 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003815 return success;
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003818 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003819 }
3820
3821 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003822 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003823 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3825 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003826 if (DBG) {
3827 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3828 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3829 + p3 + " data=" + data);
3830 }
3831 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3832 command, p1, p2, p3, data);
3833 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003834
Jordan Liu73b078d2019-02-28 12:03:40 -08003835 @Override
3836 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3837 int command, int p1, int p2, int p3, String data) {
3838 enforceModifyPermission();
3839 if (DBG) {
3840 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3841 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3842 + p3 + " data=" + data);
3843 }
3844 return iccTransmitApduLogicalChannelWithPermission(
3845 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3846 data);
3847 }
3848
3849 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3850 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003851 final long identity = Binder.clearCallingIdentity();
3852 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003853 if (channel < 0) {
3854 return "";
3855 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003856
Malcolm Chend965c8b2018-02-28 15:00:40 -08003857 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003858 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3859 null /* workSource */);
3860 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003861
Malcolm Chend965c8b2018-02-28 15:00:40 -08003862 // Append the returned status code to the end of the response payload.
3863 String s = Integer.toHexString(
3864 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3865 if (response.payload != null) {
3866 s = IccUtils.bytesToHexString(response.payload) + s;
3867 }
3868 return s;
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003871 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003872 }
Jake Hambye994d462014-02-03 13:10:13 -08003873
Evan Charltonc66da362014-05-16 14:06:40 -07003874 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003875 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3876 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3878 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003879 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003880 if (DBG) {
3881 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3882 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3883 }
3884 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3885 cla, command, p1, p2, p3, data);
3886 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003887
Jordan Liu73b078d2019-02-28 12:03:40 -08003888 @Override
3889 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3890 int command, int p1, int p2, int p3, String data) {
3891 enforceModifyPermission();
3892 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3893 if (DBG) {
3894 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3895 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3896 + " data=" + data);
3897 }
3898
3899 return iccTransmitApduBasicChannelWithPermission(
3900 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3901 p2, p3, data);
3902 }
3903
3904 // open APDU basic channel assuming the caller has sufficient permissions
3905 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3906 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003907 final long identity = Binder.clearCallingIdentity();
3908 try {
3909 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3910 && TextUtils.equals(ISDR_AID, data)) {
3911 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003912 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3913 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003914 if (bestComponent == null
3915 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3916 loge("The calling package is not allowed to select ISD-R.");
3917 throw new SecurityException(
3918 "The calling package is not allowed to select ISD-R.");
3919 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003920 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003921
Malcolm Chend965c8b2018-02-28 15:00:40 -08003922 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003923 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3924 null /* workSource */);
3925 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003926
Malcolm Chend965c8b2018-02-28 15:00:40 -08003927 // Append the returned status code to the end of the response payload.
3928 String s = Integer.toHexString(
3929 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3930 if (response.payload != null) {
3931 s = IccUtils.bytesToHexString(response.payload) + s;
3932 }
3933 return s;
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003936 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003937 }
3938
3939 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003940 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003941 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3943 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003944
Malcolm Chend965c8b2018-02-28 15:00:40 -08003945 final long identity = Binder.clearCallingIdentity();
3946 try {
3947 if (DBG) {
3948 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3949 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3950 }
3951
3952 IccIoResult response =
3953 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3954 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3955 subId);
3956
3957 if (DBG) {
3958 log("Exchange SIM_IO [R]" + response);
3959 }
3960
3961 byte[] result = null;
3962 int length = 2;
3963 if (response.payload != null) {
3964 length = 2 + response.payload.length;
3965 result = new byte[length];
3966 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3967 } else {
3968 result = new byte[length];
3969 }
3970
3971 result[length - 1] = (byte) response.sw2;
3972 result[length - 2] = (byte) response.sw1;
3973 return result;
3974 } finally {
3975 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003976 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003977 }
3978
Nathan Haroldb3014052017-01-25 15:57:32 -08003979 /**
3980 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3981 * on a particular subscription
3982 */
sqianb6e41952018-03-12 14:54:01 -07003983 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3985 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3986 return null;
3987 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003988
3989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 if (appType != TelephonyManager.APPTYPE_USIM
3992 && appType != TelephonyManager.APPTYPE_SIM) {
3993 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3994 return null;
3995 }
3996 Object response = sendRequest(
3997 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3998 if (response instanceof String[]) {
3999 return (String[]) response;
4000 }
4001 // Response is an Exception of some kind,
4002 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004003 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004004 } finally {
4005 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004006 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004007 }
4008
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004009 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004010 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4012 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004013
Malcolm Chend965c8b2018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4017 if (response.payload == null) {
4018 return "";
4019 }
Evan Charltonc66da362014-05-16 14:06:40 -07004020
Malcolm Chend965c8b2018-02-28 15:00:40 -08004021 // Append the returned status code to the end of the response payload.
4022 String s = Integer.toHexString(
4023 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4024 s = IccUtils.bytesToHexString(response.payload) + s;
4025 return s;
4026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
Evan Charltonc66da362014-05-16 14:06:40 -07004029 }
4030
Jake Hambye994d462014-02-03 13:10:13 -08004031 /**
4032 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4033 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4034 *
4035 * @param itemID the ID of the item to read
4036 * @return the NV item as a String, or null on error.
4037 */
4038 @Override
4039 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004040 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4042 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004043
4044 final long identity = Binder.clearCallingIdentity();
4045 try {
4046 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004047 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004048 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4049 return value;
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
4052 }
Jake Hambye994d462014-02-03 13:10:13 -08004053 }
4054
4055 /**
4056 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4057 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4058 *
4059 * @param itemID the ID of the item to read
4060 * @param itemValue the value to write, as a String
4061 * @return true on success; false on any failure
4062 */
4063 @Override
4064 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004065 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4067 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004068
4069 final long identity = Binder.clearCallingIdentity();
4070 try {
4071 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4072 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004073 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004074 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4075 return success;
4076 } finally {
4077 Binder.restoreCallingIdentity(identity);
4078 }
Jake Hambye994d462014-02-03 13:10:13 -08004079 }
4080
4081 /**
4082 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4083 * Used for device configuration by some CDMA operators.
4084 *
4085 * @param preferredRoamingList byte array containing the new PRL
4086 * @return true on success; false on any failure
4087 */
4088 @Override
4089 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4091 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004092
4093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4096 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4097 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4098 return success;
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
4101 }
Jake Hambye994d462014-02-03 13:10:13 -08004102 }
4103
4104 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004105 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004106 * Used for device configuration by some CDMA operators.
4107 *
chen xu1cc0abe2018-10-26 17:39:23 -07004108 * @param slotIndex - device slot.
4109 *
Jake Hambye994d462014-02-03 13:10:13 -08004110 * @return true on success; false on any failure
4111 */
4112 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004113 public boolean resetModemConfig(int slotIndex) {
4114 Phone phone = PhoneFactory.getPhone(slotIndex);
4115 if (phone != null) {
4116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4117 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004118
chen xu1cc0abe2018-10-26 17:39:23 -07004119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4122 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4123 return success;
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004127 }
chen xu1cc0abe2018-10-26 17:39:23 -07004128 return false;
4129 }
4130
4131 /**
4132 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4133 *
4134 * @param slotIndex - device slot.
4135 *
4136 * @return true on success; false on any failure
4137 */
4138 @Override
4139 public boolean rebootModem(int slotIndex) {
4140 Phone phone = PhoneFactory.getPhone(slotIndex);
4141 if (phone != null) {
4142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4143 mApp, phone.getSubId(), "rebootModem");
4144
4145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4148 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4149 return success;
4150 } finally {
4151 Binder.restoreCallingIdentity(identity);
4152 }
4153 }
4154 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004155 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004156
Svet Ganovb320e182015-04-16 12:30:10 -07004157 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004158 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004160 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004161 return new String[0];
4162 }
4163
Malcolm Chend965c8b2018-02-28 15:00:40 -08004164 final long identity = Binder.clearCallingIdentity();
4165 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004166 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004167 } finally {
4168 Binder.restoreCallingIdentity(identity);
4169 }
Wink Saville36469e72014-06-11 15:17:00 -07004170 }
4171
Brad Ebinger51f743a2017-01-23 13:50:20 -08004172 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004173 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4174 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004175 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004176 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004177 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004178
4179 final long identity = Binder.clearCallingIdentity();
4180 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004181 ImsResolver resolver = PhoneFactory.getImsResolver();
4182 if (resolver == null) {
4183 // may happen if the device does not support IMS.
4184 return;
4185 }
4186 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004187 } finally {
4188 Binder.restoreCallingIdentity(identity);
4189 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004190 }
4191
4192 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004193 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4194 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004195 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004196 public void disableIms(int slotId) {
4197 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004198
4199 final long identity = Binder.clearCallingIdentity();
4200 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004201 ImsResolver resolver = PhoneFactory.getImsResolver();
4202 if (resolver == null) {
4203 // may happen if the device does not support IMS.
4204 return;
4205 }
4206 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004210 }
4211
4212 /**
4213 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4214 * feature or {@link null} if the service is not available. If the feature is available, the
4215 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4216 */
4217 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004218 IImsServiceFeatureCallback callback) {
4219 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004220
4221 final long identity = Binder.clearCallingIdentity();
4222 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004223 ImsResolver resolver = PhoneFactory.getImsResolver();
4224 if (resolver == null) {
4225 // may happen if the device does not support IMS.
4226 return null;
4227 }
4228 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004229 } finally {
4230 Binder.restoreCallingIdentity(identity);
4231 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004232 }
4233
4234 /**
4235 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4236 * feature during emergency calling or {@link null} if the service is not available. If the
4237 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4238 * listener for feature updates.
4239 */
4240 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4241 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004242
4243 final long identity = Binder.clearCallingIdentity();
4244 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004245 ImsResolver resolver = PhoneFactory.getImsResolver();
4246 if (resolver == null) {
4247 // may happen if the device does not support IMS.
4248 return null;
4249 }
4250 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004254 }
4255
Brad Ebinger5f64b052017-12-14 14:26:15 -08004256 /**
4257 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004258 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004259 */
4260 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4261 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004262
4263 final long identity = Binder.clearCallingIdentity();
4264 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004265 ImsResolver resolver = PhoneFactory.getImsResolver();
4266 if (resolver == null) {
4267 // may happen if the device does not support IMS.
4268 return null;
4269 }
4270 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004274 }
4275
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004276 /**
4277 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004278 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004279 */
4280 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4281 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004282
4283 final long identity = Binder.clearCallingIdentity();
4284 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004285 ImsResolver resolver = PhoneFactory.getImsResolver();
4286 if (resolver == null) {
4287 // may happen if the device does not support IMS.
4288 return null;
4289 }
4290 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004294 }
4295
Brad Ebinger884c07b2018-02-15 16:17:40 -08004296 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004297 * Sets the ImsService Package Name that Telephony will bind to.
4298 *
4299 * @param slotId the slot ID that the ImsService should bind for.
4300 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4301 * ImsService is the device default ImsService.
4302 * @param packageName The package name of the application that contains the ImsService to bind
4303 * to.
4304 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4305 * @hide
4306 */
4307 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004308 int[] subIds = SubscriptionManager.getSubId(slotId);
4309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4310 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4311 "setImsService");
4312
Malcolm Chend965c8b2018-02-28 15:00:40 -08004313 final long identity = Binder.clearCallingIdentity();
4314 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004315 ImsResolver resolver = PhoneFactory.getImsResolver();
4316 if (resolver == null) {
4317 // may happen if the device does not support IMS.
4318 return false;
4319 }
4320 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4321 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004322 } finally {
4323 Binder.restoreCallingIdentity(identity);
4324 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004325 }
4326
4327 /**
4328 * Return the ImsService configuration.
4329 *
4330 * @param slotId The slot that the ImsService is associated with.
4331 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4332 * the device default.
4333 * @return the package name of the ImsService configuration.
4334 */
4335 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004336 int[] subIds = SubscriptionManager.getSubId(slotId);
4337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4338 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4339 "getImsService");
4340
Malcolm Chend965c8b2018-02-28 15:00:40 -08004341 final long identity = Binder.clearCallingIdentity();
4342 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004343 ImsResolver resolver = PhoneFactory.getImsResolver();
4344 if (resolver == null) {
4345 // may happen if the device does not support IMS.
4346 return "";
4347 }
4348 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004349 } finally {
4350 Binder.restoreCallingIdentity(identity);
4351 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004352 }
4353
Wink Saville36469e72014-06-11 15:17:00 -07004354 public void setImsRegistrationState(boolean registered) {
4355 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004356
4357 final long identity = Binder.clearCallingIdentity();
4358 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004359 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
Wink Saville36469e72014-06-11 15:17:00 -07004363 }
4364
4365 /**
Stuart Scott54788802015-03-30 13:18:01 -07004366 * Set the network selection mode to automatic.
4367 *
4368 */
4369 @Override
4370 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4372 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004373
Pengquan Meng466e2482018-09-21 15:54:48 -07004374 if (!isActiveSubscription(subId)) {
4375 return;
4376 }
4377
Malcolm Chend965c8b2018-02-28 15:00:40 -08004378 final long identity = Binder.clearCallingIdentity();
4379 try {
4380 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4381 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
Stuart Scott54788802015-03-30 13:18:01 -07004385 }
4386
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004387 /**
4388 * Ask the radio to connect to the input network and change selection mode to manual.
4389 *
4390 * @param subId the id of the subscription.
4391 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4392 * the operator to attach to.
4393 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4394 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4395 * normal network selection next time.
4396 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004397 */
4398 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004399 public boolean setNetworkSelectionModeManual(
4400 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4402 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004403
4404 if (!isActiveSubscription(subId)) {
4405 return false;
4406 }
4407
Malcolm Chend965c8b2018-02-28 15:00:40 -08004408 final long identity = Binder.clearCallingIdentity();
4409 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004410 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004411 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004412 if (DBG) {
4413 log("setNetworkSelectionModeManual: subId: " + subId
4414 + " operator: " + operatorInfo);
4415 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004416 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004420 }
4421
4422 /**
4423 * Scans for available networks.
4424 */
4425 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004426 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4428 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004429 LocationAccessPolicy.LocationPermissionResult locationResult =
4430 LocationAccessPolicy.checkLocationPermission(mApp,
4431 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4432 .setCallingPackage(callingPackage)
4433 .setCallingPid(Binder.getCallingPid())
4434 .setCallingUid(Binder.getCallingUid())
4435 .setMethod("getCellNetworkScanResults")
4436 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4437 .build());
4438 switch (locationResult) {
4439 case DENIED_HARD:
4440 throw new SecurityException("Not allowed to access scan results -- location");
4441 case DENIED_SOFT:
4442 return null;
4443 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004444
Pengquan Meng0c05b502018-09-06 09:59:22 -07004445 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004446 try {
4447 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004448 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004449 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004453 }
4454
4455 /**
yinxub1bed742017-04-17 11:45:04 -07004456 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004457 *
yinxub1bed742017-04-17 11:45:04 -07004458 * @param subId id of the subscription
4459 * @param request contains the radio access networks with bands/channels to scan
4460 * @param messenger callback messenger for scan results or errors
4461 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004462 * @return the id of the requested scan which can be used to stop the scan.
4463 */
4464 @Override
4465 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004466 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4468 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004469 LocationAccessPolicy.LocationPermissionResult locationResult =
4470 LocationAccessPolicy.checkLocationPermission(mApp,
4471 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4472 .setCallingPackage(callingPackage)
4473 .setCallingPid(Binder.getCallingPid())
4474 .setCallingUid(Binder.getCallingUid())
4475 .setMethod("requestNetworkScan")
4476 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4477 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004478 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4479 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4480 if (e != null) {
4481 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4482 throw e;
4483 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004484 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004485 return TelephonyScanManager.INVALID_SCAN_ID;
4486 }
4487 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004488 }
Hall Liubac7d482019-04-25 14:02:26 -07004489 int callingUid = Binder.getCallingUid();
4490 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004491 final long identity = Binder.clearCallingIdentity();
4492 try {
4493 return mNetworkScanRequestTracker.startNetworkScan(
4494 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004495 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004496 } finally {
4497 Binder.restoreCallingIdentity(identity);
4498 }
yinxu504e1392017-04-12 16:03:22 -07004499 }
4500
Hall Liub2ac8ef2019-02-28 15:56:23 -08004501 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4502 NetworkScanRequest request) {
4503 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4504 != PERMISSION_GRANTED) {
4505 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4506 + " without location access.");
4507 }
4508
4509 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4510 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004511 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4512 return new SecurityException("Specific channels must not be"
4513 + " scanned without location access.");
4514 }
4515 }
4516 }
4517
Hall Liub2ac8ef2019-02-28 15:56:23 -08004518 return null;
4519 }
4520
yinxu504e1392017-04-12 16:03:22 -07004521 /**
4522 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004523 *
4524 * @param subId id of the subscription
4525 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004526 */
4527 @Override
4528 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4530 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004531
Hall Liubac7d482019-04-25 14:02:26 -07004532 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004533 final long identity = Binder.clearCallingIdentity();
4534 try {
Hall Liubac7d482019-04-25 14:02:26 -07004535 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
yinxu504e1392017-04-12 16:03:22 -07004539 }
4540
4541 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004542 * Get the calculated preferred network type.
4543 * Used for debugging incorrect network type.
4544 *
4545 * @return the preferred network type, defined in RILConstants.java.
4546 */
4547 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004548 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004549 final Phone defaultPhone = getDefaultPhone();
4550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4551 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004552 return RILConstants.PREFERRED_NETWORK_MODE;
4553 }
4554
Malcolm Chend965c8b2018-02-28 15:00:40 -08004555 final long identity = Binder.clearCallingIdentity();
4556 try {
4557 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004558 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004559 } finally {
4560 Binder.restoreCallingIdentity(identity);
4561 }
Junda Liu84d15a22014-07-02 11:21:04 -07004562 }
4563
4564 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004565 * Get the preferred network type.
4566 * Used for device configuration by some CDMA operators.
4567 *
4568 * @return the preferred network type, defined in RILConstants.java.
4569 */
4570 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004571 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004572 TelephonyPermissions
4573 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4574 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004575
4576 final long identity = Binder.clearCallingIdentity();
4577 try {
4578 if (DBG) log("getPreferredNetworkType");
4579 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4580 int networkType = (result != null ? result[0] : -1);
4581 if (DBG) log("getPreferredNetworkType: " + networkType);
4582 return networkType;
4583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004586 }
4587
4588 /**
4589 * Set the preferred network type.
4590 * Used for device configuration by some CDMA operators.
4591 *
4592 * @param networkType the preferred network type, defined in RILConstants.java.
4593 * @return true on success; false on any failure.
4594 */
4595 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004596 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4598 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004599
4600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4603 Boolean success = (Boolean) sendRequest(
4604 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4605 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4606 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004607 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004608 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4609 }
4610 return success;
4611 } finally {
4612 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004613 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004614 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004615
4616 /**
Miaoa84611c2019-03-15 09:21:10 +08004617 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004618 *
Miaoa84611c2019-03-15 09:21:10 +08004619 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004620 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004621 * @hide
4622 */
4623 @Override
Miaoa84611c2019-03-15 09:21:10 +08004624 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004625 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004626 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004627 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004628 try {
Miaoa84611c2019-03-15 09:21:10 +08004629 if (phone != null) {
4630 return phone.hasMatchedTetherApnSetting();
4631 } else {
4632 return false;
4633 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004634 } finally {
4635 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004636 }
Junda Liu475951f2014-11-07 16:45:03 -08004637 }
4638
4639 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004640 * Set mobile data enabled
4641 * Used by the user through settings etc to turn on/off mobile data
4642 *
4643 * @param enable {@code true} turn turn data on, else {@code false}
4644 */
4645 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004646 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4648 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004649
4650 final long identity = Binder.clearCallingIdentity();
4651 try {
4652 int phoneId = mSubscriptionController.getPhoneId(subId);
4653 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4654 Phone phone = PhoneFactory.getPhone(phoneId);
4655 if (phone != null) {
4656 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004657 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004658 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004659 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004660 }
4661 } finally {
4662 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004663 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004664 }
4665
4666 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004667 * Get the user enabled state of Mobile Data.
4668 *
4669 * TODO: remove and use isUserDataEnabled.
4670 * This can't be removed now because some vendor codes
4671 * calls through ITelephony directly while they should
4672 * use TelephonyManager.
4673 *
4674 * @return true on enabled
4675 */
4676 @Override
4677 public boolean getDataEnabled(int subId) {
4678 return isUserDataEnabled(subId);
4679 }
4680
4681 /**
4682 * Get whether mobile data is enabled per user setting.
4683 *
4684 * There are other factors deciding whether mobile data is actually enabled, but they are
4685 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004686 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004687 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004688 *
4689 * @return {@code true} if data is enabled else {@code false}
4690 */
4691 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004692 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004693 try {
4694 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4695 null);
4696 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4698 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004699 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004700
4701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 int phoneId = mSubscriptionController.getPhoneId(subId);
4704 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4705 Phone phone = PhoneFactory.getPhone(phoneId);
4706 if (phone != null) {
4707 boolean retVal = phone.isUserDataEnabled();
4708 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4709 return retVal;
4710 } else {
4711 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4712 return false;
4713 }
4714 } finally {
4715 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004716 }
4717 }
4718
4719 /**
4720 * Get whether mobile data is enabled.
4721 *
4722 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4723 * whether mobile data is actually enabled.
4724 *
4725 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4726 *
4727 * @return {@code true} if data is enabled else {@code false}
4728 */
4729 @Override
4730 public boolean isDataEnabled(int subId) {
4731 try {
4732 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4733 null);
4734 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4736 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004737 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004738
4739 final long identity = Binder.clearCallingIdentity();
4740 try {
4741 int phoneId = mSubscriptionController.getPhoneId(subId);
4742 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4743 Phone phone = PhoneFactory.getPhone(phoneId);
4744 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004745 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004746 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4747 return retVal;
4748 } else {
4749 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4750 return false;
4751 }
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004754 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004755 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004756
4757 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004758 public int getCarrierPrivilegeStatus(int subId) {
4759 final Phone phone = getPhone(subId);
4760 if (phone == null) {
4761 loge("getCarrierPrivilegeStatus: Invalid subId");
4762 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4763 }
4764 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004765 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004766 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004767 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4768 }
4769 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004770 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004771 }
Junda Liu29340342014-07-10 15:23:27 -07004772
4773 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004774 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4775 final Phone phone = getPhone(subId);
4776 if (phone == null) {
4777 loge("getCarrierPrivilegeStatus: Invalid subId");
4778 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4779 }
4780 UiccProfile profile =
4781 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4782 if (profile == null) {
4783 loge("getCarrierPrivilegeStatus: No UICC");
4784 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4785 }
4786 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4787 }
4788
4789 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004790 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004791 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004792 if (TextUtils.isEmpty(pkgName))
4793 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004794 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004795 if (card == null) {
4796 loge("checkCarrierPrivilegesForPackage: No UICC");
4797 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4798 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004799 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4800 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004801 }
4802
4803 @Override
4804 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004805 if (TextUtils.isEmpty(pkgName))
4806 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004807 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4808 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4809 UiccCard card = UiccController.getInstance().getUiccCard(i);
4810 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004811 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004812 continue;
4813 }
4814
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004815 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004816 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4817 break;
4818 }
4819 }
4820
4821 return result;
Junda Liu29340342014-07-10 15:23:27 -07004822 }
Derek Tan89e89d42014-07-08 17:00:10 -07004823
4824 @Override
Junda Liue64de782015-04-16 17:19:16 -07004825 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4826 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4827 loge("phoneId " + phoneId + " is not valid.");
4828 return null;
4829 }
4830 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004831 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004832 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004833 return null ;
4834 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004835 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004836 }
4837
Amith Yamasani6e118872016-02-19 12:53:51 -08004838 @Override
4839 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004840 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004841 List<String> privilegedPackages = new ArrayList<>();
4842 List<PackageInfo> packages = null;
4843 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4844 UiccCard card = UiccController.getInstance().getUiccCard(i);
4845 if (card == null) {
4846 // No UICC in that slot.
4847 continue;
4848 }
4849 if (card.hasCarrierPrivilegeRules()) {
4850 if (packages == null) {
4851 // Only check packages in user 0 for now
4852 packages = pm.getInstalledPackagesAsUser(
4853 PackageManager.MATCH_DISABLED_COMPONENTS
4854 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4855 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4856 }
4857 for (int p = packages.size() - 1; p >= 0; p--) {
4858 PackageInfo pkgInfo = packages.get(p);
4859 if (pkgInfo != null && pkgInfo.packageName != null
4860 && card.getCarrierPrivilegeStatus(pkgInfo)
4861 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4862 privilegedPackages.add(pkgInfo.packageName);
4863 }
4864 }
4865 }
4866 }
4867 return privilegedPackages;
4868 }
4869
Wink Savilleb564aae2014-10-23 10:18:09 -07004870 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004871 final Phone phone = getPhone(subId);
4872 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004873 if (card == null) {
4874 loge("getIccId: No UICC");
4875 return null;
4876 }
4877 String iccId = card.getIccId();
4878 if (TextUtils.isEmpty(iccId)) {
4879 loge("getIccId: ICC ID is null or empty.");
4880 return null;
4881 }
4882 return iccId;
4883 }
4884
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004885 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004886 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4887 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004888 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4889 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004890
Malcolm Chend965c8b2018-02-28 15:00:40 -08004891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 final String iccId = getIccId(subId);
4894 final Phone phone = getPhone(subId);
4895 if (phone == null) {
4896 return false;
4897 }
4898 final String subscriberId = phone.getSubscriberId();
4899
4900 if (DBG_MERGE) {
4901 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4902 + subscriberId + " to " + number);
4903 }
4904
4905 if (TextUtils.isEmpty(iccId)) {
4906 return false;
4907 }
4908
4909 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4910
4911 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4912 if (alphaTag == null) {
4913 editor.remove(alphaTagPrefKey);
4914 } else {
4915 editor.putString(alphaTagPrefKey, alphaTag);
4916 }
4917
4918 // Record both the line number and IMSI for this ICCID, since we need to
4919 // track all merged IMSIs based on line number
4920 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4921 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4922 if (number == null) {
4923 editor.remove(numberPrefKey);
4924 editor.remove(subscriberPrefKey);
4925 } else {
4926 editor.putString(numberPrefKey, number);
4927 editor.putString(subscriberPrefKey, subscriberId);
4928 }
4929
4930 editor.commit();
4931 return true;
4932 } finally {
4933 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004934 }
Derek Tan7226c842014-07-02 17:42:23 -07004935 }
4936
4937 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004938 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004939 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004941 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004942 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004943 return null;
4944 }
Derek Tan97ebb422014-09-05 16:55:38 -07004945
Malcolm Chend965c8b2018-02-28 15:00:40 -08004946 final long identity = Binder.clearCallingIdentity();
4947 try {
4948 String iccId = getIccId(subId);
4949 if (iccId != null) {
4950 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4951 if (DBG_MERGE) {
4952 log("getLine1NumberForDisplay returning "
4953 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4954 }
4955 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004956 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004957 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4958 return null;
4959 } finally {
4960 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004961 }
Derek Tan7226c842014-07-02 17:42:23 -07004962 }
4963
4964 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004965 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004967 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004968 return null;
4969 }
Derek Tan97ebb422014-09-05 16:55:38 -07004970
Malcolm Chend965c8b2018-02-28 15:00:40 -08004971 final long identity = Binder.clearCallingIdentity();
4972 try {
4973 String iccId = getIccId(subId);
4974 if (iccId != null) {
4975 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4976 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4977 }
4978 return null;
4979 } finally {
4980 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004981 }
Derek Tan7226c842014-07-02 17:42:23 -07004982 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004983
4984 @Override
Jordan Liu9775d4b2019-05-06 14:45:15 -07004985 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004986 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4987 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004989 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4990 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004991 return null;
4992 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004993
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004994 final long identity = Binder.clearCallingIdentity();
4995 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004996 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004997 final TelephonyManager tele = TelephonyManager.from(context);
4998 final SubscriptionManager sub = SubscriptionManager.from(context);
4999
5000 // Figure out what subscribers are currently active
5001 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
5002 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5003 // the process, where TelephonyManager was instantiated.
5004 // Otherwise AppOps check will fail.
5005
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005006 final int[] subIds = sub.getActiveSubscriptionIdList();
Jordan Liu9775d4b2019-05-06 14:45:15 -07005007 for (int id : subIds) {
5008 // Only consider subs which match the current subId
5009 // This logic can be simplified. See b/131189269 for progress.
5010 if (subId != id) {
5011 continue;
5012 }
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005013 activeSubscriberIds.add(tele.getSubscriberId(subId));
5014 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005015
5016 // First pass, find a number override for an active subscriber
5017 String mergeNumber = null;
5018 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5019 for (String key : prefs.keySet()) {
5020 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5021 final String subscriberId = (String) prefs.get(key);
5022 if (activeSubscriberIds.contains(subscriberId)) {
5023 final String iccId = key.substring(
5024 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5025 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5026 mergeNumber = (String) prefs.get(numberKey);
5027 if (DBG_MERGE) {
5028 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5029 + " for active subscriber " + subscriberId);
5030 }
5031 if (!TextUtils.isEmpty(mergeNumber)) {
5032 break;
5033 }
5034 }
5035 }
5036 }
5037
5038 // Shortcut when no active merged subscribers
5039 if (TextUtils.isEmpty(mergeNumber)) {
5040 return null;
5041 }
5042
5043 // Second pass, find all subscribers under that line override
5044 final ArraySet<String> result = new ArraySet<>();
5045 for (String key : prefs.keySet()) {
5046 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5047 final String number = (String) prefs.get(key);
5048 if (mergeNumber.equals(number)) {
5049 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5050 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5051 final String subscriberId = (String) prefs.get(subscriberKey);
5052 if (!TextUtils.isEmpty(subscriberId)) {
5053 result.add(subscriberId);
5054 }
5055 }
5056 }
5057 }
5058
5059 final String[] resultArray = result.toArray(new String[result.size()]);
5060 Arrays.sort(resultArray);
5061 if (DBG_MERGE) {
5062 Slog.d(LOG_TAG,
5063 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5064 }
5065 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005066 } finally {
5067 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005068 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005069 }
5070
5071 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005072 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005073 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5074 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005075
5076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 final Phone phone = getPhone(subId);
5079 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5080 } finally {
5081 Binder.restoreCallingIdentity(identity);
5082 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005083 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005084
5085 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005086 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005087 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5088 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005089 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005090
5091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 final Phone phone = getPhone(subId);
5094 if (phone == null) {
5095 return false;
5096 }
5097 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5098 cdmaNonRoamingList);
5099 } finally {
5100 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005101 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005102 }
5103
5104 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005105 @Deprecated
5106 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5107 enforceModifyPermission();
5108
5109 int returnValue = 0;
5110 try {
vagdevie435a3e2018-08-15 16:01:53 -07005111 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005112 if(result.exception == null) {
5113 if (result.result != null) {
5114 byte[] responseData = (byte[])(result.result);
5115 if(responseData.length > oemResp.length) {
5116 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5117 responseData.length + "bytes. Buffer Size is " +
5118 oemResp.length + "bytes.");
5119 }
5120 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5121 returnValue = responseData.length;
5122 }
5123 } else {
5124 CommandException ex = (CommandException) result.exception;
5125 returnValue = ex.getCommandError().ordinal();
5126 if(returnValue > 0) returnValue *= -1;
5127 }
5128 } catch (RuntimeException e) {
5129 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5130 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5131 if(returnValue > 0) returnValue *= -1;
5132 }
5133
5134 return returnValue;
5135 }
5136
5137 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005138 public void setRadioCapability(RadioAccessFamily[] rafs) {
5139 try {
5140 ProxyController.getInstance().setRadioCapability(rafs);
5141 } catch (RuntimeException e) {
5142 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5143 }
5144 }
5145
5146 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005147 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005148 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005149 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005150 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005151 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005152 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005153 final long identity = Binder.clearCallingIdentity();
5154 try {
chen xufeeed752018-10-26 14:17:57 -07005155 TelephonyPermissions
5156 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5157 mApp, phone.getSubId(), "getRadioAccessFamily");
5158 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
chen xufeeed752018-10-26 14:17:57 -07005162 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005163 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005164
5165 @Override
5166 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005167 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005168 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005169
5170 final long identity = Binder.clearCallingIdentity();
5171 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005172 ImsManager.getInstance(defaultPhone.getContext(),
5173 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005177 }
5178
5179 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005180 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005181 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005183 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005184 return false;
5185 }
Svet Ganovb320e182015-04-16 12:30:10 -07005186
Malcolm Chend965c8b2018-02-28 15:00:40 -08005187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 // Check the user preference and the system-level IMS setting. Even if the user has
5190 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5191 // In the long run, we may instead need to check if there exists a connection service
5192 // which can support video calling.
5193 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005194 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005195 return imsManager.isVtEnabledByPlatform()
5196 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5197 && imsManager.isVtEnabledByUser();
5198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005201 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005202
Andrew Leea1239f22015-03-02 17:44:07 -08005203 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005204 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5205 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5206 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5207 return false;
5208 }
5209
5210 final long identity = Binder.clearCallingIdentity();
5211 try {
5212 CarrierConfigManager configManager =
5213 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005214 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005215 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
Andrew Leea1239f22015-03-02 17:44:07 -08005219 }
5220
5221 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005222 public boolean isWorldPhone(int subId, String callingPackage) {
5223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5224 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5225 return false;
5226 }
5227
5228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 CarrierConfigManager configManager =
5231 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005232 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005233 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
Andrew Leea1239f22015-03-02 17:44:07 -08005237 }
5238
Andrew Lee9431b832015-03-09 18:46:45 -07005239 @Override
5240 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005241 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005242 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005243 }
5244
5245 @Override
5246 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005247 final long identity = Binder.clearCallingIdentity();
5248 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005249 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
Andrew Lee9431b832015-03-09 18:46:45 -07005253 }
5254
Hall Liuf6668912018-10-31 17:05:23 -07005255 /**
5256 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5257 * support for the feature and device firmware support.
5258 *
5259 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5260 */
5261 @Override
5262 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005263 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005264 final Phone phone = getPhone(subscriptionId);
5265 if (phone == null) {
5266 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5267 return false;
5268 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005269 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005270 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005271 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5272 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005273 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005274 return isCarrierSupported && isDeviceSupported;
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Hall Liu98187582018-01-22 19:15:32 -08005278 }
5279
Hall Liuf6668912018-10-31 17:05:23 -07005280 /**
5281 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5282 * both also support RTT.
5283 */
5284 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005285 final long identity = Binder.clearCallingIdentity();
5286 try {
Hall Liuf6668912018-10-31 17:05:23 -07005287 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005288 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005292 }
5293
Sanket Padawe7310cc72015-01-14 09:53:20 -08005294 /**
5295 * Returns the unique device ID of phone, for example, the IMEI for
5296 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5297 *
5298 * <p>Requires Permission:
5299 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5300 */
5301 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005302 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005303 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005304 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005305 return null;
5306 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005307 int subId = phone.getSubId();
5308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5309 mApp, subId, callingPackage, "getDeviceId")) {
5310 return null;
5311 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005312
5313 final long identity = Binder.clearCallingIdentity();
5314 try {
5315 return phone.getDeviceId();
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005319 }
5320
Ping Sunc67b7c22016-03-02 19:16:45 +08005321 /**
5322 * {@hide}
5323 * Returns the IMS Registration Status on a particular subid
5324 *
5325 * @param subId
5326 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005327 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005328 Phone phone = getPhone(subId);
5329 if (phone != null) {
5330 return phone.isImsRegistered();
5331 } else {
5332 return false;
5333 }
5334 }
5335
Santos Cordon7a1885b2015-02-03 11:15:19 -08005336 @Override
5337 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5341 } finally {
5342 Binder.restoreCallingIdentity(identity);
5343 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005344 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005345
Tyler Gunn327a9722019-04-03 15:28:53 -07005346 @Override
5347 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5348 final long identity = Binder.clearCallingIdentity();
5349 try {
5350 Phone phone = getPhone(subscriptionId);
5351 if (phone == null) {
5352 return null;
5353 }
5354 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5355 } finally {
5356 Binder.restoreCallingIdentity(identity);
5357 }
5358 }
5359
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005360 /**
5361 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005362 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005363 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005364 final long identity = Binder.clearCallingIdentity();
5365 try {
5366 Phone phone = getPhone(subId);
5367 if (phone != null) {
5368 return phone.isWifiCallingEnabled();
5369 } else {
5370 return false;
5371 }
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005374 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005375 }
5376
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005377 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005378 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005379 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005380 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005381 final long identity = Binder.clearCallingIdentity();
5382 try {
5383 Phone phone = getPhone(subId);
5384 if (phone != null) {
5385 return phone.isVideoEnabled();
5386 } else {
5387 return false;
5388 }
5389 } finally {
5390 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005391 }
5392 }
5393
5394 /**
5395 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5396 * defined in {@link ImsRegistrationImplBase}.
5397 */
5398 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005399 final long identity = Binder.clearCallingIdentity();
5400 try {
5401 Phone phone = getPhone(subId);
5402 if (phone != null) {
5403 return phone.getImsRegistrationTech();
5404 } else {
5405 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5406 }
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005409 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005410 }
5411
Stuart Scott8eef64f2015-04-08 15:13:54 -07005412 @Override
5413 public void factoryReset(int subId) {
5414 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005415 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5416 return;
5417 }
5418
Svet Ganovcc087f82015-05-12 20:35:54 -07005419 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005420
Svet Ganovcc087f82015-05-12 20:35:54 -07005421 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005422 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5423 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005424 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005425 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005426 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005427 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5428 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005429 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005430 // There has been issues when Sms raw table somehow stores orphan
5431 // fragments. They lead to garbled message when new fragments come
5432 // in and combined with those stale ones. In case this happens again,
5433 // user can reset all network settings which will clean up this table.
5434 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005437 }
5438 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005439
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005440 private void cleanUpSmsRawTable(Context context) {
5441 ContentResolver resolver = context.getContentResolver();
5442 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5443 resolver.delete(uri, null, null);
5444 }
5445
Narayan Kamath1c496c22015-04-16 14:40:19 +01005446 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005447 public String getSimLocaleForSubscriber(int subId) {
5448 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5449 final Phone phone = getPhone(subId);
5450 if (phone == null) {
5451 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005452 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005453 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005454 final long identity = Binder.clearCallingIdentity();
5455 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005456 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5457 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005458 // Try and fetch the locale from the carrier properties or from the SIM language
5459 // preferences (EF-PL and EF-LI)...
5460 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005461 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005462 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5463 if (localeFromDefaultSim != null) {
5464 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5465 if (DBG) log("Using locale from subId: " + subId + " locale: "
5466 + localeFromDefaultSim);
5467 return localeFromDefaultSim.toLanguageTag();
5468 } else {
5469 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005470 }
5471 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005472
Malcolm Chend965c8b2018-02-28 15:00:40 -08005473 // The SIM language preferences only store a language (e.g. fr = French), not an
5474 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5475 // the SIM and carrier preferences does not include a country we add the country
5476 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005477 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005478 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005479 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005480 return mccLocale.toLanguageTag();
5481 }
5482
5483 if (DBG) log("No locale found - returning null");
5484 return null;
5485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005488 }
5489
5490 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005491 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005492 }
5493
Malcolm Chend965c8b2018-02-28 15:00:40 -08005494 /**
5495 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5496 */
5497 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005498 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005499 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005500
Chenjie Yu1ba97252018-01-11 18:16:20 -08005501 private final ModemActivityInfo mLastModemActivityInfo =
5502 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5503
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005504 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005505 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5506 * representing the state of the modem.
5507 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005508 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5509 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005510 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005511 */
5512 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005513 public void requestModemActivityInfo(ResultReceiver result) {
5514 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005515 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 ModemActivityInfo ret = null;
5520 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005521 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5522 CMD_GET_MODEM_ACTIVITY_INFO,
5523 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005524 if (isModemActivityInfoValid(info)) {
5525 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5526 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5527 mergedTxTimeMs[i] =
5528 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5529 }
5530 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5531 mLastModemActivityInfo.setSleepTimeMillis(
5532 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5533 mLastModemActivityInfo.setIdleTimeMillis(
5534 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5535 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5536 mLastModemActivityInfo.setRxTimeMillis(
5537 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5538 mLastModemActivityInfo.setEnergyUsed(
5539 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005540 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005541 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5542 mLastModemActivityInfo.getSleepTimeMillis(),
5543 mLastModemActivityInfo.getIdleTimeMillis(),
5544 mLastModemActivityInfo.getTxTimeMillis(),
5545 mLastModemActivityInfo.getRxTimeMillis(),
5546 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005547 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005548 Bundle bundle = new Bundle();
5549 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5550 result.send(0, bundle);
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005553 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005554 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005555
Siddharth Rayf5d29552018-06-17 15:02:38 -07005556 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5557 // less than total activity duration.
5558 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5559 if (info == null) {
5560 return false;
5561 }
5562 int activityDurationMs =
5563 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5564 int totalTxTimeMs = 0;
5565 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5566 totalTxTimeMs += info.getTxTimeMillis()[i];
5567 }
5568 return (info.isValid()
5569 && (info.getSleepTimeMillis() <= activityDurationMs)
5570 && (info.getIdleTimeMillis() <= activityDurationMs)
5571 && (info.getRxTimeMillis() <= activityDurationMs)
5572 && (totalTxTimeMs <= activityDurationMs));
5573 }
5574
Jack Yu85bd38a2015-11-09 11:34:32 -08005575 /**
5576 * {@hide}
5577 * Returns the service state information on specified subscription.
5578 */
5579 @Override
5580 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005582 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005583 return null;
5584 }
5585
Hall Liuf19c44f2018-11-27 14:38:17 -08005586 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5587 LocationAccessPolicy.checkLocationPermission(mApp,
5588 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5589 .setCallingPackage(callingPackage)
5590 .setCallingPid(Binder.getCallingPid())
5591 .setCallingUid(Binder.getCallingUid())
5592 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005593 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005594 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5595 .build());
5596
5597 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5598 LocationAccessPolicy.checkLocationPermission(mApp,
5599 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5600 .setCallingPackage(callingPackage)
5601 .setCallingPid(Binder.getCallingPid())
5602 .setCallingUid(Binder.getCallingUid())
5603 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005604 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005605 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5606 .build());
5607 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5608 boolean hasFinePermission =
5609 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5610 boolean hasCoarsePermission =
5611 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5612
Malcolm Chend965c8b2018-02-28 15:00:40 -08005613 final long identity = Binder.clearCallingIdentity();
5614 try {
5615 final Phone phone = getPhone(subId);
5616 if (phone == null) {
5617 return null;
5618 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005619
Hall Liuf19c44f2018-11-27 14:38:17 -08005620 ServiceState ss = phone.getServiceState();
5621
5622 // Scrub out the location info in ServiceState depending on what level of access
5623 // the caller has.
5624 if (hasFinePermission) return ss;
5625 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5626 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005630 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005631
5632 /**
5633 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5634 *
5635 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5636 * voicemail ringtone.
5637 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5638 * PhoneAccount.
5639 */
5640 @Override
5641 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005642 final long identity = Binder.clearCallingIdentity();
5643 try {
5644 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5645 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005646 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005647 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005648
Malcolm Chend965c8b2018-02-28 15:00:40 -08005649 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005653 }
5654
5655 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005656 * Sets the per-account voicemail ringtone.
5657 *
5658 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5659 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5660 *
5661 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5662 * voicemail ringtone.
5663 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5664 * PhoneAccount.
5665 */
5666 @Override
5667 public void setVoicemailRingtoneUri(String callingPackage,
5668 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005669 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005670 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5671 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005672 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5674 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5675 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005676 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005677
5678 final long identity = Binder.clearCallingIdentity();
5679 try {
5680 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5681 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005682 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005683 }
5684 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005687 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005688 }
5689
5690 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005691 * Returns whether vibration is set for voicemail notification in Phone settings.
5692 *
5693 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5694 * voicemail vibration setting.
5695 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5696 */
5697 @Override
5698 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005699 final long identity = Binder.clearCallingIdentity();
5700 try {
5701 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5702 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005703 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005704 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005705
Malcolm Chend965c8b2018-02-28 15:00:40 -08005706 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5707 } finally {
5708 Binder.restoreCallingIdentity(identity);
5709 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005710 }
5711
Youhan Wange64578a2016-05-02 15:32:42 -07005712 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005713 * Sets the per-account voicemail vibration.
5714 *
5715 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5716 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5717 *
5718 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5719 * voicemail vibration setting.
5720 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5721 * specific PhoneAccount.
5722 */
5723 @Override
5724 public void setVoicemailVibrationEnabled(String callingPackage,
5725 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005726 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005727 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5728 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005729 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5731 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5732 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005733 }
5734
Malcolm Chend965c8b2018-02-28 15:00:40 -08005735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5738 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005739 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005740 }
5741 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5742 } finally {
5743 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005744 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005745 }
5746
5747 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005748 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5749 *
5750 * @throws SecurityException if the caller does not have the required permission
5751 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005752 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005753 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005754 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005755 }
5756
5757 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005758 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5759 * permission.
5760 *
5761 * @throws SecurityException if the caller does not have the required permission
5762 */
5763 private void enforceSendSmsPermission() {
5764 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5765 }
5766
5767 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005768 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005769 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005770 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005771 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005772 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005776 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005777 if (componentName == null) {
5778 throw new SecurityException(
5779 "Caller not current active visual voicemail package[null]");
5780 }
5781 String vvmPackage = componentName.getPackageName();
5782 if (!callingPackage.equals(vvmPackage)) {
5783 throw new SecurityException("Caller not current active visual voicemail package["
5784 + vvmPackage + "]");
5785 }
5786 } finally {
5787 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005788 }
5789 }
5790
5791 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005792 * Return the application ID for the app type.
5793 *
5794 * @param subId the subscription ID that this request applies to.
5795 * @param appType the uicc app type.
5796 * @return Application ID for specificied app type, or null if no uicc.
5797 */
5798 @Override
5799 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005800 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005801 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005802
5803 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005804 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005805 if (phone == null) {
5806 return null;
5807 }
5808 String aid = null;
5809 try {
5810 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5811 .getApplicationByType(appType).getAid();
5812 } catch (Exception e) {
5813 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5814 }
5815 return aid;
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005818 }
Youhan Wange64578a2016-05-02 15:32:42 -07005819 }
5820
Youhan Wang4001d252016-05-11 10:29:41 -07005821 /**
5822 * Return the Electronic Serial Number.
5823 *
5824 * @param subId the subscription ID that this request applies to.
5825 * @return ESN or null if error.
5826 */
5827 @Override
5828 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005829 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005830 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005831
5832 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005833 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005834 if (phone == null) {
5835 return null;
5836 }
5837 String esn = null;
5838 try {
5839 esn = phone.getEsn();
5840 } catch (Exception e) {
5841 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5842 }
5843 return esn;
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005846 }
Youhan Wang4001d252016-05-11 10:29:41 -07005847 }
5848
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005849 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005850 * Return the Preferred Roaming List Version.
5851 *
5852 * @param subId the subscription ID that this request applies to.
5853 * @return PRLVersion or null if error.
5854 */
5855 @Override
5856 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005857 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005858 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005859
5860 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005861 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005862 if (phone == null) {
5863 return null;
5864 }
5865 String cdmaPrlVersion = null;
5866 try {
5867 cdmaPrlVersion = phone.getCdmaPrlVersion();
5868 } catch (Exception e) {
5869 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5870 }
5871 return cdmaPrlVersion;
5872 } finally {
5873 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005874 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005875 }
5876
5877 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005878 * Get snapshot of Telephony histograms
5879 * @return List of Telephony histograms
5880 * @hide
5881 */
5882 @Override
5883 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5885 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005886
5887 final long identity = Binder.clearCallingIdentity();
5888 try {
5889 return RIL.getTelephonyRILTimingHistograms();
5890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005893 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005894
5895 /**
5896 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005897 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5898 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005899 * Require system privileges. In the future we may add this to carrier APIs.
5900 *
Michele Berionne0963c862018-11-27 18:57:59 -08005901 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005902 */
5903 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005904 @TelephonyManager.SetCarrierRestrictionResult
5905 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005906 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005907 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005908
Michele Berionne0963c862018-11-27 18:57:59 -08005909 if (carrierRestrictionRules == null) {
5910 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005911 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005912
Malcolm Chend965c8b2018-02-28 15:00:40 -08005913 final long identity = Binder.clearCallingIdentity();
5914 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005915 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005916 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005917 } finally {
5918 Binder.restoreCallingIdentity(identity);
5919 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005920 }
5921
5922 /**
5923 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005924 * Get the allowed carrier list and the excluded carrier list, including the priority between
5925 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005926 * Require system privileges. In the future we may add this to carrier APIs.
5927 *
Michele Berionne0963c862018-11-27 18:57:59 -08005928 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005929 */
5930 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005931 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005932 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005933 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005934
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005937 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5938 if (response instanceof CarrierRestrictionRules) {
5939 return (CarrierRestrictionRules) response;
5940 }
5941 // Response is an Exception of some kind,
5942 // which is signalled to the user as a NULL retval
5943 return null;
5944 } catch (Exception e) {
5945 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5946 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005950 }
5951
fionaxu59545b42016-05-25 15:53:37 -07005952 /**
5953 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5954 * @param subId the subscription ID that this action applies to.
5955 * @param enabled control enable or disable metered apns.
5956 * {@hide}
5957 */
5958 @Override
5959 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5960 enforceModifyPermission();
5961 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005962
5963 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005964 if (phone == null) {
5965 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5966 return;
5967 }
5968 try {
5969 phone.carrierActionSetMeteredApnsEnabled(enabled);
5970 } catch (Exception e) {
5971 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005972 } finally {
5973 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005974 }
5975 }
5976
5977 /**
5978 * Action set from carrier signalling broadcast receivers to enable/disable radio
5979 * @param subId the subscription ID that this action applies to.
5980 * @param enabled control enable or disable radio.
5981 * {@hide}
5982 */
5983 @Override
5984 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5985 enforceModifyPermission();
5986 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005987
5988 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005989 if (phone == null) {
5990 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5991 return;
5992 }
5993 try {
5994 phone.carrierActionSetRadioEnabled(enabled);
5995 } catch (Exception e) {
5996 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005999 }
6000 }
6001
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006002 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006003 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6004 * network status based on which carrier apps could apply actions accordingly,
6005 * enable/disable default url handler for example.
6006 *
6007 * @param subId the subscription ID that this action applies to.
6008 * @param report control start/stop reporting the default network status.
6009 * {@hide}
6010 */
6011 @Override
6012 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6013 enforceModifyPermission();
6014 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006015
6016 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006017 if (phone == null) {
6018 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6019 return;
6020 }
6021 try {
6022 phone.carrierActionReportDefaultNetworkStatus(report);
6023 } catch (Exception e) {
6024 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006025 } finally {
6026 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006027 }
6028 }
6029
6030 /**
fionaxud9622282017-07-17 17:51:30 -07006031 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6032 * @param subId the subscription ID that this action applies to.
6033 * {@hide}
6034 */
6035 @Override
6036 public void carrierActionResetAll(int subId) {
6037 enforceModifyPermission();
6038 final Phone phone = getPhone(subId);
6039 if (phone == null) {
6040 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6041 return;
6042 }
6043 try {
6044 phone.carrierActionResetAll();
6045 } catch (Exception e) {
6046 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6047 }
6048 }
6049
6050 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006051 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6052 * bug report is being generated.
6053 */
6054 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006055 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006056 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6057 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006058 writer.println("Permission Denial: can't dump Phone from pid="
6059 + Binder.getCallingPid()
6060 + ", uid=" + Binder.getCallingUid()
6061 + "without permission "
6062 + android.Manifest.permission.DUMP);
6063 return;
6064 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006065 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006066 }
Jack Yueb89b242016-06-22 13:27:47 -07006067
Brad Ebingerdac2f002018-04-03 15:17:52 -07006068 @Override
6069 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6070 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6071 throws RemoteException {
6072 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6073 }
6074
Jack Yueb89b242016-06-22 13:27:47 -07006075 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006076 * Get aggregated video call data usage since boot.
6077 *
6078 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6079 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006080 * {@hide}
6081 */
6082 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006083 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006084 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6085 null);
6086
Malcolm Chend965c8b2018-02-28 15:00:40 -08006087 final long identity = Binder.clearCallingIdentity();
6088 try {
6089 // NetworkStatsService keeps tracking the active network interface and identity. It
6090 // records the delta with the corresponding network identity.
6091 // We just return the total video call data usage snapshot since boot.
6092 Phone phone = getPhone(subId);
6093 if (phone != null) {
6094 return phone.getVtDataUsage(perUidStats);
6095 }
6096 return null;
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006099 }
Jack Yueb89b242016-06-22 13:27:47 -07006100 }
Jack Yu75ab2952016-07-08 14:29:33 -07006101
6102 /**
6103 * Policy control of data connection. Usually used when data limit is passed.
6104 * @param enabled True if enabling the data, otherwise disabling.
6105 * @param subId Subscription index
6106 * {@hide}
6107 */
6108 @Override
6109 public void setPolicyDataEnabled(boolean enabled, int subId) {
6110 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006111
6112 final long identity = Binder.clearCallingIdentity();
6113 try {
6114 Phone phone = getPhone(subId);
6115 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006116 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006117 }
6118 } finally {
6119 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006120 }
6121 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006122
6123 /**
6124 * Get Client request stats
6125 * @return List of Client Request Stats
6126 * @hide
6127 */
6128 @Override
6129 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006131 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006132 return null;
6133 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006134 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006135
Malcolm Chend965c8b2018-02-28 15:00:40 -08006136 final long identity = Binder.clearCallingIdentity();
6137 try {
6138 if (phone != null) {
6139 return phone.getClientRequestStats();
6140 }
6141
6142 return null;
6143 } finally {
6144 Binder.restoreCallingIdentity(identity);
6145 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006146 }
6147
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006148 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006149 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006150 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006151 }
Jack Yueb4124c2017-02-16 15:32:43 -08006152
6153 /**
Grace Chen70990072017-03-24 17:21:30 -07006154 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006155 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006156 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006157 * @param state State of SIM (power down, power up, pass through)
6158 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6159 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6160 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006161 *
6162 **/
6163 @Override
Grace Chen70990072017-03-24 17:21:30 -07006164 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006165 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006166 Phone phone = PhoneFactory.getPhone(slotIndex);
6167
vagdevie435a3e2018-08-15 16:01:53 -07006168 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6169
Malcolm Chend965c8b2018-02-28 15:00:40 -08006170 final long identity = Binder.clearCallingIdentity();
6171 try {
6172 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006173 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006174 }
6175 } finally {
6176 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006177 }
6178 }
Shuo Qiandd210312017-04-12 22:11:33 +00006179
Tyler Gunn65d45c22017-06-05 11:22:26 -07006180 private boolean isUssdApiAllowed(int subId) {
6181 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006182 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006183 if (configManager == null) {
6184 return false;
6185 }
6186 PersistableBundle pb = configManager.getConfigForSubId(subId);
6187 if (pb == null) {
6188 return false;
6189 }
6190 return pb.getBoolean(
6191 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6192 }
6193
Shuo Qiandd210312017-04-12 22:11:33 +00006194 /**
6195 * Check if phone is in emergency callback mode
6196 * @return true if phone is in emergency callback mode
6197 * @param subId sub id
6198 */
goneil9c5f4872017-12-05 14:07:56 -08006199 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006200 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006201 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006202 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006203
6204 final long identity = Binder.clearCallingIdentity();
6205 try {
6206 if (phone != null) {
6207 return phone.isInEcm();
6208 } else {
6209 return false;
6210 }
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006213 }
6214 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006215
6216 /**
6217 * Get the current signal strength information for the given subscription.
6218 * Because this information is not updated when the device is in a low power state
6219 * it should not be relied-upon to be current.
6220 * @param subId Subscription index
6221 * @return the most recent cached signal strength info from the modem
6222 */
6223 @Override
6224 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006225 final long identity = Binder.clearCallingIdentity();
6226 try {
6227 Phone p = getPhone(subId);
6228 if (p == null) {
6229 return null;
6230 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006231
Malcolm Chend965c8b2018-02-28 15:00:40 -08006232 return p.getSignalStrength();
6233 } finally {
6234 Binder.restoreCallingIdentity(identity);
6235 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006236 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006237
Pengquan Meng9140aec2018-08-22 14:49:57 -07006238 /**
chen xu907e5a22018-10-11 13:21:04 -07006239 * Get the current modem radio state for the given slot.
6240 * @param slotIndex slot index.
6241 * @param callingPackage the name of the package making the call.
6242 * @return the current radio power state from the modem
6243 */
6244 @Override
6245 public int getRadioPowerState(int slotIndex, String callingPackage) {
6246 Phone phone = PhoneFactory.getPhone(slotIndex);
6247 if (phone != null) {
6248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6249 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6250 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6251 }
6252
6253 final long identity = Binder.clearCallingIdentity();
6254 try {
6255 return phone.getRadioPowerState();
6256 } finally {
6257 Binder.restoreCallingIdentity(identity);
6258 }
6259 }
6260 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6261 }
6262
6263 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006264 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6265 *
6266 * <p>Requires one of the following permissions:
6267 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6268 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6269 * privileges.
6270 *
6271 * @param subId subscription id
6272 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6273 * {@code false}.
6274 */
6275 @Override
6276 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006277 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6278 null /* message */);
6279
Pengquan Meng0c05b502018-09-06 09:59:22 -07006280 boolean isEnabled = false;
6281 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006282 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006283 Phone phone = getPhone(subId);
6284 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006285 } catch (Exception e) {
6286 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6287 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006288 } finally {
6289 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006290 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006291 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006292 }
6293
6294
6295 /**
6296 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6297 *
6298 * <p> Requires permission:
6299 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6300 * privileges.
6301 *
6302 * @param subId subscription id
6303 * @param isEnabled {@code true} means enable, {@code false} means disable.
6304 */
6305 @Override
6306 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6308 mApp, subId, "setDataRoamingEnabled");
6309
Pengquan Meng0c05b502018-09-06 09:59:22 -07006310 final long identity = Binder.clearCallingIdentity();
6311 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006312 Phone phone = getPhone(subId);
6313 if (phone != null) {
6314 phone.setDataRoamingEnabled(isEnabled);
6315 }
6316 } finally {
6317 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006318 }
6319 }
6320
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006321 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006322 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006323 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6324 mApp, subId, "isManualNetworkSelectionAllowed");
6325
Pengquan Meng312de0c2018-10-03 12:19:13 -07006326 boolean isAllowed = true;
6327 final long identity = Binder.clearCallingIdentity();
6328 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006329 Phone phone = getPhone(subId);
6330 if (phone != null) {
6331 isAllowed = phone.isCspPlmnEnabled();
6332 }
6333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
6336 return isAllowed;
6337 }
6338
6339 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006340 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006341 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006342 try {
6343 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006344 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006345 } catch (SecurityException e) {
6346 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6347 // has carrier privileges on an active UICC
6348 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6349 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006350 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006351 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006352 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006353
6354 final long identity = Binder.clearCallingIdentity();
6355 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006356 UiccController uiccController = UiccController.getInstance();
6357 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006358 if (hasReadPermission) {
6359 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006360 }
Jordan Liu67997952019-04-22 15:10:43 -07006361
6362 // Remove private info if the caller doesn't have access
6363 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6364 for (UiccCardInfo cardInfo : cardInfos) {
6365 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6366 // is available
6367 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6368 if (card == null || card.getUiccProfile() == null) {
6369 // assume no access if the card or profile is unavailable
6370 filteredInfos.add(cardInfo.getUnprivileged());
6371 continue;
6372 }
6373 UiccProfile profile = card.getUiccProfile();
6374 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6375 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6376 filteredInfos.add(cardInfo);
6377 } else {
6378 filteredInfos.add(cardInfo.getUnprivileged());
6379 }
6380 }
6381 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
6385 }
6386
6387 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006388 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006389 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006390
Malcolm Chend965c8b2018-02-28 15:00:40 -08006391 final long identity = Binder.clearCallingIdentity();
6392 try {
6393 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6394 if (slots == null) {
6395 Rlog.i(LOG_TAG, "slots is null.");
6396 return null;
6397 }
6398
6399 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6400 for (int i = 0; i < slots.length; i++) {
6401 UiccSlot slot = slots[i];
6402 if (slot == null) {
6403 continue;
6404 }
6405
6406 String cardId;
6407 UiccCard card = slot.getUiccCard();
6408 if (card != null) {
6409 cardId = card.getCardId();
6410 } else {
6411 cardId = slot.getIccId();
6412 }
6413
Jordan Liu857451f2019-05-09 16:35:35 -07006414 if (cardId != null) {
6415 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6416 // if cardId is an EID, it's all digits so this is fine
6417 cardId = IccUtils.stripTrailingFs(cardId);
6418 }
6419
Malcolm Chend965c8b2018-02-28 15:00:40 -08006420 int cardState = 0;
6421 switch (slot.getCardState()) {
6422 case CARDSTATE_ABSENT:
6423 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6424 break;
6425 case CARDSTATE_PRESENT:
6426 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6427 break;
6428 case CARDSTATE_ERROR:
6429 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6430 break;
6431 case CARDSTATE_RESTRICTED:
6432 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6433 break;
6434 default:
6435 break;
6436
6437 }
6438
6439 infos[i] = new UiccSlotInfo(
6440 slot.isActive(),
6441 slot.isEuicc(),
6442 cardId,
6443 cardState,
6444 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006445 slot.isExtendedApduSupported(),
6446 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006447 }
6448 return infos;
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006451 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006452 }
6453
6454 @Override
6455 public boolean switchSlots(int[] physicalSlots) {
6456 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006457
6458 final long identity = Binder.clearCallingIdentity();
6459 try {
6460 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006464 }
Jack Yu4c988042018-02-27 15:30:01 -08006465
6466 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006467 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006468 final long identity = Binder.clearCallingIdentity();
6469 try {
6470 return UiccController.getInstance().getCardIdForDefaultEuicc();
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
6474 }
6475
6476 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006477 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6478 enforceModifyPermission();
6479 final Phone phone = getPhone(subId);
6480 if (phone == null) {
6481 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6482 return;
6483 }
6484
Malcolm Chend965c8b2018-02-28 15:00:40 -08006485 final long identity = Binder.clearCallingIdentity();
6486 try {
6487 phone.setRadioIndicationUpdateMode(filters, mode);
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
Jack Yu4c988042018-02-27 15:30:01 -08006491 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006492
6493 /**
goneil47ffb6e2018-04-06 15:40:58 -07006494 * A test API to reload the UICC profile.
6495 *
6496 * <p>Requires that the calling app has permission
6497 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6498 * @hide
6499 */
6500 @Override
6501 public void refreshUiccProfile(int subId) {
6502 enforceModifyPermission();
6503
6504 final long identity = Binder.clearCallingIdentity();
6505 try {
6506 Phone phone = getPhone(subId);
6507 if (phone == null) {
6508 return;
6509 }
6510 UiccCard uiccCard = phone.getUiccCard();
6511 if (uiccCard == null) {
6512 return;
6513 }
6514 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6515 if (uiccProfile == null) {
6516 return;
6517 }
6518 uiccProfile.refresh();
6519 } finally {
6520 Binder.restoreCallingIdentity(identity);
6521 }
6522 }
6523
6524 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006525 * Returns false if the mobile data is disabled by default, otherwise return true.
6526 */
6527 private boolean getDefaultDataEnabled() {
6528 return "true".equalsIgnoreCase(
6529 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6530 }
6531
6532 /**
6533 * Returns true if the data roaming is enabled by default, i.e the system property
6534 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6535 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6536 */
6537 private boolean getDefaultDataRoamingEnabled(int subId) {
6538 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006539 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006540 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6541 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6542 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6543 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6544 return isDataRoamingEnabled;
6545 }
6546
6547 /**
6548 * Returns the default network type for the given {@code subId}, if the default network type is
6549 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6550 */
6551 private int getDefaultNetworkType(int subId) {
6552 return Integer.parseInt(
6553 TelephonyManager.getTelephonyProperty(
6554 mSubscriptionController.getPhoneId(subId),
6555 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6556 String.valueOf(Phone.PREFERRED_NT_MODE)));
6557 }
fionaxua13278b2018-03-21 00:08:13 -07006558
6559 @Override
6560 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6561 gid1, String gid2, String plmn, String spn) {
6562 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006563
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 final Phone phone = getPhone(subId);
6567 if (phone == null) {
6568 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6569 return;
6570 }
6571 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6572 } finally {
6573 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006574 }
fionaxua13278b2018-03-21 00:08:13 -07006575 }
6576
6577 @Override
6578 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006579 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006580
6581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 final Phone phone = getPhone(subId);
6584 if (phone == null) {
6585 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6586 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6587 }
6588 return phone.getCarrierIdListVersion();
6589 } finally {
6590 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006591 }
fionaxua13278b2018-03-21 00:08:13 -07006592 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006593
6594 @Override
6595 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6597 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6598 return -1;
6599 }
6600
6601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6604 } finally {
6605 Binder.restoreCallingIdentity(identity);
6606 }
6607 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006608
6609 @Override
6610 public int getCdmaRoamingMode(int subId) {
6611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6612 mApp, subId, "getCdmaRoamingMode");
6613
6614 final long identity = Binder.clearCallingIdentity();
6615 try {
6616 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
6620 }
6621
6622 @Override
6623 public boolean setCdmaRoamingMode(int subId, int mode) {
6624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6625 mApp, subId, "setCdmaRoamingMode");
6626
6627 final long identity = Binder.clearCallingIdentity();
6628 try {
6629 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
6632 }
6633 }
6634
6635 @Override
6636 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6638 mApp, subId, "setCdmaSubscriptionMode");
6639
6640 final long identity = Binder.clearCallingIdentity();
6641 try {
6642 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
6646 }
chen xu7ee67862018-10-30 22:27:10 -07006647
sqian2fff4a32018-11-05 14:18:37 -08006648 private void ensureUserRunning(int userId) {
6649 if (!mUserManager.isUserRunning(userId)) {
6650 throw new IllegalStateException("User " + userId + " does not exist or not running");
6651 }
6652 }
6653
6654 /**
6655 * Returns a list of SMS apps on a given user.
6656 *
6657 * Only the shell user (UID 2000 or 0) can call it.
6658 * Target user must be running.
6659 */
6660 @Override
6661 public String[] getSmsApps(int userId) {
6662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6663 ensureUserRunning(userId);
6664
6665 final Collection<SmsApplicationData> apps =
6666 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6667
6668 String[] ret = new String[apps.size()];
6669 int i = 0;
6670 for (SmsApplicationData app : apps) {
6671 ret[i++] = app.mPackageName;
6672 }
6673 return ret;
6674 }
6675
6676 /**
6677 * Returns the default SMS app package name on a given user.
6678 *
6679 * Only the shell user (UID 2000 or 0) can call it.
6680 * Target user must be running.
6681 */
6682 @Override
6683 public String getDefaultSmsApp(int userId) {
6684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6685 ensureUserRunning(userId);
6686
6687 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6688 /* updateIfNeeded= */ true, userId);
6689 return cn == null ? null : cn.getPackageName();
6690 }
6691
6692 /**
6693 * Set a package as the default SMS app on a given user.
6694 *
6695 * Only the shell user (UID 2000 or 0) can call it.
6696 * Target user must be running.
6697 */
6698 @Override
6699 public void setDefaultSmsApp(int userId, String packageName) {
6700 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6701 ensureUserRunning(userId);
6702
6703 boolean found = false;
6704 for (String pkg : getSmsApps(userId)) {
6705 if (TextUtils.equals(packageName, pkg)) {
6706 found = true;
6707 break;
6708 }
6709 }
6710 if (!found) {
6711 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6712 }
6713
6714 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6715 }
6716
chen xu7ee67862018-10-30 22:27:10 -07006717 @Override
sqian65eefe12019-02-22 15:55:18 -08006718 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006719 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006720 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006721 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006722 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6723 }
6724 final long identity = Binder.clearCallingIdentity();
6725 try {
sqian991b35e2018-12-12 16:48:18 -08006726 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6727 for (Phone phone: PhoneFactory.getPhones()) {
6728 if (phone.getEmergencyNumberTracker() != null
6729 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6730 emergencyNumberListInternal.put(
6731 phone.getSubId(),
6732 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6733 }
sqian03bca152018-12-05 18:48:28 -08006734 }
sqian991b35e2018-12-12 16:48:18 -08006735 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006736 } finally {
6737 Binder.restoreCallingIdentity(identity);
6738 }
sqian04b86072018-11-07 14:02:21 -08006739 }
6740
6741 @Override
sqian65eefe12019-02-22 15:55:18 -08006742 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006743 final Phone defaultPhone = getDefaultPhone();
6744 if (!exactMatch) {
6745 TelephonyPermissions
6746 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006747 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006748 }
6749 final long identity = Binder.clearCallingIdentity();
6750 try {
sqian991b35e2018-12-12 16:48:18 -08006751 for (Phone phone: PhoneFactory.getPhones()) {
6752 if (phone.getEmergencyNumberTracker() != null
6753 && phone.getEmergencyNumberTracker() != null) {
6754 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6755 number, exactMatch)) {
6756 return true;
sqian03bca152018-12-05 18:48:28 -08006757 }
6758 }
sqian03bca152018-12-05 18:48:28 -08006759 }
6760 return false;
6761 } finally {
6762 Binder.restoreCallingIdentity(identity);
6763 }
6764 }
6765
sqian9d4df8b2019-01-15 18:32:07 -08006766 /**
6767 * Update emergency number list for test mode.
6768 */
6769 @Override
6770 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6771 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6772 "updateEmergencyNumberListTestMode");
6773
6774 final long identity = Binder.clearCallingIdentity();
6775 try {
6776 for (Phone phone: PhoneFactory.getPhones()) {
6777 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6778 if (tracker != null) {
6779 tracker.executeEmergencyNumberTestModeCommand(action, num);
6780 }
6781 }
6782 } finally {
6783 Binder.restoreCallingIdentity(identity);
6784 }
6785 }
6786
6787 /**
6788 * Get the full emergency number list for test mode.
6789 */
6790 @Override
6791 public List<String> getEmergencyNumberListTestMode() {
6792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6793 "getEmergencyNumberListTestMode");
6794
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
6797 Set<String> emergencyNumbers = new HashSet<>();
6798 for (Phone phone: PhoneFactory.getPhones()) {
6799 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6800 if (tracker != null) {
6801 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6802 emergencyNumbers.add(num.getNumber());
6803 }
6804 }
6805 }
6806 return new ArrayList<>(emergencyNumbers);
6807 } finally {
6808 Binder.restoreCallingIdentity(identity);
6809 }
6810 }
6811
sqian04b86072018-11-07 14:02:21 -08006812 @Override
chen xu7ee67862018-10-30 22:27:10 -07006813 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6814 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6815 Phone phone = getPhone(subId);
6816 if (phone == null) {
6817 return null;
6818 }
6819 final long identity = Binder.clearCallingIdentity();
6820 try {
6821 UiccProfile profile = UiccController.getInstance()
6822 .getUiccProfileForPhone(phone.getPhoneId());
6823 if (profile != null) {
6824 return profile.getCertsFromCarrierPrivilegeAccessRules();
6825 }
6826 } finally {
6827 Binder.restoreCallingIdentity(identity);
6828 }
6829 return null;
6830 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006831
6832 /**
6833 * Enable or disable a modem stack.
6834 */
6835 @Override
6836 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6837 enforceModifyPermission();
6838
6839 final long identity = Binder.clearCallingIdentity();
6840 try {
6841 Phone phone = PhoneFactory.getPhone(slotIndex);
6842 if (phone == null) {
6843 return false;
6844 } else {
6845 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6846 }
6847 } finally {
6848 Binder.restoreCallingIdentity(identity);
6849 }
6850 }
Micheled3107c52018-12-21 15:00:11 -08006851
Malcolm Chen33f55e12019-03-27 18:34:05 -07006852 /**
6853 * Whether a modem stack is enabled or not.
6854 */
6855 @Override
6856 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6857 Phone phone = PhoneFactory.getPhone(slotIndex);
6858 if (phone == null) return false;
6859
6860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6861 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6862 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6863 }
6864
6865 final long identity = Binder.clearCallingIdentity();
6866 try {
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07006867 try {
6868 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6869 } catch (NoSuchElementException ex) {
6870 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6871 }
Malcolm Chen33f55e12019-03-27 18:34:05 -07006872 } finally {
6873 Binder.restoreCallingIdentity(identity);
6874 }
6875 }
6876
Micheled3107c52018-12-21 15:00:11 -08006877 @Override
Michele2fb0f222019-03-19 14:58:42 -07006878 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006879 enforceModifyPermission();
6880
6881 final long identity = Binder.clearCallingIdentity();
6882 try {
6883 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006884 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006885 .commit();
6886 } finally {
6887 Binder.restoreCallingIdentity(identity);
6888 }
6889 }
6890
6891 @Override
Michele2fb0f222019-03-19 14:58:42 -07006892 @TelephonyManager.IsMultiSimSupportedResult
6893 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006895 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6896 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006897 }
Micheled3107c52018-12-21 15:00:11 -08006898
6899 final long identity = Binder.clearCallingIdentity();
6900 try {
Michele2fb0f222019-03-19 14:58:42 -07006901 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006902 } finally {
6903 Binder.restoreCallingIdentity(identity);
6904 }
6905 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006906
Michele2fb0f222019-03-19 14:58:42 -07006907 @TelephonyManager.IsMultiSimSupportedResult
6908 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006909 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6910 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6911 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006912 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6913 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006914 }
6915 // Check if the hardware supports multisim functionality. If usage of multisim is not
6916 // supported by the modem, indicate that it is restricted.
6917 PhoneCapability staticCapability =
6918 mPhoneConfigurationManager.getStaticPhoneCapability();
6919 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006920 loge("isMultiSimSupportedInternal: no static configuration available");
6921 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006922 }
6923 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006924 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6925 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006926 }
6927 // Check if support of multiple SIMs is restricted by carrier
6928 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006929 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006930 }
6931
Michele2fb0f222019-03-19 14:58:42 -07006932 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006933 }
6934
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006935 /**
6936 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006937 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6938 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6939 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006940 * @param numOfSims number of active sims we want to switch to
6941 */
6942 @Override
6943 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006944 if (numOfSims == 1) {
6945 enforceModifyPermission();
6946 } else {
6947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6948 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6949 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006950 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006951
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006952 try {
Michele30b57b22019-03-01 12:01:14 -08006953 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006954 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006955 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6956 return;
6957 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006958 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6959 } finally {
6960 Binder.restoreCallingIdentity(identity);
6961 }
6962 }
6963
6964 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006965 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006966 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006967 */
6968 @Override
6969 public boolean isRebootRequiredForModemConfigChange() {
6970 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6971 final long identity = Binder.clearCallingIdentity();
6972 try {
6973 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6974 } finally {
6975 Binder.restoreCallingIdentity(identity);
6976 }
6977 }
6978
Pengquan Meng92d253b2019-02-06 11:12:53 -08006979 private void updateModemStateMetrics() {
6980 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6981 // TODO: check the state for each modem if the api is ready.
6982 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6983 }
6984
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006985 @Override
6986 public int[] getSlotsMapping() {
6987 enforceReadPrivilegedPermission("getSlotsMapping");
6988
6989 final long identity = Binder.clearCallingIdentity();
6990 try {
6991 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6992 // All logical slots should have a mapping to a physical slot.
6993 int[] logicalSlotsMapping = new int[phoneCount];
6994 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6995 for (int i = 0; i < slotInfos.length; i++) {
6996 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6997 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6998 }
6999 }
7000 return logicalSlotsMapping;
7001 } finally {
7002 Binder.restoreCallingIdentity(identity);
7003 }
7004 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007005
7006 /**
7007 * Get the IRadio HAL Version
7008 */
7009 @Override
7010 public int getRadioHalVersion() {
7011 Phone phone = getDefaultPhone();
7012 if (phone == null) return -1;
7013 HalVersion hv = phone.getHalVersion();
7014 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7015 return hv.major * 100 + hv.minor;
7016 }
Malcolm Chen460810d2019-04-10 18:25:07 -07007017
7018 /**
Malcolm Chen29739692019-04-18 13:51:02 -07007019 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7020 * corresponding network requests on a subId.
7021 *
7022 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07007023 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07007024 * 2) APN is un-metered for this subscription, or
7025 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7026 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7027 *
7028 * @return whether data is allowed for a apn type.
7029 *
7030 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07007031 */
7032 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07007033 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07007034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07007035 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7036 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07007037 }
7038
7039 // Now that all security checks passes, perform the operation as ourselves.
7040 final long identity = Binder.clearCallingIdentity();
7041 try {
7042 Phone phone = getPhone(subId);
7043 if (phone == null) return false;
7044
Jack Yu40306fc2019-05-13 16:54:09 -07007045 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen29739692019-04-18 13:51:02 -07007046 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
7050 }
7051
7052 @Override
Jack Yu40306fc2019-05-13 16:54:09 -07007053 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chen29739692019-04-18 13:51:02 -07007054 enforceReadPrivilegedPermission("isApnMetered");
7055
7056 // Now that all security checks passes, perform the operation as ourselves.
7057 final long identity = Binder.clearCallingIdentity();
7058 try {
7059 Phone phone = getPhone(subId);
7060 if (phone == null) return true; // By default return true.
7061
Jack Yu40306fc2019-05-13 16:54:09 -07007062 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07007063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
7066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007067}