blob: 924d6564305fb2b1bbc7b7c4e2c3e70f1ad9ab1a [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 Gunnf70ed162019-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 Berionne482f8202018-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;
Michele4245e952019-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 Yub5d8f642018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
94import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080096import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070097import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080098import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070099import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsMmTelFeature;
101import android.telephony.ims.aidl.IImsRcsFeature;
102import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800104import android.telephony.ims.feature.MmTelFeature;
105import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800106import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800110import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800112
Brad Ebinger35c841c2018-10-01 10:40:55 -0700113import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700114import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800115import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700117import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700118import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800119import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700120import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800123import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800124import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800126import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700127import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100128import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700129import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700132import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800133import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700134import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700135import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700136import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700137import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700138import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700140import com.android.internal.telephony.SmsApplication;
141import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800142import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800143import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700144import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800145import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700146import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800147import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800148import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.uicc.IccIoResult;
150import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800151import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700152import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800153import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000156import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700157import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700159import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800160import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700161import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700162import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800163
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700164import java.io.FileDescriptor;
165import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800166import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800168import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700169import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800170import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800171import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800172import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100173import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700175import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800176import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177
178/**
179 * Implementation of the ITelephony interface.
180 */
Santos Cordon117fee72014-05-16 17:56:12 -0700181public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182 private static final String LOG_TAG = "PhoneInterfaceManager";
183 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
184 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187 // Message codes used with mMainThreadHandler
188 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700189 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
190 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191 private static final int CMD_OPEN_CHANNEL = 9;
192 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
193 private static final int CMD_CLOSE_CHANNEL = 11;
194 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800195 private static final int CMD_NV_READ_ITEM = 13;
196 private static final int EVENT_NV_READ_ITEM_DONE = 14;
197 private static final int CMD_NV_WRITE_ITEM = 15;
198 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
199 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
200 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700201 private static final int CMD_RESET_MODEM_CONFIG = 19;
202 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800203 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
204 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
205 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
206 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800207 private static final int CMD_SEND_ENVELOPE = 25;
208 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000209 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
210 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700211 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
212 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
213 private static final int CMD_EXCHANGE_SIM_IO = 31;
214 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800215 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
216 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700217 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
218 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700219 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
220 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700221 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
222 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
223 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
224 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700225 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
226 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
227 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
228 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700229 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800230 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
231 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000232 private static final int CMD_SWITCH_SLOTS = 50;
233 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700234 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
235 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
236 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
237 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
238 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
239 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
240 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
241 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700242 private static final int CMD_GET_ALL_CELL_INFO = 60;
243 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
244 private static final int CMD_GET_CELL_LOCATION = 62;
245 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700246 private static final int CMD_MODEM_REBOOT = 64;
247 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700248 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
249 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800250 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
251 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700252 private static final int CMD_GET_MODEM_STATUS = 70;
253 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800255 // Parameters of select command.
256 private static final int SELECT_COMMAND = 0xA4;
257 private static final int SELECT_P1 = 0x04;
258 private static final int SELECT_P2 = 0;
259 private static final int SELECT_P3 = 0x10;
260
Pengquan Meng85728fb2018-03-12 16:31:21 -0700261 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
262 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
263 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
264
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265 /** The singleton instance. */
266 private static PhoneInterfaceManager sInstance;
267
Wink Saville3ab207e2014-11-20 13:07:20 -0800268 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800269 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700270 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800271 private AppOpsManager mAppOps;
272 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800273 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800274 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700275 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276
Derek Tan97ebb422014-09-05 16:55:38 -0700277 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
278 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800279 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800280 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700281
Michelecea4cf22018-12-21 15:00:11 -0800282 // String to store multi SIM allowed
283 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
284
Derek Tan740e1672017-06-27 14:56:27 -0700285 // The AID of ISD-R.
286 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
287
yinxub1bed742017-04-17 11:45:04 -0700288 private NetworkScanRequestTracker mNetworkScanRequestTracker;
289
David Kelly5e06a7f2018-03-12 14:10:59 +0000290 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
291 private static final int MANUFACTURER_CODE_LENGTH = 8;
292
Derek Tan89e89d42014-07-08 17:00:10 -0700293 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700294 * A request object to use for transmitting data to an ICC.
295 */
296 private static final class IccAPDUArgument {
297 public int channel, cla, command, p1, p2, p3;
298 public String data;
299
300 public IccAPDUArgument(int channel, int cla, int command,
301 int p1, int p2, int p3, String data) {
302 this.channel = channel;
303 this.cla = cla;
304 this.command = command;
305 this.p1 = p1;
306 this.p2 = p2;
307 this.p3 = p3;
308 this.data = data;
309 }
310 }
311
312 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700313 * A request object to use for transmitting data to an ICC.
314 */
315 private static final class ManualNetworkSelectionArgument {
316 public OperatorInfo operatorInfo;
317 public boolean persistSelection;
318
319 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
320 this.operatorInfo = operatorInfo;
321 this.persistSelection = persistSelection;
322 }
323 }
324
325 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
327 * request after sending. The main thread will notify the request when it is complete.
328 */
329 private static final class MainThreadRequest {
330 /** The argument to use for the request */
331 public Object argument;
332 /** The result of the request that is run on the main thread */
333 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800334 // The subscriber id that this request applies to. Defaults to
335 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
336 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337
Nathan Harold92bed182018-10-12 18:16:49 -0700338 // In cases where subId is unavailable, the caller needs to specify the phone.
339 public Phone phone;
340
vagdeviaf9a5b92018-08-15 16:01:53 -0700341 public WorkSource workSource;
342
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 public MainThreadRequest(Object argument) {
344 this.argument = argument;
345 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800346
Nathan Harold92bed182018-10-12 18:16:49 -0700347 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
348 this.argument = argument;
349 if (phone != null) {
350 this.phone = phone;
351 }
352 this.workSource = workSource;
353 }
354
vagdeviaf9a5b92018-08-15 16:01:53 -0700355 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800356 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800357 if (subId != null) {
358 this.subId = subId;
359 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700360 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 }
363
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800364 private static final class IncomingThirdPartyCallArgs {
365 public final ComponentName component;
366 public final String callId;
367 public final String callerDisplayName;
368
369 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
370 String callerDisplayName) {
371 this.component = component;
372 this.callId = callId;
373 this.callerDisplayName = callerDisplayName;
374 }
375 }
376
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 /**
378 * A handler that processes messages on the main thread in the phone process. Since many
379 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
380 * inbound binder threads to the main thread in the phone process. The Binder thread
381 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
382 * on, which will be notified when the operation completes and will contain the result of the
383 * request.
384 *
385 * <p>If a MainThreadRequest object is provided in the msg.obj field,
386 * note that request.result must be set to something non-null for the calling thread to
387 * unblock.
388 */
389 private final class MainThreadHandler extends Handler {
390 @Override
391 public void handleMessage(Message msg) {
392 MainThreadRequest request;
393 Message onCompleted;
394 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800395 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700396 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800397 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398
399 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700400 case CMD_HANDLE_USSD_REQUEST: {
401 request = (MainThreadRequest) msg.obj;
402 final Phone phone = getPhoneFromRequest(request);
403 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
404 String ussdRequest = ussdObject.first;
405 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700406
Pengquan Menga1bb6272018-09-06 09:59:22 -0700407 if (!isUssdApiAllowed(request.subId)) {
408 // Carrier does not support use of this API, return failure.
409 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
410 UssdResponse response = new UssdResponse(ussdRequest, null);
411 Bundle returnData = new Bundle();
412 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
413 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700414
Pengquan Menga1bb6272018-09-06 09:59:22 -0700415 request.result = true;
416 notifyRequester(request);
417 return;
418 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700419
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 try {
421 request.result = phone != null
422 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
423 } catch (CallStateException cse) {
424 request.result = false;
425 }
426 // Wake up the requesting thread
427 notifyRequester(request);
428 break;
pkanwar32d516d2016-10-14 19:37:38 -0700429 }
430
Yorke Lee716f67e2015-06-17 15:39:16 -0700431 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700433 final Phone phone = getPhoneFromRequest(request);
434 request.result = phone != null ?
435 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
436 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800445 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700446 if (uiccCard == null) {
447 loge("iccTransmitApduLogicalChannel: No UICC");
448 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700449 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
452 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 iccArgument.channel, iccArgument.cla, iccArgument.command,
455 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 break;
459
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 ar = (AsyncResult) msg.obj;
462 request = (MainThreadRequest) ar.userObj;
463 if (ar.exception == null && ar.result != null) {
464 request.result = ar.result;
465 } else {
466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
467 if (ar.result == null) {
468 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800469 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700470 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800471 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 } else {
473 loge("iccTransmitApduLogicalChannel: Unknown exception");
474 }
475 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700476 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 break;
478
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
480 request = (MainThreadRequest) msg.obj;
481 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800482 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 if (uiccCard == null) {
484 loge("iccTransmitApduBasicChannel: No UICC");
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 } else {
488 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
489 request);
490 uiccCard.iccTransmitApduBasicChannel(
491 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
492 iccArgument.p3, iccArgument.data, onCompleted);
493 }
494 break;
495
496 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
497 ar = (AsyncResult) msg.obj;
498 request = (MainThreadRequest) ar.userObj;
499 if (ar.exception == null && ar.result != null) {
500 request.result = ar.result;
501 } else {
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
503 if (ar.result == null) {
504 loge("iccTransmitApduBasicChannel: Empty response");
505 } else if (ar.exception instanceof CommandException) {
506 loge("iccTransmitApduBasicChannel: CommandException: " +
507 ar.exception);
508 } else {
509 loge("iccTransmitApduBasicChannel: Unknown exception");
510 }
511 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 break;
514
515 case CMD_EXCHANGE_SIM_IO:
516 request = (MainThreadRequest) msg.obj;
517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 if (uiccCard == null) {
520 loge("iccExchangeSimIO: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 } else {
524 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
525 request);
526 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
527 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
528 iccArgument.data, onCompleted);
529 }
530 break;
531
532 case EVENT_EXCHANGE_SIM_IO_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
537 } else {
538 request.result = new IccIoResult(0x6f, 0, (byte[])null);
539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 break;
542
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 case CMD_SEND_ENVELOPE:
544 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800545 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 if (uiccCard == null) {
547 loge("sendEnvelopeWithStatus: No UICC");
548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 } else {
551 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
552 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
553 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 break;
555
556 case EVENT_SEND_ENVELOPE_DONE:
557 ar = (AsyncResult) msg.obj;
558 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700559 if (ar.exception == null && ar.result != null) {
560 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700562 request.result = new IccIoResult(0x6F, 0, (byte[])null);
563 if (ar.result == null) {
564 loge("sendEnvelopeWithStatus: Empty response");
565 } else if (ar.exception instanceof CommandException) {
566 loge("sendEnvelopeWithStatus: CommandException: " +
567 ar.exception);
568 } else {
569 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
570 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800573 break;
574
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 case CMD_OPEN_CHANNEL:
576 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800577 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800578 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800581 request.result = new IccOpenLogicalChannelResponse(-1,
582 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 } else {
585 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800586 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
587 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
591 case EVENT_OPEN_CHANNEL_DONE:
592 ar = (AsyncResult) msg.obj;
593 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 int[] result = (int[]) ar.result;
597 int channelId = result[0];
598 byte[] selectResponse = null;
599 if (result.length > 1) {
600 selectResponse = new byte[result.length - 1];
601 for (int i = 1; i < result.length; ++i) {
602 selectResponse[i - 1] = (byte) result[i];
603 }
604 }
605 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 if (ar.result == null) {
609 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 if (ar.exception != null) {
612 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
613 }
614
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700616 if (ar.exception instanceof CommandException) {
617 CommandException.Error error =
618 ((CommandException) (ar.exception)).getCommandError();
619 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700620 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700621 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(
626 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700628 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 break;
631
632 case CMD_CLOSE_CHANNEL:
633 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800634 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 if (uiccCard == null) {
636 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900637 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 } else {
640 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
641 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
642 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 break;
644
645 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800646 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
647 break;
648
649 case CMD_NV_READ_ITEM:
650 request = (MainThreadRequest) msg.obj;
651 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800652 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
653 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800654 break;
655
656 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 ar = (AsyncResult) msg.obj;
658 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800659 if (ar.exception == null && ar.result != null) {
660 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800662 request.result = "";
663 if (ar.result == null) {
664 loge("nvReadItem: Empty response");
665 } else if (ar.exception instanceof CommandException) {
666 loge("nvReadItem: CommandException: " +
667 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800669 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 }
671 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 break;
674
Jake Hambye994d462014-02-03 13:10:13 -0800675 case CMD_NV_WRITE_ITEM:
676 request = (MainThreadRequest) msg.obj;
677 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
678 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800679 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700680 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800681 break;
682
683 case EVENT_NV_WRITE_ITEM_DONE:
684 handleNullReturnEvent(msg, "nvWriteItem");
685 break;
686
687 case CMD_NV_WRITE_CDMA_PRL:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800690 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
693 case EVENT_NV_WRITE_CDMA_PRL_DONE:
694 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
695 break;
696
chen xu6dac5ab2018-10-26 17:39:23 -0700697 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800698 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700699 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800700 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
chen xu6dac5ab2018-10-26 17:39:23 -0700703 case EVENT_RESET_MODEM_CONFIG_DONE:
704 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
Jake Hamby7c27be32014-03-03 13:25:59 -0800707 case CMD_GET_PREFERRED_NETWORK_TYPE:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700710 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 break;
712
713 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
714 ar = (AsyncResult) msg.obj;
715 request = (MainThreadRequest) ar.userObj;
716 if (ar.exception == null && ar.result != null) {
717 request.result = ar.result; // Integer
718 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800719 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 if (ar.result == null) {
721 loge("getPreferredNetworkType: Empty response");
722 } else if (ar.exception instanceof CommandException) {
723 loge("getPreferredNetworkType: CommandException: " +
724 ar.exception);
725 } else {
726 loge("getPreferredNetworkType: Unknown exception");
727 }
728 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case CMD_SET_PREFERRED_NETWORK_TYPE:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
735 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700736 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 break;
738
739 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
740 handleNullReturnEvent(msg, "setPreferredNetworkType");
741 break;
742
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000743 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
744 request = (MainThreadRequest)msg.obj;
745 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800746 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 break;
748
749 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
750 ar = (AsyncResult)msg.obj;
751 request = (MainThreadRequest)ar.userObj;
752 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700753 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 break;
755
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800756 case CMD_SET_VOICEMAIL_NUMBER:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
759 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800760 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
761 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800762 break;
763
764 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
765 handleNullReturnEvent(msg, "setVoicemailNumber");
766 break;
767
Stuart Scott54788802015-03-30 13:18:01 -0700768 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
771 request);
772 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
773 break;
774
775 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
776 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
777 break;
778
Shishir Agrawal302c8692015-06-19 13:49:39 -0700779 case CMD_PERFORM_NETWORK_SCAN:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
782 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
783 break;
784
785 case EVENT_PERFORM_NETWORK_SCAN_DONE:
786 ar = (AsyncResult) msg.obj;
787 request = (MainThreadRequest) ar.userObj;
788 CellNetworkScanResult cellScanResult;
789 if (ar.exception == null && ar.result != null) {
790 cellScanResult = new CellNetworkScanResult(
791 CellNetworkScanResult.STATUS_SUCCESS,
792 (List<OperatorInfo>) ar.result);
793 } else {
794 if (ar.result == null) {
795 loge("getCellNetworkScanResults: Empty response");
796 }
797 if (ar.exception != null) {
798 loge("getCellNetworkScanResults: Exception: " + ar.exception);
799 }
800 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
801 if (ar.exception instanceof CommandException) {
802 CommandException.Error error =
803 ((CommandException) (ar.exception)).getCommandError();
804 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
805 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
806 } else if (error == CommandException.Error.GENERIC_FAILURE) {
807 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
808 }
809 }
810 cellScanResult = new CellNetworkScanResult(errorCode, null);
811 }
812 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700813 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700814 break;
815
816 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
817 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700818 ManualNetworkSelectionArgument selArg =
819 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700820 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
821 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700822 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
823 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 break;
825
826 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700827 ar = (AsyncResult) msg.obj;
828 request = (MainThreadRequest) ar.userObj;
829 if (ar.exception == null) {
830 request.result = true;
831 } else {
832 request.result = false;
833 loge("setNetworkSelectionModeManual " + ar.exception);
834 }
835 notifyRequester(request);
836 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 break;
838
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 case CMD_GET_MODEM_ACTIVITY_INFO:
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700842 if (defaultPhone != null) {
843 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
844 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700845 break;
846
847 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
850 if (ar.exception == null && ar.result != null) {
851 request.result = ar.result;
852 } else {
853 if (ar.result == null) {
854 loge("queryModemActivityInfo: Empty response");
855 } else if (ar.exception instanceof CommandException) {
856 loge("queryModemActivityInfo: CommandException: " +
857 ar.exception);
858 } else {
859 loge("queryModemActivityInfo: Unknown exception");
860 }
861 }
Amit Mahajand4766222016-01-28 15:28:28 -0800862 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
863 if (request.result == null) {
864 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
865 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700866 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700867 break;
868
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 case CMD_SET_ALLOWED_CARRIERS:
870 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800871 CarrierRestrictionRules argument =
872 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800874 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 break;
876
877 case EVENT_SET_ALLOWED_CARRIERS_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result;
882 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800883 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
884 if (ar.exception instanceof CommandException) {
885 loge("setAllowedCarriers: CommandException: " + ar.exception);
886 CommandException.Error error =
887 ((CommandException) (ar.exception)).getCommandError();
888 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
889 request.result =
890 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
891 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 } else {
893 loge("setAllowedCarriers: Unknown exception");
894 }
895 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700896 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 break;
898
899 case CMD_GET_ALLOWED_CARRIERS:
900 request = (MainThreadRequest) msg.obj;
901 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800902 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 break;
904
905 case EVENT_GET_ALLOWED_CARRIERS_DONE:
906 ar = (AsyncResult) msg.obj;
907 request = (MainThreadRequest) ar.userObj;
908 if (ar.exception == null && ar.result != null) {
909 request.result = ar.result;
910 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800911 request.result = new IllegalStateException(
912 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 if (ar.result == null) {
914 loge("getAllowedCarriers: Empty response");
915 } else if (ar.exception instanceof CommandException) {
916 loge("getAllowedCarriers: CommandException: " +
917 ar.exception);
918 } else {
919 loge("getAllowedCarriers: Unknown exception");
920 }
921 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700922 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 break;
924
Nathan Haroldb3014052017-01-25 15:57:32 -0800925 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result;
930 } else {
931 request.result = new IllegalArgumentException(
932 "Failed to retrieve Forbidden Plmns");
933 if (ar.result == null) {
934 loge("getForbiddenPlmns: Empty response");
935 } else {
936 loge("getForbiddenPlmns: Unknown exception");
937 }
938 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800940 break;
941
942 case CMD_GET_FORBIDDEN_PLMNS:
943 request = (MainThreadRequest) msg.obj;
944 uiccCard = getUiccCardFromRequest(request);
945 if (uiccCard == null) {
946 loge("getForbiddenPlmns() UiccCard is null");
947 request.result = new IllegalArgumentException(
948 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700949 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800950 break;
951 }
952 Integer appType = (Integer) request.argument;
953 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
954 if (uiccApp == null) {
955 loge("getForbiddenPlmns() no app with specified type -- "
956 + appType);
957 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800959 break;
960 } else {
961 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
962 + " specified type -- " + appType);
963 }
964 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
965 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
966 onCompleted);
967 break;
968
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000969 case CMD_SWITCH_SLOTS:
970 request = (MainThreadRequest) msg.obj;
971 int[] physicalSlots = (int[]) request.argument;
972 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
973 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
974 break;
975
976 case EVENT_SWITCH_SLOTS_DONE:
977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
979 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700980 notifyRequester(request);
981 break;
982 case CMD_GET_NETWORK_SELECTION_MODE:
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
985 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
986 break;
987
988 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
991 if (ar.exception != null) {
992 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
993 } else {
994 int mode = ((int[]) ar.result)[0];
995 if (mode == 0) {
996 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
997 } else {
998 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
999 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001000 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001001 notifyRequester(request);
1002 break;
1003 case CMD_GET_CDMA_ROAMING_MODE:
1004 request = (MainThreadRequest) msg.obj;
1005 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1006 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1007 break;
1008 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 if (ar.exception != null) {
1012 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1013 } else {
1014 request.result = ((int[]) ar.result)[0];
1015 }
1016 notifyRequester(request);
1017 break;
1018 case CMD_SET_CDMA_ROAMING_MODE:
1019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1021 int mode = (int) request.argument;
1022 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1023 break;
1024 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 request.result = ar.exception == null;
1028 notifyRequester(request);
1029 break;
1030 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1031 request = (MainThreadRequest) msg.obj;
1032 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1033 int subscriptionMode = (int) request.argument;
1034 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1035 break;
1036 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 request.result = ar.exception == null;
1040 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001041 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001042 case CMD_GET_ALL_CELL_INFO:
1043 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001044 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001045 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 case EVENT_GET_ALL_CELL_INFO_DONE:
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001050 // If a timeout occurs, the response will be null
1051 request.result = (ar.exception == null && ar.result != null)
1052 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 synchronized (request) {
1054 request.notifyAll();
1055 }
1056 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001057 case CMD_REQUEST_CELL_INFO_UPDATE:
1058 request = (MainThreadRequest) msg.obj;
1059 request.phone.requestCellInfoUpdate(request.workSource,
1060 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1061 break;
1062 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
1065 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1066 try {
1067 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001069 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1070 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001071 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001073 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 } else {
1075 // use the result as returned
1076 cb.onCellInfo((List<CellInfo>) ar.result);
1077 }
1078 } catch (RemoteException re) {
1079 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1080 }
1081 break;
1082 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 request = (MainThreadRequest) msg.obj;
1084 WorkSource ws = (WorkSource) request.argument;
1085 Phone phone = getPhoneFromRequest(request);
1086 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1087 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
1091 if (ar.exception == null) {
1092 request.result = ar.result;
1093 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001095 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1096 ? new CdmaCellLocation() : new GsmCellLocation();
1097 }
1098
1099 synchronized (request) {
1100 request.notifyAll();
1101 }
1102 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001103 case CMD_MODEM_REBOOT:
1104 request = (MainThreadRequest) msg.obj;
1105 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001106 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001107 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001108 case EVENT_CMD_MODEM_REBOOT_DONE:
1109 handleNullReturnEvent(msg, "rebootModem");
1110 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001111 case CMD_REQUEST_ENABLE_MODEM:
1112 request = (MainThreadRequest) msg.obj;
1113 boolean enable = (boolean) request.argument;
1114 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001115 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001116 PhoneConfigurationManager.getInstance()
1117 .enablePhone(request.phone, enable, onCompleted);
1118 break;
1119 case EVENT_ENABLE_MODEM_DONE:
1120 ar = (AsyncResult) msg.obj;
1121 request = (MainThreadRequest) ar.userObj;
1122 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001123 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001124 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001125 if ((boolean) request.result) {
1126 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1127 updateModemStateMetrics();
1128 } else {
1129 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1130 + ar.exception);
1131 }
1132 notifyRequester(request);
1133 break;
1134 case CMD_GET_MODEM_STATUS:
1135 request = (MainThreadRequest) msg.obj;
1136 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1137 PhoneConfigurationManager.getInstance()
1138 .getPhoneStatusFromModem(request.phone, onCompleted);
1139 break;
1140 case EVENT_GET_MODEM_STATUS_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 int id = request.phone.getPhoneId();
1144 if (ar.exception == null && ar.result != null) {
1145 request.result = ar.result;
1146 //update the cache as modem status has changed
1147 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1148 (boolean) request.result);
1149 } else {
1150 // Return true if modem status cannot be retrieved. For most cases,
1151 // modem status is on. And for older version modems, GET_MODEM_STATUS
1152 // and disable modem are not supported. Modem is always on.
1153 // TODO: this should be fixed in R to support a third
1154 // status UNKNOWN b/131631629
1155 request.result = true;
1156 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1157 + ar.exception);
1158 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001159 notifyRequester(request);
1160 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001161 default:
1162 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1163 break;
1164 }
1165 }
Jake Hambye994d462014-02-03 13:10:13 -08001166
Pengquan Menga1bb6272018-09-06 09:59:22 -07001167 private void notifyRequester(MainThreadRequest request) {
1168 synchronized (request) {
1169 request.notifyAll();
1170 }
1171 }
1172
Jake Hambye994d462014-02-03 13:10:13 -08001173 private void handleNullReturnEvent(Message msg, String command) {
1174 AsyncResult ar = (AsyncResult) msg.obj;
1175 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1176 if (ar.exception == null) {
1177 request.result = true;
1178 } else {
1179 request.result = false;
1180 if (ar.exception instanceof CommandException) {
1181 loge(command + ": CommandException: " + ar.exception);
1182 } else {
1183 loge(command + ": Unknown exception");
1184 }
1185 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001186 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 }
1189
1190 /**
1191 * Posts the specified command to be executed on the main thread,
1192 * waits for the request to complete, and returns the result.
1193 * @see #sendRequestAsync
1194 */
1195 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001196 return sendRequest(
1197 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001198 }
1199
1200 /**
1201 * Posts the specified command to be executed on the main thread,
1202 * waits for the request to complete, and returns the result.
1203 * @see #sendRequestAsync
1204 */
1205 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1206 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001207 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001208 }
1209
1210 /**
1211 * Posts the specified command to be executed on the main thread,
1212 * waits for the request to complete, and returns the result.
1213 * @see #sendRequestAsync
1214 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001215 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001216 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001217 }
1218
1219 /**
1220 * Posts the specified command to be executed on the main thread,
1221 * waits for the request to complete, and returns the result.
1222 * @see #sendRequestAsync
1223 */
Nathan Harold92bed182018-10-12 18:16:49 -07001224 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1225 return sendRequest(command, argument, subId, null, workSource);
1226 }
1227
1228 /**
1229 * Posts the specified command to be executed on the main thread,
1230 * waits for the request to complete, and returns the result.
1231 * @see #sendRequestAsync
1232 */
1233 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1234 return sendRequest(
1235 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1236 }
1237
1238 /**
1239 * Posts the specified command to be executed on the main thread,
1240 * waits for the request to complete, and returns the result.
1241 * @see #sendRequestAsync
1242 */
1243 private Object sendRequest(
1244 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1246 throw new RuntimeException("This method will deadlock if called from the main thread.");
1247 }
1248
Nathan Harold92bed182018-10-12 18:16:49 -07001249 MainThreadRequest request = null;
1250 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1251 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1252 } else if (phone != null) {
1253 request = new MainThreadRequest(argument, phone, workSource);
1254 } else {
1255 request = new MainThreadRequest(argument, subId, workSource);
1256 }
1257
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 Message msg = mMainThreadHandler.obtainMessage(command, request);
1259 msg.sendToTarget();
1260
1261 // Wait for the request to complete
1262 synchronized (request) {
1263 while (request.result == null) {
1264 try {
1265 request.wait();
1266 } catch (InterruptedException e) {
1267 // Do nothing, go back and wait until the request is complete
1268 }
1269 }
1270 }
1271 return request.result;
1272 }
1273
1274 /**
1275 * Asynchronous ("fire and forget") version of sendRequest():
1276 * Posts the specified command to be executed on the main thread, and
1277 * returns immediately.
1278 * @see #sendRequest
1279 */
1280 private void sendRequestAsync(int command) {
1281 mMainThreadHandler.sendEmptyMessage(command);
1282 }
1283
1284 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001285 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001286 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001287 */
1288 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 sendRequestAsync(command, argument, null, null);
1290 }
1291
1292 /**
1293 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1294 * @see {@link #sendRequest(int,Object)}
1295 */
1296 private void sendRequestAsync(
1297 int command, Object argument, Phone phone, WorkSource workSource) {
1298 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001299 Message msg = mMainThreadHandler.obtainMessage(command, request);
1300 msg.sendToTarget();
1301 }
1302
1303 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 * Initialize the singleton PhoneInterfaceManager instance.
1305 * This is only done once, at startup, from PhoneApp.onCreate().
1306 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001307 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 synchronized (PhoneInterfaceManager.class) {
1309 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001310 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 } else {
1312 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1313 }
1314 return sInstance;
1315 }
1316 }
1317
1318 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001319 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001322 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1324 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001325 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001326 mTelephonySharedPreferences =
1327 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001328 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001329 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 publish();
1332 }
1333
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001334 private Phone getDefaultPhone() {
1335 Phone thePhone = getPhone(getDefaultSubscription());
1336 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1337 }
1338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 private void publish() {
1340 if (DBG) log("publish: " + this);
1341
1342 ServiceManager.addService("phone", this);
1343 }
1344
Stuart Scott584921c2015-01-15 17:10:34 -08001345 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001346 if (request.phone != null) {
1347 return request.phone;
1348 } else {
1349 return getPhoneFromSubId(request.subId);
1350 }
1351 }
1352
1353 private Phone getPhoneFromSubId(int subId) {
1354 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1355 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001356 }
1357
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001358 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1359 Phone phone = getPhoneFromRequest(request);
1360 return phone == null ? null :
1361 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1362 }
1363
Wink Saville36469e72014-06-11 15:17:00 -07001364 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001365 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001366 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368
1369 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001370 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
1372
Wink Savilleb564aae2014-10-23 10:18:09 -07001373 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 if (DBG) log("dial: " + number);
1375 // No permission check needed here: This is just a wrapper around the
1376 // ACTION_DIAL intent, which is available to any app since it puts up
1377 // the UI before it does anything.
1378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001379 final long identity = Binder.clearCallingIdentity();
1380 try {
1381 String url = createTelUrl(number);
1382 if (url == null) {
1383 return;
1384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001386 // PENDING: should we just silently fail if phone is offhook or ringing?
1387 PhoneConstants.State state = mCM.getState(subId);
1388 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1389 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1390 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1391 mApp.startActivity(intent);
1392 }
1393 } finally {
1394 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 }
1396 }
1397
1398 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001400 }
1401
Wink Savilleb564aae2014-10-23 10:18:09 -07001402 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 if (DBG) log("call: " + number);
1404
1405 // This is just a wrapper around the ACTION_CALL intent, but we still
1406 // need to do a permission check since we're calling startActivity()
1407 // from the context of the phone app.
1408 enforceCallPermission();
1409
1410 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1411 != AppOpsManager.MODE_ALLOWED) {
1412 return;
1413 }
1414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001415 final long identity = Binder.clearCallingIdentity();
1416 try {
1417 String url = createTelUrl(number);
1418 if (url == null) {
1419 return;
1420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001422 boolean isValid = false;
1423 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1424 if (slist != null) {
1425 for (SubscriptionInfo subInfoRecord : slist) {
1426 if (subInfoRecord.getSubscriptionId() == subId) {
1427 isValid = true;
1428 break;
1429 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001430 }
Wink Saville08874612014-08-31 19:19:58 -07001431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001432 if (!isValid) {
1433 return;
1434 }
Wink Saville08874612014-08-31 19:19:58 -07001435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001436 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1437 intent.putExtra(SUBSCRIPTION_KEY, subId);
1438 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1439 mApp.startActivity(intent);
1440 } finally {
1441 Binder.restoreCallingIdentity(identity);
1442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 }
1444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001446 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001447 }
1448
Wink Savilleb564aae2014-10-23 10:18:09 -07001449 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001450 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001451 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1452 }
1453
1454 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001459 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001460 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1461 }
1462
1463 /** {@hide} */
1464 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001465 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001466 }
1467
Wink Savilleb564aae2014-10-23 10:18:09 -07001468 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001470
1471 final long identity = Binder.clearCallingIdentity();
1472 try {
1473 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1474 checkSimPin.start();
1475 return checkSimPin.unlockSim(null, pin);
1476 } finally {
1477 Binder.restoreCallingIdentity(identity);
1478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480
Wink Saville9de0f752013-10-22 19:04:03 -07001481 /** {@hide} */
1482 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001483 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
Wink Savilleb564aae2014-10-23 10:18:09 -07001486 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001488
1489 final long identity = Binder.clearCallingIdentity();
1490 try {
1491 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1492 checkSimPuk.start();
1493 return checkSimPuk.unlockSim(puk, pin);
1494 } finally {
1495 Binder.restoreCallingIdentity(identity);
1496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 }
1498
1499 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001500 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 * a synchronous one.
1502 */
1503 private static class UnlockSim extends Thread {
1504
1505 private final IccCard mSimCard;
1506
1507 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001508 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1509 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510
1511 // For replies from SimCard interface
1512 private Handler mHandler;
1513
1514 // For async handler to identify request type
1515 private static final int SUPPLY_PIN_COMPLETE = 100;
1516
1517 public UnlockSim(IccCard simCard) {
1518 mSimCard = simCard;
1519 }
1520
1521 @Override
1522 public void run() {
1523 Looper.prepare();
1524 synchronized (UnlockSim.this) {
1525 mHandler = new Handler() {
1526 @Override
1527 public void handleMessage(Message msg) {
1528 AsyncResult ar = (AsyncResult) msg.obj;
1529 switch (msg.what) {
1530 case SUPPLY_PIN_COMPLETE:
1531 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1532 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001533 mRetryCount = msg.arg1;
1534 if (ar.exception != null) {
1535 if (ar.exception instanceof CommandException &&
1536 ((CommandException)(ar.exception)).getCommandError()
1537 == CommandException.Error.PASSWORD_INCORRECT) {
1538 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1539 } else {
1540 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1541 }
1542 } else {
1543 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 mDone = true;
1546 UnlockSim.this.notifyAll();
1547 }
1548 break;
1549 }
1550 }
1551 };
1552 UnlockSim.this.notifyAll();
1553 }
1554 Looper.loop();
1555 }
1556
1557 /*
1558 * Use PIN or PUK to unlock SIM card
1559 *
1560 * If PUK is null, unlock SIM card with PIN
1561 *
1562 * If PUK is not null, unlock SIM card with PUK and set PIN code
1563 */
Wink Saville9de0f752013-10-22 19:04:03 -07001564 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565
1566 while (mHandler == null) {
1567 try {
1568 wait();
1569 } catch (InterruptedException e) {
1570 Thread.currentThread().interrupt();
1571 }
1572 }
1573 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1574
1575 if (puk == null) {
1576 mSimCard.supplyPin(pin, callback);
1577 } else {
1578 mSimCard.supplyPuk(puk, pin, callback);
1579 }
1580
1581 while (!mDone) {
1582 try {
1583 Log.d(LOG_TAG, "wait for done");
1584 wait();
1585 } catch (InterruptedException e) {
1586 // Restore the interrupted status
1587 Thread.currentThread().interrupt();
1588 }
1589 }
1590 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001591 int[] resultArray = new int[2];
1592 resultArray[0] = mResult;
1593 resultArray[1] = mRetryCount;
1594 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 }
1596 }
1597
1598 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001599 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001600
1601 }
1602
Wink Savilleb564aae2014-10-23 10:18:09 -07001603 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 // No permission check needed here: this call is harmless, and it's
1605 // needed for the ServiceState.requestStateUpdate() call (which is
1606 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001607 final long identity = Binder.clearCallingIdentity();
1608 try {
1609 final Phone phone = getPhone(subId);
1610 if (phone != null) {
1611 phone.updateServiceLocation();
1612 }
1613 } finally {
1614 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 }
1617
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001618 @Override
1619 public boolean isRadioOn(String callingPackage) {
1620 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001621 }
1622
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001623 @Override
1624 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001626 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001627 return false;
1628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001629
1630 final long identity = Binder.clearCallingIdentity();
1631 try {
1632 return isRadioOnForSubscriber(subId);
1633 } finally {
1634 Binder.restoreCallingIdentity(identity);
1635 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001636 }
1637
1638 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001639 final long identity = Binder.clearCallingIdentity();
1640 try {
1641 final Phone phone = getPhone(subId);
1642 if (phone != null) {
1643 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1644 } else {
1645 return false;
1646 }
1647 } finally {
1648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651
1652 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001653 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 }
Wink Saville36469e72014-06-11 15:17:00 -07001655
Wink Savilleb564aae2014-10-23 10:18:09 -07001656 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001658
1659 final long identity = Binder.clearCallingIdentity();
1660 try {
1661 final Phone phone = getPhone(subId);
1662 if (phone != null) {
1663 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1664 }
1665 } finally {
1666 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001667 }
Wink Saville36469e72014-06-11 15:17:00 -07001668 }
1669
1670 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001671 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
Wink Savilleb564aae2014-10-23 10:18:09 -07001674 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001675 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001676
1677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 final Phone phone = getPhone(subId);
1680 if (phone == null) {
1681 return false;
1682 }
1683 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1684 toggleRadioOnOffForSubscriber(subId);
1685 }
1686 return true;
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
Wink Saville36469e72014-06-11 15:17:00 -07001691
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001692 public boolean needMobileRadioShutdown() {
1693 /*
1694 * If any of the Radios are available, it will need to be
1695 * shutdown. So return true if any Radio is available.
1696 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001697 final long identity = Binder.clearCallingIdentity();
1698 try {
1699 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1700 Phone phone = PhoneFactory.getPhone(i);
1701 if (phone != null && phone.isRadioAvailable()) return true;
1702 }
1703 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1704 return false;
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001707 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001708 }
1709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001710 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001712 enforceModifyPermission();
1713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1717 logv("Shutting down Phone " + i);
1718 shutdownRadioUsingPhoneId(i);
1719 }
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001722 }
1723 }
1724
1725 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001726 Phone phone = PhoneFactory.getPhone(phoneId);
1727 if (phone != null && phone.isRadioAvailable()) {
1728 phone.shutdownRadio();
1729 }
1730 }
1731
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001733 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001734
1735 final long identity = Binder.clearCallingIdentity();
1736 try {
1737 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1738 if (defaultPhone != null) {
1739 defaultPhone.setRadioPower(turnOn);
1740 return true;
1741 } else {
1742 loge("There's no default phone.");
1743 return false;
1744 }
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001747 }
Wink Saville36469e72014-06-11 15:17:00 -07001748 }
1749
Wink Savilleb564aae2014-10-23 10:18:09 -07001750 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 final Phone phone = getPhone(subId);
1756 if (phone != null) {
1757 phone.setRadioPower(turnOn);
1758 return true;
1759 } else {
1760 return false;
1761 }
1762 } finally {
1763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 }
1766
Wink Saville36469e72014-06-11 15:17:00 -07001767 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 public boolean enableDataConnectivity() {
1770 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001771
1772 final long identity = Binder.clearCallingIdentity();
1773 try {
1774 int subId = mSubscriptionController.getDefaultDataSubId();
1775 final Phone phone = getPhone(subId);
1776 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001777 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001778 return true;
1779 } else {
1780 return false;
1781 }
1782 } finally {
1783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Wink Saville36469e72014-06-11 15:17:00 -07001787 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 public boolean disableDataConnectivity() {
1790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001791
1792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 int subId = mSubscriptionController.getDefaultDataSubId();
1795 final Phone phone = getPhone(subId);
1796 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001797 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798 return true;
1799 } else {
1800 return false;
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 }
1806
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001808 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 final Phone phone = getPhone(subId);
1812 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001813 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001814 } else {
1815 return false;
1816 }
1817 } finally {
1818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 }
1821
1822 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001823 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001824 }
1825
pkanwarae03a6b2016-11-06 20:37:09 -08001826 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001827 enforceCallPermission();
1828
1829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1832 return;
1833 }
1834 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1835 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1836 } finally {
1837 Binder.restoreCallingIdentity(identity);
1838 }
pkanwar32d516d2016-10-14 19:37:38 -07001839 };
1840
Wink Savilleb564aae2014-10-23 10:18:09 -07001841 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001843
1844 final long identity = Binder.clearCallingIdentity();
1845 try {
1846 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1847 return false;
1848 }
1849 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1850 } finally {
1851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 }
1854
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001856 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001857 }
1858
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001859 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001860 final long identity = Binder.clearCallingIdentity();
1861 try {
1862 Phone phone = PhoneFactory.getPhone(slotIndex);
1863 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1864 PhoneConstantConversions.convertCallState(phone.getState());
1865 } finally {
1866 Binder.restoreCallingIdentity(identity);
1867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 }
1869
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1875 if (phone != null) {
1876 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1877 } else {
1878 return PhoneConstantConversions.convertDataState(
1879 PhoneConstants.DataState.DISCONNECTED);
1880 }
1881 } finally {
1882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001888 final long identity = Binder.clearCallingIdentity();
1889 try {
1890 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1891 if (phone != null) {
1892 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1893 } else {
1894 return TelephonyManager.DATA_ACTIVITY_NONE;
1895 }
1896 } finally {
1897 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 }
1900
1901 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001902 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001903 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001904 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001905
1906 LocationAccessPolicy.LocationPermissionResult locationResult =
1907 LocationAccessPolicy.checkLocationPermission(mApp,
1908 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1909 .setCallingPackage(callingPackage)
1910 .setCallingPid(Binder.getCallingPid())
1911 .setCallingUid(Binder.getCallingUid())
1912 .setMethod("getCellLocation")
1913 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1914 .build());
1915 switch (locationResult) {
1916 case DENIED_HARD:
1917 throw new SecurityException("Not allowed to access cell location");
1918 case DENIED_SOFT:
1919 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001922 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001923 final long identity = Binder.clearCallingIdentity();
1924 try {
1925 if (DBG_LOC) log("getCellLocation: is active user");
1926 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001927 int subId = mSubscriptionController.getDefaultDataSubId();
1928 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1929 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930 return data;
1931 } finally {
1932 Binder.restoreCallingIdentity(identity);
1933 }
Svetoslav64fad262015-04-14 14:35:21 -07001934 }
1935
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001937 public String getNetworkCountryIsoForPhone(int phoneId) {
1938 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1939 // registered cell info, so return a NULL country instead.
1940 final long identity = Binder.clearCallingIdentity();
1941 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001942 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1943 // Get default phone in this case.
1944 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1945 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001946 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001947 // Todo: fix this when we can get the actual cellular network info when the device
1948 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001949 if (TelephonyManager.NETWORK_TYPE_IWLAN
1950 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1951 return "";
1952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001953 Phone phone = PhoneFactory.getPhone(phoneId);
1954 if (phone != null) {
1955 ServiceStateTracker sst = phone.getServiceStateTracker();
1956 if (sst != null) {
1957 LocaleTracker lt = sst.getLocaleTracker();
1958 if (lt != null) {
1959 return lt.getCurrentCountry();
1960 }
1961 }
1962 }
1963 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001964 } finally {
1965 Binder.restoreCallingIdentity(identity);
1966 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001967 }
1968
1969 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001971 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001972 }
1973
Sanket Padawe356d7632015-06-22 14:03:32 -07001974 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001975 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 mApp.enforceCallingOrSelfPermission(
1977 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001978
1979 final long identity = Binder.clearCallingIdentity();
1980 try {
1981 final Phone phone = getPhone(subId);
1982 if (phone != null) {
1983 phone.enableLocationUpdates();
1984 }
1985 } finally {
1986 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 }
1989
1990 @Override
1991 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001992 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001993 }
1994
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001996 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 mApp.enforceCallingOrSelfPermission(
1998 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999
2000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 final Phone phone = getPhone(subId);
2003 if (phone != null) {
2004 phone.disableLocationUpdates();
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
Nathan Harold31d7ff32018-10-15 20:20:30 -07002011 /**
2012 * Returns the target SDK version number for a given package name.
2013 *
2014 * @return target SDK if the package is found or INT_MAX.
2015 */
2016 private int getTargetSdk(String packageName) {
2017 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002018 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2019 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002020 if (ai != null) return ai.targetSdkVersion;
2021 } catch (PackageManager.NameNotFoundException unexpected) {
2022 }
2023 return Integer.MAX_VALUE;
2024 }
2025
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 @Override
2027 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002028 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2029 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002030 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2031 throw new SecurityException(
2032 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2033 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002034
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2036 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2037 return null;
2038 }
Svetoslav64fad262015-04-14 14:35:21 -07002039
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002040 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041
Nathan Haroldf180aac2018-06-01 18:43:55 -07002042 List<CellInfo> info = getAllCellInfo(callingPackage);
2043 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044
Nathan Haroldf180aac2018-06-01 18:43:55 -07002045 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2046 for (CellInfo ci : info) {
2047 if (ci instanceof CellInfoGsm) {
2048 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2049 } else if (ci instanceof CellInfoWcdma) {
2050 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002053 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 }
2055
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002056 private List<CellInfo> getCachedCellInfo() {
2057 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2058 for (Phone phone : PhoneFactory.getPhones()) {
2059 List<CellInfo> info = phone.getAllCellInfo();
2060 if (info != null) cellInfos.addAll(info);
2061 }
2062 return cellInfos;
2063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064
2065 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002066 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002067 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002068 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002069
2070 LocationAccessPolicy.LocationPermissionResult locationResult =
2071 LocationAccessPolicy.checkLocationPermission(mApp,
2072 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2073 .setCallingPackage(callingPackage)
2074 .setCallingPid(Binder.getCallingPid())
2075 .setCallingUid(Binder.getCallingUid())
2076 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002077 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002078 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2079 .build());
2080 switch (locationResult) {
2081 case DENIED_HARD:
2082 throw new SecurityException("Not allowed to access cell info");
2083 case DENIED_SOFT:
2084 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 }
2086
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002087 final int targetSdk = getTargetSdk(callingPackage);
2088 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2089 return getCachedCellInfo();
2090 }
2091
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002092 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002093 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002094 final long identity = Binder.clearCallingIdentity();
2095 try {
2096 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2097 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002098 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002099 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002100 if (info != null) cellInfos.addAll(info);
2101 }
2102 return cellInfos;
2103 } finally {
2104 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 }
2106 }
2107
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002108 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002109 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2110 requestCellInfoUpdateInternal(
2111 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2112 }
2113
2114 @Override
2115 public void requestCellInfoUpdateWithWorkSource(
2116 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2117 enforceModifyPermission();
2118 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2119 }
2120
2121 private void requestCellInfoUpdateInternal(
2122 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002123 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002124 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002125
2126 LocationAccessPolicy.LocationPermissionResult locationResult =
2127 LocationAccessPolicy.checkLocationPermission(mApp,
2128 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2129 .setCallingPackage(callingPackage)
2130 .setCallingPid(Binder.getCallingPid())
2131 .setCallingUid(Binder.getCallingUid())
2132 .setMethod("requestCellInfoUpdate")
2133 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2134 .build());
2135 switch (locationResult) {
2136 case DENIED_HARD:
2137 throw new SecurityException("Not allowed to access cell info");
2138 case DENIED_SOFT:
2139 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002140 }
2141
2142 final Phone phone = getPhone(subId);
2143 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2144
2145 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2146 }
2147
2148 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002150 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002155 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 } finally {
2157 Binder.restoreCallingIdentity(identity);
2158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
Shishir Agrawala9f32182016-04-12 12:00:16 -07002161 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002162 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002163 Phone phone = PhoneFactory.getPhone(slotIndex);
2164 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002165 return null;
2166 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002167 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002168 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2169 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002170 return null;
2171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 return phone.getImei();
2176 } finally {
2177 Binder.restoreCallingIdentity(identity);
2178 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002179 }
2180
2181 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002182 public String getTypeAllocationCodeForSlot(int slotIndex) {
2183 Phone phone = PhoneFactory.getPhone(slotIndex);
2184 String tac = null;
2185 if (phone != null) {
2186 String imei = phone.getImei();
2187 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2188 }
2189 return tac;
2190 }
2191
2192 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002193 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002194 Phone phone = PhoneFactory.getPhone(slotIndex);
2195 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002196 return null;
2197 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002198
Jeff Davidson913390f2018-02-23 17:11:49 -08002199 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002200 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2201 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002202 return null;
2203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002204
2205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 return phone.getMeid();
2208 } finally {
2209 Binder.restoreCallingIdentity(identity);
2210 }
Jack Yu2af8d712017-03-15 17:14:14 -07002211 }
2212
2213 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002214 public String getManufacturerCodeForSlot(int slotIndex) {
2215 Phone phone = PhoneFactory.getPhone(slotIndex);
2216 String manufacturerCode = null;
2217 if (phone != null) {
2218 String meid = phone.getMeid();
2219 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2220 }
2221 return manufacturerCode;
2222 }
2223
2224 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002225 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002226 Phone phone = PhoneFactory.getPhone(slotIndex);
2227 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002228 return null;
2229 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002230 int subId = phone.getSubId();
2231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2232 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2233 return null;
2234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235
2236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 return phone.getDeviceSvn();
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
2241 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002242 }
2243
fionaxu43304da2017-11-27 22:51:16 -08002244 @Override
2245 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246 final long identity = Binder.clearCallingIdentity();
2247 try {
2248 final Phone phone = getPhone(subId);
2249 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
2252 }
fionaxu43304da2017-11-27 22:51:16 -08002253 }
2254
2255 @Override
2256 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 final Phone phone = getPhone(subId);
2260 return phone == null ? null : phone.getCarrierName();
2261 } finally {
2262 Binder.restoreCallingIdentity(identity);
2263 }
fionaxu43304da2017-11-27 22:51:16 -08002264 }
2265
calvinpanffe225e2018-11-01 19:43:06 +08002266 @Override
chen xu0026ca62019-03-06 15:28:50 -08002267 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002268 final long identity = Binder.clearCallingIdentity();
2269 try {
2270 final Phone phone = getPhone(subId);
2271 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002272 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002273 } finally {
2274 Binder.restoreCallingIdentity(identity);
2275 }
2276 }
2277
2278 @Override
chen xu0026ca62019-03-06 15:28:50 -08002279 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002280 final long identity = Binder.clearCallingIdentity();
2281 try {
2282 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002283 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002284 } finally {
2285 Binder.restoreCallingIdentity(identity);
2286 }
2287 }
2288
chen xu651eec72018-11-11 19:03:44 -08002289 @Override
chen xu864e11c2018-12-06 22:10:03 -08002290 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2291 if (!isSubscriptionMccMnc) {
2292 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2293 }
chen xu651eec72018-11-11 19:03:44 -08002294 final Phone phone = PhoneFactory.getPhone(slotIndex);
2295 if (phone == null) {
2296 return TelephonyManager.UNKNOWN_CARRIER_ID;
2297 }
2298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2301 } finally {
2302 Binder.restoreCallingIdentity(identity);
2303 }
2304 }
2305
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 //
2307 // Internal helper methods.
2308 //
2309
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002310 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2312 *
2313 * @throws SecurityException if the caller does not have the required permission
2314 */
2315 private void enforceModifyPermission() {
2316 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2317 }
2318
2319 /**
2320 * Make sure the caller has the CALL_PHONE permission.
2321 *
2322 * @throws SecurityException if the caller does not have the required permission
2323 */
2324 private void enforceCallPermission() {
2325 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2326 }
2327
Stuart Scott8eef64f2015-04-08 15:13:54 -07002328 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002329 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002330 "ConnectivityService");
2331 }
2332
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 private String createTelUrl(String number) {
2334 if (TextUtils.isEmpty(number)) {
2335 return null;
2336 }
2337
Jake Hambye994d462014-02-03 13:10:13 -08002338 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
Ihab Awadf9e92732013-12-05 18:02:52 -08002341 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2343 }
2344
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002345 private static void logv(String msg) {
2346 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2347 }
2348
Ihab Awadf9e92732013-12-05 18:02:52 -08002349 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2351 }
2352
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002353 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002355 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002356 }
2357
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002359 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 final Phone phone = PhoneFactory.getPhone(slotIndex);
2363 if (phone == null) {
2364 return PhoneConstants.PHONE_TYPE_NONE;
2365 } else {
2366 return phone.getPhoneType();
2367 }
2368 } finally {
2369 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
2373 /**
2374 * Returns the CDMA ERI icon index to display
2375 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002376 @Override
2377 public int getCdmaEriIconIndex(String callingPackage) {
2378 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002379 }
2380
Sanket Padawe356d7632015-06-22 14:03:32 -07002381 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002382 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002384 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002385 return -1;
2386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 if (phone != null) {
2392 return phone.getCdmaEriIconIndex();
2393 } else {
2394 return -1;
2395 }
2396 } finally {
2397 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 }
2400
2401 /**
2402 * Returns the CDMA ERI icon mode,
2403 * 0 - ON
2404 * 1 - FLASHING
2405 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002406 @Override
2407 public int getCdmaEriIconMode(String callingPackage) {
2408 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002409 }
2410
Sanket Padawe356d7632015-06-22 14:03:32 -07002411 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002412 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002414 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002415 return -1;
2416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 final Phone phone = getPhone(subId);
2421 if (phone != null) {
2422 return phone.getCdmaEriIconMode();
2423 } else {
2424 return -1;
2425 }
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
2431 /**
2432 * Returns the CDMA ERI text,
2433 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002434 @Override
2435 public String getCdmaEriText(String callingPackage) {
2436 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002437 }
2438
Sanket Padawe356d7632015-06-22 14:03:32 -07002439 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002440 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002442 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002443 return null;
2444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445
2446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 final Phone phone = getPhone(subId);
2449 if (phone != null) {
2450 return phone.getCdmaEriText();
2451 } else {
2452 return null;
2453 }
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
2459 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002460 * Returns the CDMA MDN.
2461 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002463 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2465 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466
2467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002470 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471 return phone.getLine1Number();
2472 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002473 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 return null;
2475 }
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002478 }
2479 }
2480
2481 /**
2482 * Returns the CDMA MIN.
2483 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002485 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2487 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = getPhone(subId);
2492 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2493 return phone.getCdmaMin();
2494 } else {
2495 return null;
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002499 }
2500 }
2501
Hall Liud892bec2018-11-30 14:51:45 -08002502 @Override
2503 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2504 INumberVerificationCallback callback, String callingPackage) {
2505 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2506 != PERMISSION_GRANTED) {
2507 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2508 }
2509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2510
2511 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2512 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2513 throw new SecurityException("Calling package must be configured in the device config");
2514 }
2515
2516 if (range == null) {
2517 throw new NullPointerException("Range must be non-null");
2518 }
2519
2520 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002521 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002522
2523 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2524 }
2525
Junda Liuca05d5d2014-08-14 22:36:34 -07002526 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 * Returns true if CDMA provisioning needs to run.
2528 */
2529 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530 final long identity = Binder.clearCallingIdentity();
2531 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002532 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 } finally {
2534 Binder.restoreCallingIdentity(identity);
2535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536 }
2537
2538 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002539 * Sets the voice mail number of a given subId.
2540 */
2541 @Override
2542 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002543 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2548 new Pair<String, String>(alphaTag, number), new Integer(subId));
2549 return success;
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
2552 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002553 }
2554
Ta-wei Yen87c49842016-05-13 21:19:52 -07002555 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002556 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2557 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002558 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002559 if (!TextUtils.equals(callingPackage, systemDialer)) {
2560 throw new SecurityException("caller must be system dialer");
2561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2566 if (phoneAccountHandle == null) {
2567 return null;
2568 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002569 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570 } finally {
2571 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002572 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002573 }
2574
2575 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002576 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002579 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002580 return null;
2581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002583 final long identity = Binder.clearCallingIdentity();
2584 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002585 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002586 } finally {
2587 Binder.restoreCallingIdentity(identity);
2588 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002589 }
2590
2591 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002592 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2593 VisualVoicemailSmsFilterSettings settings) {
2594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002599 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 } finally {
2601 Binder.restoreCallingIdentity(identity);
2602 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002603 }
2604
2605 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002606 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608
2609 final long identity = Binder.clearCallingIdentity();
2610 try {
2611 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002612 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 } finally {
2614 Binder.restoreCallingIdentity(identity);
2615 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002616 }
2617
2618 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002619 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2620 String callingPackage, int subId) {
2621 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002626 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 } finally {
2628 Binder.restoreCallingIdentity(identity);
2629 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002630 }
2631
2632 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002633 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002634 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002639 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 } finally {
2641 Binder.restoreCallingIdentity(identity);
2642 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002643 }
2644
2645 @Override
2646 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2647 String number, int port, String text, PendingIntent sentIntent) {
2648 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002649 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002650 enforceSendSmsPermission();
2651 // Make the calls as the phone process.
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2655 if (port == 0) {
2656 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2657 sentIntent, null, false);
2658 } else {
2659 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2660 smsManager.sendDataMessageWithSelfPermissions(number, null,
2661 (short) port, data, sentIntent, null);
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002666 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002667 /**
fionaxu0152e512016-11-14 13:36:14 -08002668 * Sets the voice activation state of a given subId.
2669 */
2670 @Override
2671 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2673 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 final Phone phone = getPhone(subId);
2678 if (phone != null) {
2679 phone.setVoiceActivationState(activationState);
2680 } else {
2681 loge("setVoiceActivationState fails with invalid subId: " + subId);
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002685 }
2686 }
2687
2688 /**
2689 * Sets the data activation state of a given subId.
2690 */
2691 @Override
2692 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2694 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695
2696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 final Phone phone = getPhone(subId);
2699 if (phone != null) {
2700 phone.setDataActivationState(activationState);
2701 } else {
2702 loge("setVoiceActivationState fails with invalid subId: " + subId);
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002706 }
2707 }
2708
2709 /**
2710 * Returns the voice activation state of a given subId.
2711 */
2712 @Override
2713 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002714 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715
fionaxu0152e512016-11-14 13:36:14 -08002716 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 if (phone != null) {
2720 return phone.getVoiceActivationState();
2721 } else {
2722 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002726 }
2727 }
2728
2729 /**
2730 * Returns the data activation state of a given subId.
2731 */
2732 @Override
2733 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002734 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735
fionaxu0152e512016-11-14 13:36:14 -08002736 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 final long identity = Binder.clearCallingIdentity();
2738 try {
2739 if (phone != null) {
2740 return phone.getDataActivationState();
2741 } else {
2742 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002746 }
2747 }
2748
2749 /**
Wink Saville36469e72014-06-11 15:17:00 -07002750 * Returns the unread count of voicemails for a subId
2751 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002752 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002753 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2755 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2756 return 0;
2757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 final Phone phone = getPhone(subId);
2761 if (phone != null) {
2762 return phone.getVoiceMessageCount();
2763 } else {
2764 return 0;
2765 }
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
2771 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002772 * returns true, if the device is in a state where both voice and data
2773 * are supported simultaneously. This can change based on location or network condition.
2774 */
2775 @Override
2776 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 final Phone phone = getPhone(subId);
2780 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2781 } finally {
2782 Binder.restoreCallingIdentity(identity);
2783 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002784 }
2785
2786 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002787 * Send the dialer code if called from the current default dialer or the caller has
2788 * carrier privilege.
2789 * @param inputCode The dialer code to send
2790 */
2791 @Override
2792 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002793 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002795 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2796 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002797 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002798 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2799 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002804 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 } finally {
2806 Binder.restoreCallingIdentity(identity);
2807 }
fionaxu235cc5e2017-03-06 22:25:57 -08002808 }
2809
2810 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002811 * Returns the data network type.
2812 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 *
2814 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2815 */
2816 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002817 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 final Phone phone = getPhone(getDefaultSubscription());
2821 if (phone != null) {
2822 return phone.getServiceState().getDataNetworkType();
2823 } else {
2824 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2825 }
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002828 }
Wink Saville36469e72014-06-11 15:17:00 -07002829 }
2830
Pengquan Menga1bb6272018-09-06 09:59:22 -07002831 @Override
2832 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002833 if (!isActiveSubscription(subId)) {
2834 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2835 }
2836
Pengquan Menga1bb6272018-09-06 09:59:22 -07002837 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2838 }
2839
Brad Ebinger35c841c2018-10-01 10:40:55 -07002840 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002841 public boolean isInEmergencySmsMode() {
2842 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 for (Phone phone : PhoneFactory.getPhones()) {
2846 if (phone.isInEmergencySmsMode()) {
2847 return true;
2848 }
2849 }
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
2852 }
2853 return false;
2854 }
2855
2856 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002857 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2858 throws RemoteException {
2859 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002860 final long token = Binder.clearCallingIdentity();
2861 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002864 .addRegistrationCallbackForSubscription(c, subId);
2865 } finally {
2866 Binder.restoreCallingIdentity(token);
2867 }
2868 }
2869
2870 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002871 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2872 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2875 }
2876 Binder.withCleanCallingIdentity(() -> {
2877 try {
2878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002879 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002880 .removeRegistrationCallbackForSubscription(c, subId);
2881 } catch (IllegalArgumentException e) {
2882 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2883 + "is inactive, ignoring unregister.");
2884 // If the subscription is no longer active, just return, since the callback
2885 // will already have been removed internally.
2886 }
2887 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002888 }
2889
2890 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002891 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2892 throws RemoteException {
2893 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2895 final long token = Binder.clearCallingIdentity();
2896 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002897 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002898 .addCapabilitiesCallbackForSubscription(c, subId);
2899 } finally {
2900 Binder.restoreCallingIdentity(token);
2901 }
2902 }
2903
2904 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002905 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2906 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002907
2908 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2909 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2910 }
2911 Binder.withCleanCallingIdentity(() -> {
2912 try {
2913 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002914 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002915 .removeCapabilitiesCallbackForSubscription(c, subId);
2916 } catch (IllegalArgumentException e) {
2917 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2918 + "is inactive, ignoring unregister.");
2919 // If the subscription is no longer active, just return, since the callback
2920 // will already have been removed internally.
2921 }
2922 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002923 }
2924
2925 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002926 public boolean isCapable(int subId, int capability, int regTech) {
2927 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002928 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2929 final long token = Binder.clearCallingIdentity();
2930 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002931 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002932 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2933 } catch (ImsException e) {
2934 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2935 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002936 } catch (IllegalArgumentException e) {
2937 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2938 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002939 } finally {
2940 Binder.restoreCallingIdentity(token);
2941 }
2942 }
2943
2944 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002945 public boolean isAvailable(int subId, int capability, int regTech) {
2946 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002947 final long token = Binder.clearCallingIdentity();
2948 try {
2949 Phone phone = getPhone(subId);
2950 if (phone == null) return false;
2951 return phone.isImsCapabilityAvailable(capability, regTech);
2952 } finally {
2953 Binder.restoreCallingIdentity(token);
2954 }
2955 }
2956
2957 @Override
2958 public boolean isAdvancedCallingSettingEnabled(int subId) {
2959 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2961 final long token = Binder.clearCallingIdentity();
2962 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002963 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002964 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2965 } finally {
2966 Binder.restoreCallingIdentity(token);
2967 }
2968 }
2969
2970 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002971 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002973 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002977 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002978 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002985 public boolean isVtSettingEnabled(int subId) {
2986 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002991 getSlotIndexOrException(subId)).isVtEnabledByUser();
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
2997 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002998 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003000 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 }
3009
3010 @Override
3011 public boolean isVoWiFiSettingEnabled(int subId) {
3012 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003016 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003017 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
3021 }
3022
3023 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003024 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003026 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003030 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
3034 }
3035
3036 @Override
3037 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3038 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003043 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
3047 }
3048
3049 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003050 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003052 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003056 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003057 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
3060 }
3061 }
3062
3063 @Override
3064 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3066 "setVoWiFiNonPersistent");
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003070 boolean isRoaming = TelephonyManager.from(
3071 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003072 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003073 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 } finally {
3075 Binder.restoreCallingIdentity(identity);
3076 }
3077 }
3078
3079 @Override
3080 public int getVoWiFiModeSetting(int subId) {
3081 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003085 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003086 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
3090 }
3091
3092 @Override
3093 public void setVoWiFiModeSetting(int subId, int mode) {
3094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3095 "setVoWiFiModeSetting");
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003099 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
3104 }
3105
3106 @Override
3107 public int getVoWiFiRoamingModeSetting(int subId) {
3108 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003112 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
3117 }
3118
3119 @Override
3120 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3122 "setVoWiFiRoamingModeSetting");
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003126 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003127 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
3131 }
3132
3133 @Override
3134 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3136 "setRttCapabilityEnabled");
3137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003140 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003141 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
3144 }
3145 }
3146
3147 @Override
3148 public boolean isTtyOverVolteEnabled(int subId) {
3149 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003153 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
3157 }
3158 }
3159
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003160 @Override
3161 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3162 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003166 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003167 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
3171 }
3172
3173 @Override
3174 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3175 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3176 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003177 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3178 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3179 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003180 try {
3181 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003182 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003183 .removeProvisioningCallbackForSubscription(callback, subId);
3184 } catch (IllegalArgumentException e) {
3185 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3186 + "is inactive, ignoring unregister.");
3187 // If the subscription is no longer active, just return, since the callback will already
3188 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
3192 }
3193
3194 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003195 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3196 boolean isProvisioned) {
3197 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3198 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3199 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3200 }
3201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3202 "setProvisioningStatusForCapability");
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3206 Phone phone = getPhone(subId);
3207 if (phone == null) {
3208 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3209 + subId);
3210 return;
3211 }
3212 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3213 return;
3214 }
3215
3216 // this capability requires provisioning, route to the correct API.
3217 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3218 switch (capability) {
3219 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3220 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3221 ims.setVolteProvisioned(isProvisioned);
3222 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3223 ims.setWfcProvisioned(isProvisioned);
3224 }
3225 break;
3226 }
3227 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3228 // There is currently no difference in VT provisioning type.
3229 ims.setVtProvisioned(isProvisioned);
3230 break;
3231 }
3232 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3233 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3234 // change the capability of the feature instead if needed.
3235 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3236 == isProvisioned) {
3237 // No change in provisioning.
3238 return;
3239 }
3240 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3241 try {
3242 ims.changeMmTelCapability(capability, tech, isProvisioned);
3243 } catch (ImsException e) {
3244 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3245 + ", Exception" + e.getMessage());
3246 }
3247 break;
3248 }
3249 default: {
3250 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3251 + capability + "', which does not require provisioning.");
3252 }
3253 }
3254
3255 } finally {
3256 Binder.restoreCallingIdentity(identity);
3257 }
3258 }
3259
3260 @Override
3261 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3262 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3263 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3264 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3265 }
3266 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3267 final long identity = Binder.clearCallingIdentity();
3268 try {
3269 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3270 Phone phone = getPhone(subId);
3271 if (phone == null) {
3272 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3273 + subId);
3274 // We will fail with "true" as the provisioning status because this is the default
3275 // if we do not require provisioning.
3276 return true;
3277 }
3278
3279 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3280 return true;
3281 }
3282
3283 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3284 switch (capability) {
3285 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3286 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3287 return ims.isVolteProvisionedOnDevice();
3288 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3289 return ims.isWfcProvisionedOnDevice();
3290 }
3291 // This should never happen, since we are checking tech above to make sure it
3292 // is either LTE or IWLAN.
3293 throw new IllegalArgumentException("Invalid radio technology for voice "
3294 + "capability.");
3295 }
3296 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3297 // There is currently no difference in VT provisioning type.
3298 return ims.isVtProvisionedOnDevice();
3299 }
3300 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3301 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3302 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3303 }
3304 default: {
3305 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3306 + capability + "', which does not require provisioning.");
3307 }
3308 }
3309
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
3312 }
3313 }
3314
3315 @Override
3316 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3317 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3318 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3319 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3320 }
3321 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3322 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3323 return (provisionedBits & capability) > 0;
3324 }
3325
3326 @Override
3327 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3328 boolean isProvisioned) {
3329 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3330 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3331 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3332 }
3333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3334 "setProvisioningStatusForCapability");
3335 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3336 // If the current provisioning status for capability already matches isProvisioned,
3337 // do nothing.
3338 if (((provisionedBits & capability) > 0) == isProvisioned) {
3339 return;
3340 }
3341 if (isProvisioned) {
3342 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3343 } else {
3344 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3345 }
3346 }
3347
3348 /**
3349 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3350 * technology. The bitfield should mirror the bitfield defined by
3351 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3352 */
3353 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3354 String key = getMmTelProvisioningKey(subId, tech);
3355 // Default is no capabilities are provisioned.
3356 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3357 }
3358
3359 /**
3360 * Sets the MmTel capability provisioning bitfield (defined by
3361 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3362 * technology specified.
3363 *
3364 * Note: This is a synchronous command and should not be called on UI thread.
3365 */
3366 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3367 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3368 String key = getMmTelProvisioningKey(subId, tech);
3369 editor.putInt(key, newField);
3370 editor.commit();
3371 }
3372
3373 private static String getMmTelProvisioningKey(int subId, int tech) {
3374 // resulting key is provision_ims_mmtel_{subId}_{tech}
3375 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3376 }
3377
3378 /**
3379 * Query CarrierConfig to see if the specified capability requires provisioning for the
3380 * carrier associated with the subscription id.
3381 */
3382 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3383 int capability) {
3384 CarrierConfigManager configManager = new CarrierConfigManager(context);
3385 PersistableBundle c = configManager.getConfigForSubId(subId);
3386 boolean requireUtProvisioning = c.getBoolean(
3387 // By default, this config is true (even if there is no SIM). We also check to make
3388 // sure the subscription needs provisioning here, so we do not need to check for
3389 // the no-SIM case, where we would normally shortcut this to false.
3390 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3391 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3392 false);
3393 boolean requireVoiceVtProvisioning = c.getBoolean(
3394 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3395
3396 // First check to make sure that the capability requires provisioning.
3397 switch (capability) {
3398 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3399 // intentional fallthrough
3400 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3401 if (requireVoiceVtProvisioning) {
3402 // Voice and Video requires provisioning
3403 return true;
3404 }
3405 break;
3406 }
3407 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3408 if (requireUtProvisioning) {
3409 // UT requires provisioning
3410 return true;
3411 }
3412 break;
3413 }
3414 }
3415 return false;
3416 }
3417
3418 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003419 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003420 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3421 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3422 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003423 enforceReadPrivilegedPermission("getImsProvisioningInt");
3424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003427 int slotId = getSlotIndex(subId);
3428 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3429 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3430 + subId + "' for key:" + key);
3431 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3432 }
3433 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003434 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003435 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3436 + subId + "' for key:" + key);
3437 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003438 } finally {
3439 Binder.restoreCallingIdentity(identity);
3440 }
3441 }
3442
3443 @Override
3444 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003445 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3446 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3447 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003448 enforceReadPrivilegedPermission("getImsProvisioningString");
3449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003452 int slotId = getSlotIndex(subId);
3453 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3454 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3455 + subId + "' for key:" + key);
3456 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3457 }
3458 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003459 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003460 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3461 + subId + "' for key:" + key);
3462 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003463 } finally {
3464 Binder.restoreCallingIdentity(identity);
3465 }
3466 }
3467
3468 @Override
3469 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003470 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3471 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3472 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3474 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003475 final long identity = Binder.clearCallingIdentity();
3476 try {
3477 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003478 int slotId = getSlotIndex(subId);
3479 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3480 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3481 + subId + "' for key:" + key);
3482 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3483 }
3484 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003485 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003486 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3487 + "' for key:" + key);
3488 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003489 } finally {
3490 Binder.restoreCallingIdentity(identity);
3491 }
3492 }
3493
3494 @Override
3495 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003496 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3497 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3498 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3500 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003501 final long identity = Binder.clearCallingIdentity();
3502 try {
3503 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003504 int slotId = getSlotIndex(subId);
3505 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3506 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3507 + subId + "' for key:" + key);
3508 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3509 }
3510 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003511 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003512 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3513 + "' for key:" + key);
3514 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003515 } finally {
3516 Binder.restoreCallingIdentity(identity);
3517 }
3518 }
3519
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3521 int slotId = SubscriptionManager.getSlotIndex(subId);
3522 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003523 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 }
3525 return slotId;
3526 }
3527
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003528 private int getSlotIndex(int subId) {
3529 int slotId = SubscriptionManager.getSlotIndex(subId);
3530 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3531 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3532 }
3533 return slotId;
3534 }
3535
Wink Saville36469e72014-06-11 15:17:00 -07003536 /**
3537 * Returns the network type for a subId
3538 */
3539 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003540 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003542 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003543 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3544 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 final Phone phone = getPhone(subId);
3549 if (phone != null) {
3550 return phone.getServiceState().getDataNetworkType();
3551 } else {
3552 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3553 }
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003557 }
3558
3559 /**
3560 * Returns the data network type
3561 */
3562 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 public int getDataNetworkType(String callingPackage) {
3564 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003565 }
3566
3567 /**
3568 * Returns the data network type for a subId
3569 */
3570 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003571 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003573 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003574 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3575 }
3576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 final Phone phone = getPhone(subId);
3580 if (phone != null) {
3581 return phone.getServiceState().getDataNetworkType();
3582 } else {
3583 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3584 }
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003588 }
3589
3590 /**
Wink Saville36469e72014-06-11 15:17:00 -07003591 * Returns the Voice network type for a subId
3592 */
3593 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003594 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003596 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003597 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3598 }
3599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 final Phone phone = getPhone(subId);
3603 if (phone != null) {
3604 return phone.getServiceState().getVoiceNetworkType();
3605 } else {
3606 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3607 }
3608 } finally {
3609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003611 }
3612
3613 /**
3614 * @return true if a ICC card is present
3615 */
3616 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003617 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003618 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3619 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003620 }
3621
3622 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003623 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003624 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003625 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003626 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 final Phone phone = PhoneFactory.getPhone(slotIndex);
3630 if (phone != null) {
3631 return phone.getIccCard().hasIccCard();
3632 } else {
3633 return false;
3634 }
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003638 }
3639
3640 /**
3641 * Return if the current radio is LTE on CDMA. This
3642 * is a tri-state return value as for a period of time
3643 * the mode may be unknown.
3644 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003645 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003646 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003647 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003649 @Override
3650 public int getLteOnCdmaMode(String callingPackage) {
3651 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003652 }
3653
Sanket Padawe356d7632015-06-22 14:03:32 -07003654 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003655 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003657 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003658 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3659 }
3660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 final Phone phone = getPhone(subId);
3664 if (phone == null) {
3665 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3666 } else {
3667 return phone.getLteOnCdmaMode();
3668 }
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003671 }
Wink Saville36469e72014-06-11 15:17:00 -07003672 }
3673
Wink Saville36469e72014-06-11 15:17:00 -07003674 /**
3675 * {@hide}
3676 * Returns Default subId, 0 in the case of single standby.
3677 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003678 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003679 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003680 }
3681
Shishir Agrawala9f32182016-04-12 12:00:16 -07003682 private int getSlotForDefaultSubscription() {
3683 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3684 }
3685
Wink Savilleb564aae2014-10-23 10:18:09 -07003686 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003687 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003688 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003689
Pengquan Menge92a50d2018-09-21 15:54:48 -07003690 private boolean isActiveSubscription(int subId) {
3691 return mSubscriptionController.isActiveSubId(subId);
3692 }
3693
Ihab Awadf2177b72013-11-25 13:33:23 -08003694 /**
3695 * @see android.telephony.TelephonyManager.WifiCallingChoices
3696 */
3697 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698 final long identity = Binder.clearCallingIdentity();
3699 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003700 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3702 getWhenToMakeWifiCallsDefaultPreference());
3703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003706 }
3707
3708 /**
3709 * @see android.telephony.TelephonyManager.WifiCallingChoices
3710 */
3711 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003715 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3717 } finally {
3718 Binder.restoreCallingIdentity(identity);
3719 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003720 }
3721
Sailesh Nepald1e68152013-12-12 19:08:02 -08003722 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003723 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003724 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003725 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003726
Jordan Liu4c733742019-02-28 12:03:40 -08003727 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3728 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3729 if (phoneId == -1) {
3730 throw new IllegalArgumentException("Given slot index: " + slotIndex
3731 + " does not correspond to an active phone");
3732 }
3733 return PhoneFactory.getPhone(phoneId);
3734 }
3735
Shishir Agrawal566b7612013-10-28 14:41:00 -07003736 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003737 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3738 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3740 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003742 if (DBG) {
3743 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3744 }
3745 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3746 p2);
3747 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003748
Jordan Liu4c733742019-02-28 12:03:40 -08003749
3750 @Override
3751 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3752 int slotIndex, String callingPackage, String aid, int p2) {
3753 enforceModifyPermission();
3754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3755 if (DBG) {
3756 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3757 }
3758 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3759 callingPackage, aid, p2);
3760 }
3761
3762 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3763 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764 final long identity = Binder.clearCallingIdentity();
3765 try {
3766 if (TextUtils.equals(ISDR_AID, aid)) {
3767 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003768 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3769 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770 if (bestComponent == null
3771 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3772 loge("The calling package is not allowed to access ISD-R.");
3773 throw new SecurityException(
3774 "The calling package is not allowed to access ISD-R.");
3775 }
Derek Tan740e1672017-06-27 14:56:27 -07003776 }
Derek Tan740e1672017-06-27 14:56:27 -07003777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003778 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003779 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3780 null /* workSource */);
3781 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782 return response;
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
3785 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003786 }
3787
3788 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003789 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3791 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003792 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3793 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3794 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003795
Jordan Liu4c733742019-02-28 12:03:40 -08003796 @Override
3797 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3798 enforceModifyPermission();
3799 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3800 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3801 channel);
3802 }
3803
3804 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805 final long identity = Binder.clearCallingIdentity();
3806 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003807 if (channel < 0) {
3808 return false;
3809 }
Jordan Liu4c733742019-02-28 12:03:40 -08003810 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3811 null /* workSource */);
3812 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 return success;
3814 } finally {
3815 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003816 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003817 }
3818
3819 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003820 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003821 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3823 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003824 if (DBG) {
3825 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3826 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3827 + p3 + " data=" + data);
3828 }
3829 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3830 command, p1, p2, p3, data);
3831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003832
Jordan Liu4c733742019-02-28 12:03:40 -08003833 @Override
3834 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3835 int command, int p1, int p2, int p3, String data) {
3836 enforceModifyPermission();
3837 if (DBG) {
3838 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3839 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3840 + p3 + " data=" + data);
3841 }
3842 return iccTransmitApduLogicalChannelWithPermission(
3843 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3844 data);
3845 }
3846
3847 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3848 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849 final long identity = Binder.clearCallingIdentity();
3850 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851 if (channel < 0) {
3852 return "";
3853 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003856 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3857 null /* workSource */);
3858 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 // Append the returned status code to the end of the response payload.
3861 String s = Integer.toHexString(
3862 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3863 if (response.payload != null) {
3864 s = IccUtils.bytesToHexString(response.payload) + s;
3865 }
3866 return s;
3867 } finally {
3868 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003870 }
Jake Hambye994d462014-02-03 13:10:13 -08003871
Evan Charltonc66da362014-05-16 14:06:40 -07003872 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003873 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3874 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3876 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003877 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003878 if (DBG) {
3879 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3880 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3881 }
3882 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3883 cla, command, p1, p2, p3, data);
3884 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003885
Jordan Liu4c733742019-02-28 12:03:40 -08003886 @Override
3887 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3888 int command, int p1, int p2, int p3, String data) {
3889 enforceModifyPermission();
3890 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3891 if (DBG) {
3892 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3893 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3894 + " data=" + data);
3895 }
3896
3897 return iccTransmitApduBasicChannelWithPermission(
3898 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3899 p2, p3, data);
3900 }
3901
3902 // open APDU basic channel assuming the caller has sufficient permissions
3903 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3904 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3908 && TextUtils.equals(ISDR_AID, data)) {
3909 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003910 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3911 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 if (bestComponent == null
3913 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3914 loge("The calling package is not allowed to select ISD-R.");
3915 throw new SecurityException(
3916 "The calling package is not allowed to select ISD-R.");
3917 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003918 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003921 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3922 null /* workSource */);
3923 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925 // Append the returned status code to the end of the response payload.
3926 String s = Integer.toHexString(
3927 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3928 if (response.payload != null) {
3929 s = IccUtils.bytesToHexString(response.payload) + s;
3930 }
3931 return s;
3932 } finally {
3933 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003934 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003935 }
3936
3937 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003938 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003939 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3941 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943 final long identity = Binder.clearCallingIdentity();
3944 try {
3945 if (DBG) {
3946 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3947 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3948 }
3949
3950 IccIoResult response =
3951 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3952 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3953 subId);
3954
3955 if (DBG) {
3956 log("Exchange SIM_IO [R]" + response);
3957 }
3958
3959 byte[] result = null;
3960 int length = 2;
3961 if (response.payload != null) {
3962 length = 2 + response.payload.length;
3963 result = new byte[length];
3964 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3965 } else {
3966 result = new byte[length];
3967 }
3968
3969 result[length - 1] = (byte) response.sw2;
3970 result[length - 2] = (byte) response.sw1;
3971 return result;
3972 } finally {
3973 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003974 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003975 }
3976
Nathan Haroldb3014052017-01-25 15:57:32 -08003977 /**
3978 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3979 * on a particular subscription
3980 */
sqianb6e41952018-03-12 14:54:01 -07003981 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3983 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3984 return null;
3985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986
3987 final long identity = Binder.clearCallingIdentity();
3988 try {
3989 if (appType != TelephonyManager.APPTYPE_USIM
3990 && appType != TelephonyManager.APPTYPE_SIM) {
3991 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3992 return null;
3993 }
3994 Object response = sendRequest(
3995 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3996 if (response instanceof String[]) {
3997 return (String[]) response;
3998 }
3999 // Response is an Exception of some kind,
4000 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004001 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002 } finally {
4003 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004004 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004005 }
4006
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004007 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004008 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4010 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004012 final long identity = Binder.clearCallingIdentity();
4013 try {
4014 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4015 if (response.payload == null) {
4016 return "";
4017 }
Evan Charltonc66da362014-05-16 14:06:40 -07004018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019 // Append the returned status code to the end of the response payload.
4020 String s = Integer.toHexString(
4021 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4022 s = IccUtils.bytesToHexString(response.payload) + s;
4023 return s;
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
4026 }
Evan Charltonc66da362014-05-16 14:06:40 -07004027 }
4028
Jake Hambye994d462014-02-03 13:10:13 -08004029 /**
4030 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4031 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4032 *
4033 * @param itemID the ID of the item to read
4034 * @return the NV item as a String, or null on error.
4035 */
4036 @Override
4037 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4040 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041
4042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004045 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4047 return value;
4048 } finally {
4049 Binder.restoreCallingIdentity(identity);
4050 }
Jake Hambye994d462014-02-03 13:10:13 -08004051 }
4052
4053 /**
4054 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4055 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4056 *
4057 * @param itemID the ID of the item to read
4058 * @param itemValue the value to write, as a String
4059 * @return true on success; false on any failure
4060 */
4061 @Override
4062 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004063 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4065 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004066
4067 final long identity = Binder.clearCallingIdentity();
4068 try {
4069 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4070 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004071 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4073 return success;
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Jake Hambye994d462014-02-03 13:10:13 -08004077 }
4078
4079 /**
4080 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4081 * Used for device configuration by some CDMA operators.
4082 *
4083 * @param preferredRoamingList byte array containing the new PRL
4084 * @return true on success; false on any failure
4085 */
4086 @Override
4087 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4089 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090
4091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4094 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4095 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4096 return success;
4097 } finally {
4098 Binder.restoreCallingIdentity(identity);
4099 }
Jake Hambye994d462014-02-03 13:10:13 -08004100 }
4101
4102 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004103 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004104 * Used for device configuration by some CDMA operators.
4105 *
chen xu6dac5ab2018-10-26 17:39:23 -07004106 * @param slotIndex - device slot.
4107 *
Jake Hambye994d462014-02-03 13:10:13 -08004108 * @return true on success; false on any failure
4109 */
4110 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004111 public boolean resetModemConfig(int slotIndex) {
4112 Phone phone = PhoneFactory.getPhone(slotIndex);
4113 if (phone != null) {
4114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4115 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116
chen xu6dac5ab2018-10-26 17:39:23 -07004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4120 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4121 return success;
4122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125 }
chen xu6dac5ab2018-10-26 17:39:23 -07004126 return false;
4127 }
4128
4129 /**
4130 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4131 *
4132 * @param slotIndex - device slot.
4133 *
4134 * @return true on success; false on any failure
4135 */
4136 @Override
4137 public boolean rebootModem(int slotIndex) {
4138 Phone phone = PhoneFactory.getPhone(slotIndex);
4139 if (phone != null) {
4140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4141 mApp, phone.getSubId(), "rebootModem");
4142
4143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4146 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4147 return success;
4148 } finally {
4149 Binder.restoreCallingIdentity(identity);
4150 }
4151 }
4152 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004153 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004154
Svet Ganovb320e182015-04-16 12:30:10 -07004155 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004156 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004158 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004159 return new String[0];
4160 }
4161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 final long identity = Binder.clearCallingIdentity();
4163 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004164 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
Wink Saville36469e72014-06-11 15:17:00 -07004168 }
4169
Brad Ebinger51f743a2017-01-23 13:50:20 -08004170 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004171 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4172 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004173 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004174 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004175 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004176
4177 final long identity = Binder.clearCallingIdentity();
4178 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004179 ImsResolver resolver = PhoneFactory.getImsResolver();
4180 if (resolver == null) {
4181 // may happen if the device does not support IMS.
4182 return;
4183 }
4184 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004188 }
4189
4190 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004191 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4192 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004193 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004194 public void disableIms(int slotId) {
4195 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196
4197 final long identity = Binder.clearCallingIdentity();
4198 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004199 ImsResolver resolver = PhoneFactory.getImsResolver();
4200 if (resolver == null) {
4201 // may happen if the device does not support IMS.
4202 return;
4203 }
4204 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004208 }
4209
4210 /**
4211 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4212 * feature or {@link null} if the service is not available. If the feature is available, the
4213 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4214 */
4215 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004216 IImsServiceFeatureCallback callback) {
4217 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004221 ImsResolver resolver = PhoneFactory.getImsResolver();
4222 if (resolver == null) {
4223 // may happen if the device does not support IMS.
4224 return null;
4225 }
4226 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004230 }
4231
4232 /**
4233 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4234 * feature during emergency calling or {@link null} if the service is not available. If the
4235 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4236 * listener for feature updates.
4237 */
4238 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4239 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240
4241 final long identity = Binder.clearCallingIdentity();
4242 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004243 ImsResolver resolver = PhoneFactory.getImsResolver();
4244 if (resolver == null) {
4245 // may happen if the device does not support IMS.
4246 return null;
4247 }
4248 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
4251 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004252 }
4253
Brad Ebinger5f64b052017-12-14 14:26:15 -08004254 /**
4255 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004256 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004257 */
4258 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4259 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260
4261 final long identity = Binder.clearCallingIdentity();
4262 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004263 ImsResolver resolver = PhoneFactory.getImsResolver();
4264 if (resolver == null) {
4265 // may happen if the device does not support IMS.
4266 return null;
4267 }
4268 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004272 }
4273
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004274 /**
4275 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004276 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004277 */
4278 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004283 ImsResolver resolver = PhoneFactory.getImsResolver();
4284 if (resolver == null) {
4285 // may happen if the device does not support IMS.
4286 return null;
4287 }
4288 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 } finally {
4290 Binder.restoreCallingIdentity(identity);
4291 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004292 }
4293
Brad Ebinger884c07b2018-02-15 16:17:40 -08004294 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004295 * Sets the ImsService Package Name that Telephony will bind to.
4296 *
4297 * @param slotId the slot ID that the ImsService should bind for.
4298 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4299 * ImsService is the device default ImsService.
4300 * @param packageName The package name of the application that contains the ImsService to bind
4301 * to.
4302 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4303 * @hide
4304 */
4305 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004306 int[] subIds = SubscriptionManager.getSubId(slotId);
4307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4308 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4309 "setImsService");
4310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311 final long identity = Binder.clearCallingIdentity();
4312 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004313 ImsResolver resolver = PhoneFactory.getImsResolver();
4314 if (resolver == null) {
4315 // may happen if the device does not support IMS.
4316 return false;
4317 }
4318 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4319 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004323 }
4324
4325 /**
4326 * Return the ImsService configuration.
4327 *
4328 * @param slotId The slot that the ImsService is associated with.
4329 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4330 * the device default.
4331 * @return the package name of the ImsService configuration.
4332 */
4333 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004334 int[] subIds = SubscriptionManager.getSubId(slotId);
4335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4336 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4337 "getImsService");
4338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339 final long identity = Binder.clearCallingIdentity();
4340 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004341 ImsResolver resolver = PhoneFactory.getImsResolver();
4342 if (resolver == null) {
4343 // may happen if the device does not support IMS.
4344 return "";
4345 }
4346 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347 } finally {
4348 Binder.restoreCallingIdentity(identity);
4349 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004350 }
4351
Wink Saville36469e72014-06-11 15:17:00 -07004352 public void setImsRegistrationState(boolean registered) {
4353 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004354
4355 final long identity = Binder.clearCallingIdentity();
4356 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004357 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Wink Saville36469e72014-06-11 15:17:00 -07004361 }
4362
4363 /**
Stuart Scott54788802015-03-30 13:18:01 -07004364 * Set the network selection mode to automatic.
4365 *
4366 */
4367 @Override
4368 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4370 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371
Pengquan Menge92a50d2018-09-21 15:54:48 -07004372 if (!isActiveSubscription(subId)) {
4373 return;
4374 }
4375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4379 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
Stuart Scott54788802015-03-30 13:18:01 -07004383 }
4384
Pengquan Mengea84e042018-09-20 14:57:26 -07004385 /**
4386 * Ask the radio to connect to the input network and change selection mode to manual.
4387 *
4388 * @param subId the id of the subscription.
4389 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4390 * the operator to attach to.
4391 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4392 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4393 * normal network selection next time.
4394 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004395 */
4396 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004397 public boolean setNetworkSelectionModeManual(
4398 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4400 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004401
4402 if (!isActiveSubscription(subId)) {
4403 return false;
4404 }
4405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 final long identity = Binder.clearCallingIdentity();
4407 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004408 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004410 if (DBG) {
4411 log("setNetworkSelectionModeManual: subId: " + subId
4412 + " operator: " + operatorInfo);
4413 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004418 }
4419
4420 /**
4421 * Scans for available networks.
4422 */
4423 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004424 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4426 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004427 LocationAccessPolicy.LocationPermissionResult locationResult =
4428 LocationAccessPolicy.checkLocationPermission(mApp,
4429 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4430 .setCallingPackage(callingPackage)
4431 .setCallingPid(Binder.getCallingPid())
4432 .setCallingUid(Binder.getCallingUid())
4433 .setMethod("getCellNetworkScanResults")
4434 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4435 .build());
4436 switch (locationResult) {
4437 case DENIED_HARD:
4438 throw new SecurityException("Not allowed to access scan results -- location");
4439 case DENIED_SOFT:
4440 return null;
4441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442
Pengquan Menga1bb6272018-09-06 09:59:22 -07004443 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 try {
4445 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004446 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004451 }
4452
4453 /**
yinxub1bed742017-04-17 11:45:04 -07004454 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004455 *
yinxub1bed742017-04-17 11:45:04 -07004456 * @param subId id of the subscription
4457 * @param request contains the radio access networks with bands/channels to scan
4458 * @param messenger callback messenger for scan results or errors
4459 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004460 * @return the id of the requested scan which can be used to stop the scan.
4461 */
4462 @Override
4463 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004464 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4466 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004467 LocationAccessPolicy.LocationPermissionResult locationResult =
4468 LocationAccessPolicy.checkLocationPermission(mApp,
4469 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4470 .setCallingPackage(callingPackage)
4471 .setCallingPid(Binder.getCallingPid())
4472 .setCallingUid(Binder.getCallingUid())
4473 .setMethod("requestNetworkScan")
4474 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4475 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004476 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4477 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4478 if (e != null) {
4479 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4480 throw e;
4481 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004482 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004483 return TelephonyScanManager.INVALID_SCAN_ID;
4484 }
4485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004486 }
Hall Liu912dfd32019-04-25 14:02:26 -07004487 int callingUid = Binder.getCallingUid();
4488 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004489 final long identity = Binder.clearCallingIdentity();
4490 try {
4491 return mNetworkScanRequestTracker.startNetworkScan(
4492 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004493 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004494 } finally {
4495 Binder.restoreCallingIdentity(identity);
4496 }
yinxu504e1392017-04-12 16:03:22 -07004497 }
4498
Hall Liub2ac8ef2019-02-28 15:56:23 -08004499 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4500 NetworkScanRequest request) {
4501 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4502 != PERMISSION_GRANTED) {
4503 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4504 + " without location access.");
4505 }
4506
4507 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4508 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004509 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4510 return new SecurityException("Specific channels must not be"
4511 + " scanned without location access.");
4512 }
4513 }
4514 }
4515
Hall Liub2ac8ef2019-02-28 15:56:23 -08004516 return null;
4517 }
4518
yinxu504e1392017-04-12 16:03:22 -07004519 /**
4520 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004521 *
4522 * @param subId id of the subscription
4523 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004524 */
4525 @Override
4526 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4528 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529
Hall Liu912dfd32019-04-25 14:02:26 -07004530 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004531 final long identity = Binder.clearCallingIdentity();
4532 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004533 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 } finally {
4535 Binder.restoreCallingIdentity(identity);
4536 }
yinxu504e1392017-04-12 16:03:22 -07004537 }
4538
4539 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004540 * Get the calculated preferred network type.
4541 * Used for debugging incorrect network type.
4542 *
4543 * @return the preferred network type, defined in RILConstants.java.
4544 */
4545 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004546 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004547 final Phone defaultPhone = getDefaultPhone();
4548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4549 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004550 return RILConstants.PREFERRED_NETWORK_MODE;
4551 }
4552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 final long identity = Binder.clearCallingIdentity();
4554 try {
4555 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004556 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
Junda Liu84d15a22014-07-02 11:21:04 -07004560 }
4561
4562 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004563 * Get the preferred network type.
4564 * Used for device configuration by some CDMA operators.
4565 *
4566 * @return the preferred network type, defined in RILConstants.java.
4567 */
4568 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004569 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004570 TelephonyPermissions
4571 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4572 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573
4574 final long identity = Binder.clearCallingIdentity();
4575 try {
4576 if (DBG) log("getPreferredNetworkType");
4577 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4578 int networkType = (result != null ? result[0] : -1);
4579 if (DBG) log("getPreferredNetworkType: " + networkType);
4580 return networkType;
4581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004584 }
4585
4586 /**
4587 * Set the preferred network type.
4588 * Used for device configuration by some CDMA operators.
4589 *
4590 * @param networkType the preferred network type, defined in RILConstants.java.
4591 * @return true on success; false on any failure.
4592 */
4593 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004594 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4596 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597
4598 final long identity = Binder.clearCallingIdentity();
4599 try {
4600 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4601 Boolean success = (Boolean) sendRequest(
4602 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4603 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4604 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004605 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4607 }
4608 return success;
4609 } finally {
4610 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004611 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004612 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004613
4614 /**
Miaoa84611c2019-03-15 09:21:10 +08004615 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004616 *
Miaoa84611c2019-03-15 09:21:10 +08004617 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004618 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004619 * @hide
4620 */
4621 @Override
Miaoa84611c2019-03-15 09:21:10 +08004622 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004623 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004625 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 try {
Miaoa84611c2019-03-15 09:21:10 +08004627 if (phone != null) {
4628 return phone.hasMatchedTetherApnSetting();
4629 } else {
4630 return false;
4631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 } finally {
4633 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004634 }
Junda Liu475951f2014-11-07 16:45:03 -08004635 }
4636
4637 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004638 * Set mobile data enabled
4639 * Used by the user through settings etc to turn on/off mobile data
4640 *
4641 * @param enable {@code true} turn turn data on, else {@code false}
4642 */
4643 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004644 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4646 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647
4648 final long identity = Binder.clearCallingIdentity();
4649 try {
4650 int phoneId = mSubscriptionController.getPhoneId(subId);
4651 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4652 Phone phone = PhoneFactory.getPhone(phoneId);
4653 if (phone != null) {
4654 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004655 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004657 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004658 }
4659 } finally {
4660 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004661 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004662 }
4663
4664 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004665 * Get the user enabled state of Mobile Data.
4666 *
4667 * TODO: remove and use isUserDataEnabled.
4668 * This can't be removed now because some vendor codes
4669 * calls through ITelephony directly while they should
4670 * use TelephonyManager.
4671 *
4672 * @return true on enabled
4673 */
4674 @Override
4675 public boolean getDataEnabled(int subId) {
4676 return isUserDataEnabled(subId);
4677 }
4678
4679 /**
4680 * Get whether mobile data is enabled per user setting.
4681 *
4682 * There are other factors deciding whether mobile data is actually enabled, but they are
4683 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004684 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004685 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004686 *
4687 * @return {@code true} if data is enabled else {@code false}
4688 */
4689 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004690 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004691 try {
4692 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4693 null);
4694 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4696 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698
4699 final long identity = Binder.clearCallingIdentity();
4700 try {
4701 int phoneId = mSubscriptionController.getPhoneId(subId);
4702 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4703 Phone phone = PhoneFactory.getPhone(phoneId);
4704 if (phone != null) {
4705 boolean retVal = phone.isUserDataEnabled();
4706 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4707 return retVal;
4708 } else {
4709 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4710 return false;
4711 }
4712 } finally {
4713 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004714 }
4715 }
4716
4717 /**
4718 * Get whether mobile data is enabled.
4719 *
4720 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4721 * whether mobile data is actually enabled.
4722 *
4723 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4724 *
4725 * @return {@code true} if data is enabled else {@code false}
4726 */
4727 @Override
4728 public boolean isDataEnabled(int subId) {
4729 try {
4730 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4731 null);
4732 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4734 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736
4737 final long identity = Binder.clearCallingIdentity();
4738 try {
4739 int phoneId = mSubscriptionController.getPhoneId(subId);
4740 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4741 Phone phone = PhoneFactory.getPhone(phoneId);
4742 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004743 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4745 return retVal;
4746 } else {
4747 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4748 return false;
4749 }
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004752 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004753 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004754
4755 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004756 public int getCarrierPrivilegeStatus(int subId) {
4757 final Phone phone = getPhone(subId);
4758 if (phone == null) {
4759 loge("getCarrierPrivilegeStatus: Invalid subId");
4760 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4761 }
4762 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004763 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004764 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004765 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4766 }
4767 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004768 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004769 }
Junda Liu29340342014-07-10 15:23:27 -07004770
4771 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004772 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4773 final Phone phone = getPhone(subId);
4774 if (phone == null) {
4775 loge("getCarrierPrivilegeStatus: Invalid subId");
4776 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4777 }
4778 UiccProfile profile =
4779 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4780 if (profile == null) {
4781 loge("getCarrierPrivilegeStatus: No UICC");
4782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4783 }
4784 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4785 }
4786
4787 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004788 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004789 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004790 if (TextUtils.isEmpty(pkgName))
4791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004792 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004793 if (card == null) {
4794 loge("checkCarrierPrivilegesForPackage: No UICC");
4795 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4796 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004797 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4798 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004799 }
4800
4801 @Override
4802 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004803 if (TextUtils.isEmpty(pkgName))
4804 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004805 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4806 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4807 UiccCard card = UiccController.getInstance().getUiccCard(i);
4808 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004809 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004810 continue;
4811 }
4812
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004813 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004814 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4815 break;
4816 }
4817 }
4818
4819 return result;
Junda Liu29340342014-07-10 15:23:27 -07004820 }
Derek Tan89e89d42014-07-08 17:00:10 -07004821
4822 @Override
Junda Liue64de782015-04-16 17:19:16 -07004823 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4824 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4825 loge("phoneId " + phoneId + " is not valid.");
4826 return null;
4827 }
4828 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004829 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004830 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004831 return null ;
4832 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004833 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004834 }
4835
Amith Yamasani6e118872016-02-19 12:53:51 -08004836 @Override
4837 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004838 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004839 List<String> privilegedPackages = new ArrayList<>();
4840 List<PackageInfo> packages = null;
4841 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4842 UiccCard card = UiccController.getInstance().getUiccCard(i);
4843 if (card == null) {
4844 // No UICC in that slot.
4845 continue;
4846 }
4847 if (card.hasCarrierPrivilegeRules()) {
4848 if (packages == null) {
4849 // Only check packages in user 0 for now
4850 packages = pm.getInstalledPackagesAsUser(
4851 PackageManager.MATCH_DISABLED_COMPONENTS
4852 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4853 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4854 }
4855 for (int p = packages.size() - 1; p >= 0; p--) {
4856 PackageInfo pkgInfo = packages.get(p);
4857 if (pkgInfo != null && pkgInfo.packageName != null
4858 && card.getCarrierPrivilegeStatus(pkgInfo)
4859 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4860 privilegedPackages.add(pkgInfo.packageName);
4861 }
4862 }
4863 }
4864 }
4865 return privilegedPackages;
4866 }
4867
Wink Savilleb564aae2014-10-23 10:18:09 -07004868 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004869 final Phone phone = getPhone(subId);
4870 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004871 if (card == null) {
4872 loge("getIccId: No UICC");
4873 return null;
4874 }
4875 String iccId = card.getIccId();
4876 if (TextUtils.isEmpty(iccId)) {
4877 loge("getIccId: ICC ID is null or empty.");
4878 return null;
4879 }
4880 return iccId;
4881 }
4882
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004883 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004884 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4885 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004886 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4887 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 final String iccId = getIccId(subId);
4892 final Phone phone = getPhone(subId);
4893 if (phone == null) {
4894 return false;
4895 }
4896 final String subscriberId = phone.getSubscriberId();
4897
4898 if (DBG_MERGE) {
4899 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4900 + subscriberId + " to " + number);
4901 }
4902
4903 if (TextUtils.isEmpty(iccId)) {
4904 return false;
4905 }
4906
4907 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4908
4909 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4910 if (alphaTag == null) {
4911 editor.remove(alphaTagPrefKey);
4912 } else {
4913 editor.putString(alphaTagPrefKey, alphaTag);
4914 }
4915
4916 // Record both the line number and IMSI for this ICCID, since we need to
4917 // track all merged IMSIs based on line number
4918 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4919 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4920 if (number == null) {
4921 editor.remove(numberPrefKey);
4922 editor.remove(subscriberPrefKey);
4923 } else {
4924 editor.putString(numberPrefKey, number);
4925 editor.putString(subscriberPrefKey, subscriberId);
4926 }
4927
4928 editor.commit();
4929 return true;
4930 } finally {
4931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004932 }
Derek Tan7226c842014-07-02 17:42:23 -07004933 }
4934
4935 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004936 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004937 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004939 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004940 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004941 return null;
4942 }
Derek Tan97ebb422014-09-05 16:55:38 -07004943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 String iccId = getIccId(subId);
4947 if (iccId != null) {
4948 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4949 if (DBG_MERGE) {
4950 log("getLine1NumberForDisplay returning "
4951 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4952 }
4953 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004955 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4956 return null;
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004959 }
Derek Tan7226c842014-07-02 17:42:23 -07004960 }
4961
4962 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004963 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004965 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004966 return null;
4967 }
Derek Tan97ebb422014-09-05 16:55:38 -07004968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 final long identity = Binder.clearCallingIdentity();
4970 try {
4971 String iccId = getIccId(subId);
4972 if (iccId != null) {
4973 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4974 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4975 }
4976 return null;
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004979 }
Derek Tan7226c842014-07-02 17:42:23 -07004980 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004981
4982 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07004983 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004984 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4985 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004987 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4988 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004989 return null;
4990 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004991
Jordan Liub49b04b2019-05-06 14:45:15 -07004992 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4993 // the process, where TelephonyManager was instantiated.
4994 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004995 final long identity = Binder.clearCallingIdentity();
4996 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004997 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 final TelephonyManager tele = TelephonyManager.from(context);
4999 final SubscriptionManager sub = SubscriptionManager.from(context);
5000
5001 // Figure out what subscribers are currently active
5002 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003
Jordan Liub49b04b2019-05-06 14:45:15 -07005004 // Only consider subs which match the current subId
5005 // This logic can be simplified. See b/131189269 for progress.
5006 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005007 activeSubscriberIds.add(tele.getSubscriberId(subId));
5008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009
5010 // First pass, find a number override for an active subscriber
5011 String mergeNumber = null;
5012 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5013 for (String key : prefs.keySet()) {
5014 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5015 final String subscriberId = (String) prefs.get(key);
5016 if (activeSubscriberIds.contains(subscriberId)) {
5017 final String iccId = key.substring(
5018 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5019 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5020 mergeNumber = (String) prefs.get(numberKey);
5021 if (DBG_MERGE) {
5022 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5023 + " for active subscriber " + subscriberId);
5024 }
5025 if (!TextUtils.isEmpty(mergeNumber)) {
5026 break;
5027 }
5028 }
5029 }
5030 }
5031
5032 // Shortcut when no active merged subscribers
5033 if (TextUtils.isEmpty(mergeNumber)) {
5034 return null;
5035 }
5036
5037 // Second pass, find all subscribers under that line override
5038 final ArraySet<String> result = new ArraySet<>();
5039 for (String key : prefs.keySet()) {
5040 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5041 final String number = (String) prefs.get(key);
5042 if (mergeNumber.equals(number)) {
5043 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5044 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5045 final String subscriberId = (String) prefs.get(subscriberKey);
5046 if (!TextUtils.isEmpty(subscriberId)) {
5047 result.add(subscriberId);
5048 }
5049 }
5050 }
5051 }
5052
5053 final String[] resultArray = result.toArray(new String[result.size()]);
5054 Arrays.sort(resultArray);
5055 if (DBG_MERGE) {
5056 Slog.d(LOG_TAG,
5057 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5058 }
5059 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005060 } finally {
5061 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005062 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005063 }
5064
5065 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005066 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005067 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5068 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069
5070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 final Phone phone = getPhone(subId);
5073 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5074 } finally {
5075 Binder.restoreCallingIdentity(identity);
5076 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005077 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005078
5079 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005080 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005081 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5082 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005083 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005084
5085 final long identity = Binder.clearCallingIdentity();
5086 try {
5087 final Phone phone = getPhone(subId);
5088 if (phone == null) {
5089 return false;
5090 }
5091 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5092 cdmaNonRoamingList);
5093 } finally {
5094 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005095 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005096 }
5097
5098 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005099 @Deprecated
5100 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5101 enforceModifyPermission();
5102
5103 int returnValue = 0;
5104 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005105 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005106 if(result.exception == null) {
5107 if (result.result != null) {
5108 byte[] responseData = (byte[])(result.result);
5109 if(responseData.length > oemResp.length) {
5110 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5111 responseData.length + "bytes. Buffer Size is " +
5112 oemResp.length + "bytes.");
5113 }
5114 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5115 returnValue = responseData.length;
5116 }
5117 } else {
5118 CommandException ex = (CommandException) result.exception;
5119 returnValue = ex.getCommandError().ordinal();
5120 if(returnValue > 0) returnValue *= -1;
5121 }
5122 } catch (RuntimeException e) {
5123 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5124 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5125 if(returnValue > 0) returnValue *= -1;
5126 }
5127
5128 return returnValue;
5129 }
5130
5131 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005132 public void setRadioCapability(RadioAccessFamily[] rafs) {
5133 try {
5134 ProxyController.getInstance().setRadioCapability(rafs);
5135 } catch (RuntimeException e) {
5136 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5137 }
5138 }
5139
5140 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005141 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005142 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005143 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005144 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005145 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 final long identity = Binder.clearCallingIdentity();
5148 try {
chen xub97461a2018-10-26 14:17:57 -07005149 TelephonyPermissions
5150 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5151 mApp, phone.getSubId(), "getRadioAccessFamily");
5152 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
chen xub97461a2018-10-26 14:17:57 -07005156 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005157 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005158
5159 @Override
5160 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005161 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005162 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163
5164 final long identity = Binder.clearCallingIdentity();
5165 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005166 ImsManager.getInstance(defaultPhone.getContext(),
5167 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 } finally {
5169 Binder.restoreCallingIdentity(identity);
5170 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005171 }
5172
5173 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005174 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005175 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005177 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005178 return false;
5179 }
Svet Ganovb320e182015-04-16 12:30:10 -07005180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 final long identity = Binder.clearCallingIdentity();
5182 try {
5183 // Check the user preference and the system-level IMS setting. Even if the user has
5184 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5185 // In the long run, we may instead need to check if there exists a connection service
5186 // which can support video calling.
5187 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005188 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 return imsManager.isVtEnabledByPlatform()
5190 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5191 && imsManager.isVtEnabledByUser();
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005195 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005196
Andrew Leea1239f22015-03-02 17:44:07 -08005197 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5199 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5200 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5201 return false;
5202 }
5203
5204 final long identity = Binder.clearCallingIdentity();
5205 try {
5206 CarrierConfigManager configManager =
5207 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005208 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
Andrew Leea1239f22015-03-02 17:44:07 -08005213 }
5214
5215 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 public boolean isWorldPhone(int subId, String callingPackage) {
5217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5218 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5219 return false;
5220 }
5221
5222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 CarrierConfigManager configManager =
5225 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005226 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Andrew Leea1239f22015-03-02 17:44:07 -08005231 }
5232
Andrew Lee9431b832015-03-09 18:46:45 -07005233 @Override
5234 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005235 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005236 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005237 }
5238
5239 @Override
5240 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
5242 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005243 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Andrew Lee9431b832015-03-09 18:46:45 -07005247 }
5248
Hall Liuf6668912018-10-31 17:05:23 -07005249 /**
5250 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5251 * support for the feature and device firmware support.
5252 *
5253 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5254 */
5255 @Override
5256 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005258 final Phone phone = getPhone(subscriptionId);
5259 if (phone == null) {
5260 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5261 return false;
5262 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005264 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5266 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005267 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 return isCarrierSupported && isDeviceSupported;
5269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
Hall Liu98187582018-01-22 19:15:32 -08005272 }
5273
Hall Liuf6668912018-10-31 17:05:23 -07005274 /**
5275 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5276 * both also support RTT.
5277 */
5278 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 final long identity = Binder.clearCallingIdentity();
5280 try {
Hall Liuf6668912018-10-31 17:05:23 -07005281 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005282 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005286 }
5287
Sanket Padawe7310cc72015-01-14 09:53:20 -08005288 /**
5289 * Returns the unique device ID of phone, for example, the IMEI for
5290 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5291 *
5292 * <p>Requires Permission:
5293 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5294 */
5295 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005296 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005297 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005298 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005299 return null;
5300 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005301 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005302 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5303 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005304 return null;
5305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306
5307 final long identity = Binder.clearCallingIdentity();
5308 try {
5309 return phone.getDeviceId();
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
5312 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005313 }
5314
Ping Sunc67b7c22016-03-02 19:16:45 +08005315 /**
5316 * {@hide}
5317 * Returns the IMS Registration Status on a particular subid
5318 *
5319 * @param subId
5320 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005321 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005322 Phone phone = getPhone(subId);
5323 if (phone != null) {
5324 return phone.isImsRegistered();
5325 } else {
5326 return false;
5327 }
5328 }
5329
Santos Cordon7a1885b2015-02-03 11:15:19 -08005330 @Override
5331 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005338 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005339
Tyler Gunnf70ed162019-04-03 15:28:53 -07005340 @Override
5341 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5342 final long identity = Binder.clearCallingIdentity();
5343 try {
5344 Phone phone = getPhone(subscriptionId);
5345 if (phone == null) {
5346 return null;
5347 }
5348 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
5352 }
5353
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005354 /**
5355 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005356 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005357 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 final long identity = Binder.clearCallingIdentity();
5359 try {
5360 Phone phone = getPhone(subId);
5361 if (phone != null) {
5362 return phone.isWifiCallingEnabled();
5363 } else {
5364 return false;
5365 }
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005368 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005369 }
5370
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005371 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005372 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005373 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005374 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 Phone phone = getPhone(subId);
5378 if (phone != null) {
5379 return phone.isVideoEnabled();
5380 } else {
5381 return false;
5382 }
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005385 }
5386 }
5387
5388 /**
5389 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5390 * defined in {@link ImsRegistrationImplBase}.
5391 */
5392 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
5395 Phone phone = getPhone(subId);
5396 if (phone != null) {
5397 return phone.getImsRegistrationTech();
5398 } else {
5399 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5400 }
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005403 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005404 }
5405
Stuart Scott8eef64f2015-04-08 15:13:54 -07005406 @Override
5407 public void factoryReset(int subId) {
5408 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005409 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5410 return;
5411 }
5412
Svet Ganovcc087f82015-05-12 20:35:54 -07005413 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005414
Svet Ganovcc087f82015-05-12 20:35:54 -07005415 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005416 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5417 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005418 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005419 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005420 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005421 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5422 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005423 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005424 // There has been issues when Sms raw table somehow stores orphan
5425 // fragments. They lead to garbled message when new fragments come
5426 // in and combined with those stale ones. In case this happens again,
5427 // user can reset all network settings which will clean up this table.
5428 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005431 }
5432 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005433
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005434 private void cleanUpSmsRawTable(Context context) {
5435 ContentResolver resolver = context.getContentResolver();
5436 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5437 resolver.delete(uri, null, null);
5438 }
5439
Narayan Kamath1c496c22015-04-16 14:40:19 +01005440 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005441 public String getSimLocaleForSubscriber(int subId) {
5442 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5443 final Phone phone = getPhone(subId);
5444 if (phone == null) {
5445 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005446 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
chen xu5d3637b2019-01-21 23:31:38 -08005450 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5451 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005452 if (info == null) {
5453 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5454 return null;
5455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456 // Try and fetch the locale from the carrier properties or from the SIM language
5457 // preferences (EF-PL and EF-LI)...
5458 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005460 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5461 if (localeFromDefaultSim != null) {
5462 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5463 if (DBG) log("Using locale from subId: " + subId + " locale: "
5464 + localeFromDefaultSim);
5465 return localeFromDefaultSim.toLanguageTag();
5466 } else {
5467 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 }
5469 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 // The SIM language preferences only store a language (e.g. fr = French), not an
5472 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5473 // the SIM and carrier preferences does not include a country we add the country
5474 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005475 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005477 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 return mccLocale.toLanguageTag();
5479 }
5480
5481 if (DBG) log("No locale found - returning null");
5482 return null;
5483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005486 }
5487
5488 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005489 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005490 }
5491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 /**
5493 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5494 */
5495 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005496 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005497 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005498
Chenjie Yu1ba97252018-01-11 18:16:20 -08005499 private final ModemActivityInfo mLastModemActivityInfo =
5500 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5501
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005502 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005503 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5504 * representing the state of the modem.
5505 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005506 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5507 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005508 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005509 */
5510 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005511 public void requestModemActivityInfo(ResultReceiver result) {
5512 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005513 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514
5515 final long identity = Binder.clearCallingIdentity();
5516 try {
5517 ModemActivityInfo ret = null;
5518 synchronized (mLastModemActivityInfo) {
5519 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5520 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005521 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005522 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5524 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005525 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5526 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 }
5528 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005529 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5530 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 mLastModemActivityInfo.setIdleTimeMillis(
5532 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5533 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5534 mLastModemActivityInfo.setRxTimeMillis(
5535 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5536 mLastModemActivityInfo.setEnergyUsed(
5537 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5540 mLastModemActivityInfo.getSleepTimeMillis(),
5541 mLastModemActivityInfo.getIdleTimeMillis(),
5542 mLastModemActivityInfo.getTxTimeMillis(),
5543 mLastModemActivityInfo.getRxTimeMillis(),
5544 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 Bundle bundle = new Bundle();
5547 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5548 result.send(0, bundle);
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005551 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005552 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005553
Siddharth Rayb8114062018-06-17 15:02:38 -07005554 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5555 // less than total activity duration.
5556 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5557 if (info == null) {
5558 return false;
5559 }
5560 int activityDurationMs =
5561 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5562 int totalTxTimeMs = 0;
5563 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5564 totalTxTimeMs += info.getTxTimeMillis()[i];
5565 }
5566 return (info.isValid()
5567 && (info.getSleepTimeMillis() <= activityDurationMs)
5568 && (info.getIdleTimeMillis() <= activityDurationMs)
5569 && (info.getRxTimeMillis() <= activityDurationMs)
5570 && (totalTxTimeMs <= activityDurationMs));
5571 }
5572
Jack Yu85bd38a2015-11-09 11:34:32 -08005573 /**
5574 * {@hide}
5575 * Returns the service state information on specified subscription.
5576 */
5577 @Override
5578 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005579 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005580 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005581 return null;
5582 }
5583
Hall Liuf19c44f2018-11-27 14:38:17 -08005584 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5585 LocationAccessPolicy.checkLocationPermission(mApp,
5586 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5587 .setCallingPackage(callingPackage)
5588 .setCallingPid(Binder.getCallingPid())
5589 .setCallingUid(Binder.getCallingUid())
5590 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005591 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005592 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5593 .build());
5594
5595 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5596 LocationAccessPolicy.checkLocationPermission(mApp,
5597 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5598 .setCallingPackage(callingPackage)
5599 .setCallingPid(Binder.getCallingPid())
5600 .setCallingUid(Binder.getCallingUid())
5601 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005602 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005603 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5604 .build());
5605 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5606 boolean hasFinePermission =
5607 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5608 boolean hasCoarsePermission =
5609 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 final long identity = Binder.clearCallingIdentity();
5612 try {
5613 final Phone phone = getPhone(subId);
5614 if (phone == null) {
5615 return null;
5616 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005617
Hall Liuf19c44f2018-11-27 14:38:17 -08005618 ServiceState ss = phone.getServiceState();
5619
5620 // Scrub out the location info in ServiceState depending on what level of access
5621 // the caller has.
5622 if (hasFinePermission) return ss;
5623 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5624 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625 } finally {
5626 Binder.restoreCallingIdentity(identity);
5627 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005628 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005629
5630 /**
5631 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5632 *
5633 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5634 * voicemail ringtone.
5635 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5636 * PhoneAccount.
5637 */
5638 @Override
5639 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 final long identity = Binder.clearCallingIdentity();
5641 try {
5642 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5643 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005644 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005651 }
5652
5653 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005654 * Sets the per-account voicemail ringtone.
5655 *
5656 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5657 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5658 *
5659 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5660 * voicemail ringtone.
5661 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5662 * PhoneAccount.
5663 */
5664 @Override
5665 public void setVoicemailRingtoneUri(String callingPackage,
5666 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005667 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005668 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5669 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005670 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5672 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5673 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005674 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5679 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005680 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 }
5682 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005685 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005686 }
5687
5688 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005689 * Returns whether vibration is set for voicemail notification in Phone settings.
5690 *
5691 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5692 * voicemail vibration setting.
5693 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5694 */
5695 @Override
5696 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 final long identity = Binder.clearCallingIdentity();
5698 try {
5699 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5700 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005701 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005708 }
5709
Youhan Wange64578a2016-05-02 15:32:42 -07005710 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005711 * Sets the per-account voicemail vibration.
5712 *
5713 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5714 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5715 *
5716 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5717 * voicemail vibration setting.
5718 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5719 * specific PhoneAccount.
5720 */
5721 @Override
5722 public void setVoicemailVibrationEnabled(String callingPackage,
5723 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005724 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005725 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5726 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005727 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5729 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5730 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005731 }
5732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 final long identity = Binder.clearCallingIdentity();
5734 try {
5735 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5736 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005737 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 }
5739 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5740 } finally {
5741 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005742 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005743 }
5744
5745 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005746 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5747 *
5748 * @throws SecurityException if the caller does not have the required permission
5749 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005750 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005751 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005752 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005753 }
5754
5755 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005756 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5757 * permission.
5758 *
5759 * @throws SecurityException if the caller does not have the required permission
5760 */
5761 private void enforceSendSmsPermission() {
5762 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5763 }
5764
5765 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005766 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005767 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005768 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005769 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005770 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005774 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 if (componentName == null) {
5776 throw new SecurityException(
5777 "Caller not current active visual voicemail package[null]");
5778 }
5779 String vvmPackage = componentName.getPackageName();
5780 if (!callingPackage.equals(vvmPackage)) {
5781 throw new SecurityException("Caller not current active visual voicemail package["
5782 + vvmPackage + "]");
5783 }
5784 } finally {
5785 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005786 }
5787 }
5788
5789 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005790 * Return the application ID for the app type.
5791 *
5792 * @param subId the subscription ID that this request applies to.
5793 * @param appType the uicc app type.
5794 * @return Application ID for specificied app type, or null if no uicc.
5795 */
5796 @Override
5797 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005798 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005799 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800
5801 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005802 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803 if (phone == null) {
5804 return null;
5805 }
5806 String aid = null;
5807 try {
5808 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5809 .getApplicationByType(appType).getAid();
5810 } catch (Exception e) {
5811 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5812 }
5813 return aid;
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005816 }
Youhan Wange64578a2016-05-02 15:32:42 -07005817 }
5818
Youhan Wang4001d252016-05-11 10:29:41 -07005819 /**
5820 * Return the Electronic Serial Number.
5821 *
5822 * @param subId the subscription ID that this request applies to.
5823 * @return ESN or null if error.
5824 */
5825 @Override
5826 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005827 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005828 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829
5830 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005831 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 if (phone == null) {
5833 return null;
5834 }
5835 String esn = null;
5836 try {
5837 esn = phone.getEsn();
5838 } catch (Exception e) {
5839 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5840 }
5841 return esn;
5842 } finally {
5843 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005844 }
Youhan Wang4001d252016-05-11 10:29:41 -07005845 }
5846
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005847 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005848 * Return the Preferred Roaming List Version.
5849 *
5850 * @param subId the subscription ID that this request applies to.
5851 * @return PRLVersion or null if error.
5852 */
5853 @Override
5854 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005855 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005856 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857
5858 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005859 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 if (phone == null) {
5861 return null;
5862 }
5863 String cdmaPrlVersion = null;
5864 try {
5865 cdmaPrlVersion = phone.getCdmaPrlVersion();
5866 } catch (Exception e) {
5867 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5868 }
5869 return cdmaPrlVersion;
5870 } finally {
5871 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005872 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005873 }
5874
5875 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005876 * Get snapshot of Telephony histograms
5877 * @return List of Telephony histograms
5878 * @hide
5879 */
5880 @Override
5881 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5883 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884
5885 final long identity = Binder.clearCallingIdentity();
5886 try {
5887 return RIL.getTelephonyRILTimingHistograms();
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005891 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005892
5893 /**
5894 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005895 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5896 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005897 * Require system privileges. In the future we may add this to carrier APIs.
5898 *
Michele Berionne482f8202018-11-27 18:57:59 -08005899 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005900 */
5901 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005902 @TelephonyManager.SetCarrierRestrictionResult
5903 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005904 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005905 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005906
Michele Berionne482f8202018-11-27 18:57:59 -08005907 if (carrierRestrictionRules == null) {
5908 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005909 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 final long identity = Binder.clearCallingIdentity();
5912 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005913 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005914 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005918 }
5919
5920 /**
5921 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005922 * Get the allowed carrier list and the excluded carrier list, including the priority between
5923 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005924 * Require system privileges. In the future we may add this to carrier APIs.
5925 *
Michele Berionne482f8202018-11-27 18:57:59 -08005926 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005927 */
5928 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005929 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005930 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005931 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932
5933 final long identity = Binder.clearCallingIdentity();
5934 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005935 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5936 if (response instanceof CarrierRestrictionRules) {
5937 return (CarrierRestrictionRules) response;
5938 }
5939 // Response is an Exception of some kind,
5940 // which is signalled to the user as a NULL retval
5941 return null;
5942 } catch (Exception e) {
5943 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5944 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 } finally {
5946 Binder.restoreCallingIdentity(identity);
5947 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005948 }
5949
fionaxu59545b42016-05-25 15:53:37 -07005950 /**
5951 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5952 * @param subId the subscription ID that this action applies to.
5953 * @param enabled control enable or disable metered apns.
5954 * {@hide}
5955 */
5956 @Override
5957 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5958 enforceModifyPermission();
5959 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960
5961 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005962 if (phone == null) {
5963 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5964 return;
5965 }
5966 try {
5967 phone.carrierActionSetMeteredApnsEnabled(enabled);
5968 } catch (Exception e) {
5969 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 } finally {
5971 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005972 }
5973 }
5974
5975 /**
5976 * Action set from carrier signalling broadcast receivers to enable/disable radio
5977 * @param subId the subscription ID that this action applies to.
5978 * @param enabled control enable or disable radio.
5979 * {@hide}
5980 */
5981 @Override
5982 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5983 enforceModifyPermission();
5984 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985
5986 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005987 if (phone == null) {
5988 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5989 return;
5990 }
5991 try {
5992 phone.carrierActionSetRadioEnabled(enabled);
5993 } catch (Exception e) {
5994 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 } finally {
5996 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005997 }
5998 }
5999
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006000 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006001 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6002 * network status based on which carrier apps could apply actions accordingly,
6003 * enable/disable default url handler for example.
6004 *
6005 * @param subId the subscription ID that this action applies to.
6006 * @param report control start/stop reporting the default network status.
6007 * {@hide}
6008 */
6009 @Override
6010 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6011 enforceModifyPermission();
6012 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013
6014 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006015 if (phone == null) {
6016 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6017 return;
6018 }
6019 try {
6020 phone.carrierActionReportDefaultNetworkStatus(report);
6021 } catch (Exception e) {
6022 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 } finally {
6024 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006025 }
6026 }
6027
6028 /**
fionaxud9622282017-07-17 17:51:30 -07006029 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6030 * @param subId the subscription ID that this action applies to.
6031 * {@hide}
6032 */
6033 @Override
6034 public void carrierActionResetAll(int subId) {
6035 enforceModifyPermission();
6036 final Phone phone = getPhone(subId);
6037 if (phone == null) {
6038 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6039 return;
6040 }
6041 try {
6042 phone.carrierActionResetAll();
6043 } catch (Exception e) {
6044 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6045 }
6046 }
6047
6048 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006049 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6050 * bug report is being generated.
6051 */
6052 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006053 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006054 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6055 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006056 writer.println("Permission Denial: can't dump Phone from pid="
6057 + Binder.getCallingPid()
6058 + ", uid=" + Binder.getCallingUid()
6059 + "without permission "
6060 + android.Manifest.permission.DUMP);
6061 return;
6062 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006063 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006064 }
Jack Yueb89b242016-06-22 13:27:47 -07006065
Brad Ebingerdac2f002018-04-03 15:17:52 -07006066 @Override
6067 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6068 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6069 throws RemoteException {
6070 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6071 }
6072
Jack Yueb89b242016-06-22 13:27:47 -07006073 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006074 * Get aggregated video call data usage since boot.
6075 *
6076 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6077 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006078 * {@hide}
6079 */
6080 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006081 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006082 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6083 null);
6084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 // NetworkStatsService keeps tracking the active network interface and identity. It
6088 // records the delta with the corresponding network identity.
6089 // We just return the total video call data usage snapshot since boot.
6090 Phone phone = getPhone(subId);
6091 if (phone != null) {
6092 return phone.getVtDataUsage(perUidStats);
6093 }
6094 return null;
6095 } finally {
6096 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006097 }
Jack Yueb89b242016-06-22 13:27:47 -07006098 }
Jack Yu75ab2952016-07-08 14:29:33 -07006099
6100 /**
6101 * Policy control of data connection. Usually used when data limit is passed.
6102 * @param enabled True if enabling the data, otherwise disabling.
6103 * @param subId Subscription index
6104 * {@hide}
6105 */
6106 @Override
6107 public void setPolicyDataEnabled(boolean enabled, int subId) {
6108 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109
6110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 Phone phone = getPhone(subId);
6113 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006114 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 }
6116 } finally {
6117 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006118 }
6119 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006120
6121 /**
6122 * Get Client request stats
6123 * @return List of Client Request Stats
6124 * @hide
6125 */
6126 @Override
6127 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006129 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006130 return null;
6131 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006132 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 final long identity = Binder.clearCallingIdentity();
6135 try {
6136 if (phone != null) {
6137 return phone.getClientRequestStats();
6138 }
6139
6140 return null;
6141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006144 }
6145
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006146 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006147 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006148 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006149 }
Jack Yueb4124c2017-02-16 15:32:43 -08006150
6151 /**
Grace Chen70990072017-03-24 17:21:30 -07006152 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006153 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006154 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006155 * @param state State of SIM (power down, power up, pass through)
6156 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6157 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6158 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006159 *
6160 **/
6161 @Override
Grace Chen70990072017-03-24 17:21:30 -07006162 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006163 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006164 Phone phone = PhoneFactory.getPhone(slotIndex);
6165
vagdeviaf9a5b92018-08-15 16:01:53 -07006166 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 final long identity = Binder.clearCallingIdentity();
6169 try {
6170 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006171 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 }
6173 } finally {
6174 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006175 }
6176 }
Shuo Qiandd210312017-04-12 22:11:33 +00006177
Tyler Gunn65d45c22017-06-05 11:22:26 -07006178 private boolean isUssdApiAllowed(int subId) {
6179 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006180 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006181 if (configManager == null) {
6182 return false;
6183 }
6184 PersistableBundle pb = configManager.getConfigForSubId(subId);
6185 if (pb == null) {
6186 return false;
6187 }
6188 return pb.getBoolean(
6189 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6190 }
6191
Shuo Qiandd210312017-04-12 22:11:33 +00006192 /**
6193 * Check if phone is in emergency callback mode
6194 * @return true if phone is in emergency callback mode
6195 * @param subId sub id
6196 */
goneil9c5f4872017-12-05 14:07:56 -08006197 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006198 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006199 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006200 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201
6202 final long identity = Binder.clearCallingIdentity();
6203 try {
6204 if (phone != null) {
6205 return phone.isInEcm();
6206 } else {
6207 return false;
6208 }
6209 } finally {
6210 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006211 }
6212 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006213
6214 /**
6215 * Get the current signal strength information for the given subscription.
6216 * Because this information is not updated when the device is in a low power state
6217 * it should not be relied-upon to be current.
6218 * @param subId Subscription index
6219 * @return the most recent cached signal strength info from the modem
6220 */
6221 @Override
6222 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 Phone p = getPhone(subId);
6226 if (p == null) {
6227 return null;
6228 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 return p.getSignalStrength();
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006234 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006235
Pengquan Meng77b7f132018-08-22 14:49:57 -07006236 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006237 * Get the current modem radio state for the given slot.
6238 * @param slotIndex slot index.
6239 * @param callingPackage the name of the package making the call.
6240 * @return the current radio power state from the modem
6241 */
6242 @Override
6243 public int getRadioPowerState(int slotIndex, String callingPackage) {
6244 Phone phone = PhoneFactory.getPhone(slotIndex);
6245 if (phone != null) {
6246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6247 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6248 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6249 }
6250
6251 final long identity = Binder.clearCallingIdentity();
6252 try {
6253 return phone.getRadioPowerState();
6254 } finally {
6255 Binder.restoreCallingIdentity(identity);
6256 }
6257 }
6258 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6259 }
6260
6261 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006262 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6263 *
6264 * <p>Requires one of the following permissions:
6265 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6266 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6267 * privileges.
6268 *
6269 * @param subId subscription id
6270 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6271 * {@code false}.
6272 */
6273 @Override
6274 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006275 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6276 null /* message */);
6277
Pengquan Menga1bb6272018-09-06 09:59:22 -07006278 boolean isEnabled = false;
6279 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006280 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006281 Phone phone = getPhone(subId);
6282 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006283 } catch (Exception e) {
6284 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6285 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006286 } finally {
6287 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006288 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006289 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006290 }
6291
6292
6293 /**
6294 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6295 *
6296 * <p> Requires permission:
6297 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6298 * privileges.
6299 *
6300 * @param subId subscription id
6301 * @param isEnabled {@code true} means enable, {@code false} means disable.
6302 */
6303 @Override
6304 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6306 mApp, subId, "setDataRoamingEnabled");
6307
Pengquan Menga1bb6272018-09-06 09:59:22 -07006308 final long identity = Binder.clearCallingIdentity();
6309 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006310 Phone phone = getPhone(subId);
6311 if (phone != null) {
6312 phone.setDataRoamingEnabled(isEnabled);
6313 }
6314 } finally {
6315 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006316 }
6317 }
6318
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006319 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006320 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006321 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6322 mApp, subId, "isManualNetworkSelectionAllowed");
6323
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006324 boolean isAllowed = true;
6325 final long identity = Binder.clearCallingIdentity();
6326 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006327 Phone phone = getPhone(subId);
6328 if (phone != null) {
6329 isAllowed = phone.isCspPlmnEnabled();
6330 }
6331 } finally {
6332 Binder.restoreCallingIdentity(identity);
6333 }
6334 return isAllowed;
6335 }
6336
6337 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006338 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006339 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006340 try {
6341 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006342 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006343 } catch (SecurityException e) {
6344 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6345 // has carrier privileges on an active UICC
6346 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6347 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006348 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006349 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006350 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006351
6352 final long identity = Binder.clearCallingIdentity();
6353 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006354 UiccController uiccController = UiccController.getInstance();
6355 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006356 if (hasReadPermission) {
6357 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006358 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006359
6360 // Remove private info if the caller doesn't have access
6361 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6362 for (UiccCardInfo cardInfo : cardInfos) {
6363 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6364 // is available
6365 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6366 if (card == null || card.getUiccProfile() == null) {
6367 // assume no access if the card or profile is unavailable
6368 filteredInfos.add(cardInfo.getUnprivileged());
6369 continue;
6370 }
6371 UiccProfile profile = card.getUiccProfile();
6372 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6373 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6374 filteredInfos.add(cardInfo);
6375 } else {
6376 filteredInfos.add(cardInfo.getUnprivileged());
6377 }
6378 }
6379 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
6383 }
6384
6385 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006386 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006387 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6392 if (slots == null) {
6393 Rlog.i(LOG_TAG, "slots is null.");
6394 return null;
6395 }
6396
6397 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6398 for (int i = 0; i < slots.length; i++) {
6399 UiccSlot slot = slots[i];
6400 if (slot == null) {
6401 continue;
6402 }
6403
Jordan Liu7be7e652019-05-06 18:55:02 +00006404 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 UiccCard card = slot.getUiccCard();
6406 if (card != null) {
6407 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006408 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409 cardId = slot.getIccId();
6410 }
6411
6412 int cardState = 0;
6413 switch (slot.getCardState()) {
6414 case CARDSTATE_ABSENT:
6415 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6416 break;
6417 case CARDSTATE_PRESENT:
6418 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6419 break;
6420 case CARDSTATE_ERROR:
6421 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6422 break;
6423 case CARDSTATE_RESTRICTED:
6424 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6425 break;
6426 default:
6427 break;
6428
6429 }
6430
6431 infos[i] = new UiccSlotInfo(
6432 slot.isActive(),
6433 slot.isEuicc(),
6434 cardId,
6435 cardState,
6436 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006437 slot.isExtendedApduSupported(),
6438 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 }
6440 return infos;
6441 } finally {
6442 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006443 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006444 }
6445
6446 @Override
6447 public boolean switchSlots(int[] physicalSlots) {
6448 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449
6450 final long identity = Binder.clearCallingIdentity();
6451 try {
6452 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006456 }
Jack Yu4c988042018-02-27 15:30:01 -08006457
6458 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006459 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 return UiccController.getInstance().getCardIdForDefaultEuicc();
6463 } finally {
6464 Binder.restoreCallingIdentity(identity);
6465 }
6466 }
6467
6468 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006469 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6470 enforceModifyPermission();
6471 final Phone phone = getPhone(subId);
6472 if (phone == null) {
6473 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6474 return;
6475 }
6476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 final long identity = Binder.clearCallingIdentity();
6478 try {
6479 phone.setRadioIndicationUpdateMode(filters, mode);
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
Jack Yu4c988042018-02-27 15:30:01 -08006483 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006484
6485 /**
goneil47ffb6e2018-04-06 15:40:58 -07006486 * A test API to reload the UICC profile.
6487 *
6488 * <p>Requires that the calling app has permission
6489 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6490 * @hide
6491 */
6492 @Override
6493 public void refreshUiccProfile(int subId) {
6494 enforceModifyPermission();
6495
6496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 Phone phone = getPhone(subId);
6499 if (phone == null) {
6500 return;
6501 }
6502 UiccCard uiccCard = phone.getUiccCard();
6503 if (uiccCard == null) {
6504 return;
6505 }
6506 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6507 if (uiccProfile == null) {
6508 return;
6509 }
6510 uiccProfile.refresh();
6511 } finally {
6512 Binder.restoreCallingIdentity(identity);
6513 }
6514 }
6515
6516 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006517 * Returns false if the mobile data is disabled by default, otherwise return true.
6518 */
6519 private boolean getDefaultDataEnabled() {
6520 return "true".equalsIgnoreCase(
6521 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6522 }
6523
6524 /**
6525 * Returns true if the data roaming is enabled by default, i.e the system property
6526 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6527 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6528 */
6529 private boolean getDefaultDataRoamingEnabled(int subId) {
6530 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006531 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006532 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6533 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6534 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6535 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6536 return isDataRoamingEnabled;
6537 }
6538
6539 /**
6540 * Returns the default network type for the given {@code subId}, if the default network type is
6541 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6542 */
6543 private int getDefaultNetworkType(int subId) {
6544 return Integer.parseInt(
6545 TelephonyManager.getTelephonyProperty(
6546 mSubscriptionController.getPhoneId(subId),
6547 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6548 String.valueOf(Phone.PREFERRED_NT_MODE)));
6549 }
fionaxua13278b2018-03-21 00:08:13 -07006550
6551 @Override
6552 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006553 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555
6556 final long identity = Binder.clearCallingIdentity();
6557 try {
6558 final Phone phone = getPhone(subId);
6559 if (phone == null) {
6560 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6561 return;
6562 }
chen xueaba88a2019-03-15 13:15:10 -07006563 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6564 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 } finally {
6566 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006567 }
fionaxua13278b2018-03-21 00:08:13 -07006568 }
6569
6570 @Override
6571 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006572 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573
6574 final long identity = Binder.clearCallingIdentity();
6575 try {
6576 final Phone phone = getPhone(subId);
6577 if (phone == null) {
6578 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6579 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6580 }
6581 return phone.getCarrierIdListVersion();
6582 } finally {
6583 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006584 }
fionaxua13278b2018-03-21 00:08:13 -07006585 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006586
6587 @Override
6588 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6590 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6591 return -1;
6592 }
6593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6597 } finally {
6598 Binder.restoreCallingIdentity(identity);
6599 }
6600 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006601
6602 @Override
6603 public int getCdmaRoamingMode(int subId) {
6604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6605 mApp, subId, "getCdmaRoamingMode");
6606
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
6613 }
6614
6615 @Override
6616 public boolean setCdmaRoamingMode(int subId, int mode) {
6617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6618 mApp, subId, "setCdmaRoamingMode");
6619
6620 final long identity = Binder.clearCallingIdentity();
6621 try {
6622 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
6626 }
6627
6628 @Override
6629 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6631 mApp, subId, "setCdmaSubscriptionMode");
6632
6633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
6638 }
6639 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006640
6641 private void ensureUserRunning(int userId) {
6642 if (!mUserManager.isUserRunning(userId)) {
6643 throw new IllegalStateException("User " + userId + " does not exist or not running");
6644 }
6645 }
6646
6647 /**
6648 * Returns a list of SMS apps on a given user.
6649 *
6650 * Only the shell user (UID 2000 or 0) can call it.
6651 * Target user must be running.
6652 */
6653 @Override
6654 public String[] getSmsApps(int userId) {
6655 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6656 ensureUserRunning(userId);
6657
6658 final Collection<SmsApplicationData> apps =
6659 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6660
6661 String[] ret = new String[apps.size()];
6662 int i = 0;
6663 for (SmsApplicationData app : apps) {
6664 ret[i++] = app.mPackageName;
6665 }
6666 return ret;
6667 }
6668
6669 /**
6670 * Returns the default SMS app package name on a given user.
6671 *
6672 * Only the shell user (UID 2000 or 0) can call it.
6673 * Target user must be running.
6674 */
6675 @Override
6676 public String getDefaultSmsApp(int userId) {
6677 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6678 ensureUserRunning(userId);
6679
6680 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6681 /* updateIfNeeded= */ true, userId);
6682 return cn == null ? null : cn.getPackageName();
6683 }
6684
6685 /**
6686 * Set a package as the default SMS app on a given user.
6687 *
6688 * Only the shell user (UID 2000 or 0) can call it.
6689 * Target user must be running.
6690 */
6691 @Override
6692 public void setDefaultSmsApp(int userId, String packageName) {
6693 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6694 ensureUserRunning(userId);
6695
6696 boolean found = false;
6697 for (String pkg : getSmsApps(userId)) {
6698 if (TextUtils.equals(packageName, pkg)) {
6699 found = true;
6700 break;
6701 }
6702 }
6703 if (!found) {
6704 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6705 }
6706
6707 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6708 }
sqianc5eccab2018-10-19 18:46:41 -07006709
6710 @Override
sqian8c685422019-02-22 15:55:18 -08006711 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006712 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006714 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006715 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6716 }
6717 final long identity = Binder.clearCallingIdentity();
6718 try {
sqian854d44b2018-12-12 16:48:18 -08006719 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6720 for (Phone phone: PhoneFactory.getPhones()) {
6721 if (phone.getEmergencyNumberTracker() != null
6722 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6723 emergencyNumberListInternal.put(
6724 phone.getSubId(),
6725 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6726 }
sqian11b7a0e2018-12-05 18:48:28 -08006727 }
sqian854d44b2018-12-12 16:48:18 -08006728 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006729 } finally {
6730 Binder.restoreCallingIdentity(identity);
6731 }
sqianc5eccab2018-10-19 18:46:41 -07006732 }
6733
6734 @Override
sqian8c685422019-02-22 15:55:18 -08006735 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006736 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006737 if (!exactMatch) {
6738 TelephonyPermissions
6739 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006740 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006741 }
6742 final long identity = Binder.clearCallingIdentity();
6743 try {
sqian854d44b2018-12-12 16:48:18 -08006744 for (Phone phone: PhoneFactory.getPhones()) {
6745 if (phone.getEmergencyNumberTracker() != null
6746 && phone.getEmergencyNumberTracker() != null) {
6747 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6748 number, exactMatch)) {
6749 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006750 }
6751 }
sqian11b7a0e2018-12-05 18:48:28 -08006752 }
6753 return false;
6754 } finally {
6755 Binder.restoreCallingIdentity(identity);
6756 }
6757 }
6758
sqianf4ca7ed2019-01-15 18:32:07 -08006759 /**
6760 * Update emergency number list for test mode.
6761 */
6762 @Override
6763 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6764 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6765 "updateEmergencyNumberListTestMode");
6766
6767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 for (Phone phone: PhoneFactory.getPhones()) {
6770 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6771 if (tracker != null) {
6772 tracker.executeEmergencyNumberTestModeCommand(action, num);
6773 }
6774 }
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
6778 }
6779
6780 /**
6781 * Get the full emergency number list for test mode.
6782 */
6783 @Override
6784 public List<String> getEmergencyNumberListTestMode() {
6785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6786 "getEmergencyNumberListTestMode");
6787
6788 final long identity = Binder.clearCallingIdentity();
6789 try {
6790 Set<String> emergencyNumbers = new HashSet<>();
6791 for (Phone phone: PhoneFactory.getPhones()) {
6792 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6793 if (tracker != null) {
6794 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6795 emergencyNumbers.add(num.getNumber());
6796 }
6797 }
6798 }
6799 return new ArrayList<>(emergencyNumbers);
6800 } finally {
6801 Binder.restoreCallingIdentity(identity);
6802 }
6803 }
6804
chen xud6b45bd2018-10-30 22:27:10 -07006805 @Override
6806 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6807 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6808 Phone phone = getPhone(subId);
6809 if (phone == null) {
6810 return null;
6811 }
6812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 UiccProfile profile = UiccController.getInstance()
6815 .getUiccProfileForPhone(phone.getPhoneId());
6816 if (profile != null) {
6817 return profile.getCertsFromCarrierPrivilegeAccessRules();
6818 }
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
6821 }
6822 return null;
6823 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006824
6825 /**
6826 * Enable or disable a modem stack.
6827 */
6828 @Override
6829 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6830 enforceModifyPermission();
6831
6832 final long identity = Binder.clearCallingIdentity();
6833 try {
6834 Phone phone = PhoneFactory.getPhone(slotIndex);
6835 if (phone == null) {
6836 return false;
6837 } else {
6838 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6839 }
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842 }
6843 }
Michelecea4cf22018-12-21 15:00:11 -08006844
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006845 /**
6846 * Whether a modem stack is enabled or not.
6847 */
6848 @Override
6849 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6850 Phone phone = PhoneFactory.getPhone(slotIndex);
6851 if (phone == null) return false;
6852
6853 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6854 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6855 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6856 }
6857
6858 final long identity = Binder.clearCallingIdentity();
6859 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006860 try {
6861 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6862 } catch (NoSuchElementException ex) {
6863 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6864 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006865 } finally {
6866 Binder.restoreCallingIdentity(identity);
6867 }
6868 }
6869
Michelecea4cf22018-12-21 15:00:11 -08006870 @Override
Michele0ea7d782019-03-19 14:58:42 -07006871 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006872 enforceModifyPermission();
6873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006877 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006878 .commit();
6879 } finally {
6880 Binder.restoreCallingIdentity(identity);
6881 }
6882 }
6883
6884 @Override
Michele0ea7d782019-03-19 14:58:42 -07006885 @TelephonyManager.IsMultiSimSupportedResult
6886 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006888 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6889 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006890 }
Michelecea4cf22018-12-21 15:00:11 -08006891
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
Michele0ea7d782019-03-19 14:58:42 -07006894 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006895 } finally {
6896 Binder.restoreCallingIdentity(identity);
6897 }
6898 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006899
Michele0ea7d782019-03-19 14:58:42 -07006900 @TelephonyManager.IsMultiSimSupportedResult
6901 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006902 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6903 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6904 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006905 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6906 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006907 }
6908 // Check if the hardware supports multisim functionality. If usage of multisim is not
6909 // supported by the modem, indicate that it is restricted.
6910 PhoneCapability staticCapability =
6911 mPhoneConfigurationManager.getStaticPhoneCapability();
6912 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006913 loge("isMultiSimSupportedInternal: no static configuration available");
6914 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006915 }
6916 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006917 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6918 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006919 }
6920 // Check if support of multiple SIMs is restricted by carrier
6921 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006922 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006923 }
6924
Michele0ea7d782019-03-19 14:58:42 -07006925 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006926 }
6927
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006928 /**
6929 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006930 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6931 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6932 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006933 * @param numOfSims number of active sims we want to switch to
6934 */
6935 @Override
6936 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006937 if (numOfSims == 1) {
6938 enforceModifyPermission();
6939 } else {
6940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6941 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6942 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006943 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006944
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006945 try {
Michele30b57b22019-03-01 12:01:14 -08006946 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006947 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006948 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6949 return;
6950 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006951 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6952 } finally {
6953 Binder.restoreCallingIdentity(identity);
6954 }
6955 }
6956
6957 /**
chen xub4baa772019-04-03 10:23:41 -07006958 * Get whether making changes to modem configurations will trigger reboot.
6959 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006960 */
6961 @Override
chen xub4baa772019-04-03 10:23:41 -07006962 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6963 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6964 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6965 return false;
6966 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6970 } finally {
6971 Binder.restoreCallingIdentity(identity);
6972 }
6973 }
6974
Nathan Harold29f5f052019-02-15 13:41:57 -08006975 private void updateModemStateMetrics() {
6976 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6977 // TODO: check the state for each modem if the api is ready.
6978 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6979 }
6980
Pengquan Meng3889a572019-01-23 11:16:29 -08006981 @Override
6982 public int[] getSlotsMapping() {
6983 enforceReadPrivilegedPermission("getSlotsMapping");
6984
6985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6988 // All logical slots should have a mapping to a physical slot.
6989 int[] logicalSlotsMapping = new int[phoneCount];
6990 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6991 for (int i = 0; i < slotInfos.length; i++) {
6992 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6993 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6994 }
6995 }
6996 return logicalSlotsMapping;
6997 } finally {
6998 Binder.restoreCallingIdentity(identity);
6999 }
7000 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007001
7002 /**
7003 * Get the IRadio HAL Version
7004 */
7005 @Override
7006 public int getRadioHalVersion() {
7007 Phone phone = getDefaultPhone();
7008 if (phone == null) return -1;
7009 HalVersion hv = phone.getHalVersion();
7010 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7011 return hv.major * 100 + hv.minor;
7012 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007013
7014 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007015 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7016 * corresponding network requests on a subId.
7017 *
7018 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007019 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007020 * 2) APN is un-metered for this subscription, or
7021 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7022 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7023 *
7024 * @return whether data is allowed for a apn type.
7025 *
7026 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007027 */
7028 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007029 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007031 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7032 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007033 }
7034
7035 // Now that all security checks passes, perform the operation as ourselves.
7036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 Phone phone = getPhone(subId);
7039 if (phone == null) return false;
7040
7041 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007042 apnType), phone);
7043 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7044 } finally {
7045 Binder.restoreCallingIdentity(identity);
7046 }
7047 }
7048
7049 @Override
7050 public boolean isApnMetered(int apnType, int subId) {
7051 enforceReadPrivilegedPermission("isApnMetered");
7052
7053 // Now that all security checks passes, perform the operation as ourselves.
7054 final long identity = Binder.clearCallingIdentity();
7055 try {
7056 Phone phone = getPhone(subId);
7057 if (phone == null) return true; // By default return true.
7058
7059 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
7060 apnType), phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007061 } finally {
7062 Binder.restoreCallingIdentity(identity);
7063 }
7064 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007065}