blob: f428c52a68ee492a6a35cba1f0ecf6ec16fe8c12 [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:
Nathan Haroldb3c5da42019-05-09 10:26:08 -07002139 try {
2140 cb.onCellInfo(new ArrayList<CellInfo>());
2141 } catch (RemoteException re) {
2142 // Drop without consequences
2143 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002144 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002145 }
2146
Nathan Harold32e84c42019-05-09 10:13:47 -07002147
2148 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002149 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2150
2151 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2152 }
2153
2154 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002156 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002157 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002158
2159 final long identity = Binder.clearCallingIdentity();
2160 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002161 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002162 } finally {
2163 Binder.restoreCallingIdentity(identity);
2164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
Shishir Agrawala9f32182016-04-12 12:00:16 -07002167 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002168 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002169 Phone phone = PhoneFactory.getPhone(slotIndex);
2170 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002171 return null;
2172 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002173 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002174 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2175 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002176 return null;
2177 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002178
2179 final long identity = Binder.clearCallingIdentity();
2180 try {
2181 return phone.getImei();
2182 } finally {
2183 Binder.restoreCallingIdentity(identity);
2184 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002185 }
2186
2187 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002188 public String getTypeAllocationCodeForSlot(int slotIndex) {
2189 Phone phone = PhoneFactory.getPhone(slotIndex);
2190 String tac = null;
2191 if (phone != null) {
2192 String imei = phone.getImei();
2193 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2194 }
2195 return tac;
2196 }
2197
2198 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002199 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002200 Phone phone = PhoneFactory.getPhone(slotIndex);
2201 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002202 return null;
2203 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002204
Jeff Davidson913390f2018-02-23 17:11:49 -08002205 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002206 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2207 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002208 return null;
2209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210
2211 final long identity = Binder.clearCallingIdentity();
2212 try {
2213 return phone.getMeid();
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
2216 }
Jack Yu2af8d712017-03-15 17:14:14 -07002217 }
2218
2219 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002220 public String getManufacturerCodeForSlot(int slotIndex) {
2221 Phone phone = PhoneFactory.getPhone(slotIndex);
2222 String manufacturerCode = null;
2223 if (phone != null) {
2224 String meid = phone.getMeid();
2225 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2226 }
2227 return manufacturerCode;
2228 }
2229
2230 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002231 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002232 Phone phone = PhoneFactory.getPhone(slotIndex);
2233 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002234 return null;
2235 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002236 int subId = phone.getSubId();
2237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2238 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2239 return null;
2240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241
2242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 return phone.getDeviceSvn();
2245 } finally {
2246 Binder.restoreCallingIdentity(identity);
2247 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002248 }
2249
fionaxu43304da2017-11-27 22:51:16 -08002250 @Override
2251 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 final Phone phone = getPhone(subId);
2255 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
2258 }
fionaxu43304da2017-11-27 22:51:16 -08002259 }
2260
2261 @Override
2262 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263 final long identity = Binder.clearCallingIdentity();
2264 try {
2265 final Phone phone = getPhone(subId);
2266 return phone == null ? null : phone.getCarrierName();
2267 } finally {
2268 Binder.restoreCallingIdentity(identity);
2269 }
fionaxu43304da2017-11-27 22:51:16 -08002270 }
2271
calvinpanffe225e2018-11-01 19:43:06 +08002272 @Override
chen xu0026ca62019-03-06 15:28:50 -08002273 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002274 final long identity = Binder.clearCallingIdentity();
2275 try {
2276 final Phone phone = getPhone(subId);
2277 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002278 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002279 } finally {
2280 Binder.restoreCallingIdentity(identity);
2281 }
2282 }
2283
2284 @Override
chen xu0026ca62019-03-06 15:28:50 -08002285 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002286 final long identity = Binder.clearCallingIdentity();
2287 try {
2288 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002289 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002290 } finally {
2291 Binder.restoreCallingIdentity(identity);
2292 }
2293 }
2294
chen xu651eec72018-11-11 19:03:44 -08002295 @Override
chen xu864e11c2018-12-06 22:10:03 -08002296 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2297 if (!isSubscriptionMccMnc) {
2298 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2299 }
chen xu651eec72018-11-11 19:03:44 -08002300 final Phone phone = PhoneFactory.getPhone(slotIndex);
2301 if (phone == null) {
2302 return TelephonyManager.UNKNOWN_CARRIER_ID;
2303 }
2304 final long identity = Binder.clearCallingIdentity();
2305 try {
2306 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2307 } finally {
2308 Binder.restoreCallingIdentity(identity);
2309 }
2310 }
2311
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 //
2313 // Internal helper methods.
2314 //
2315
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002316 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2318 *
2319 * @throws SecurityException if the caller does not have the required permission
2320 */
2321 private void enforceModifyPermission() {
2322 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2323 }
2324
2325 /**
2326 * Make sure the caller has the CALL_PHONE permission.
2327 *
2328 * @throws SecurityException if the caller does not have the required permission
2329 */
2330 private void enforceCallPermission() {
2331 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2332 }
2333
Stuart Scott8eef64f2015-04-08 15:13:54 -07002334 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002335 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002336 "ConnectivityService");
2337 }
2338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 private String createTelUrl(String number) {
2340 if (TextUtils.isEmpty(number)) {
2341 return null;
2342 }
2343
Jake Hambye994d462014-02-03 13:10:13 -08002344 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 }
2346
Ihab Awadf9e92732013-12-05 18:02:52 -08002347 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2349 }
2350
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002351 private static void logv(String msg) {
2352 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2353 }
2354
Ihab Awadf9e92732013-12-05 18:02:52 -08002355 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2357 }
2358
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002359 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002361 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002362 }
2363
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002365 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = PhoneFactory.getPhone(slotIndex);
2369 if (phone == null) {
2370 return PhoneConstants.PHONE_TYPE_NONE;
2371 } else {
2372 return phone.getPhoneType();
2373 }
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002376 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 }
2378
2379 /**
2380 * Returns the CDMA ERI icon index to display
2381 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002382 @Override
2383 public int getCdmaEriIconIndex(String callingPackage) {
2384 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002385 }
2386
Sanket Padawe356d7632015-06-22 14:03:32 -07002387 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002388 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002390 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002391 return -1;
2392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393
2394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 final Phone phone = getPhone(subId);
2397 if (phone != null) {
2398 return phone.getCdmaEriIconIndex();
2399 } else {
2400 return -1;
2401 }
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
2406
2407 /**
2408 * Returns the CDMA ERI icon mode,
2409 * 0 - ON
2410 * 1 - FLASHING
2411 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002412 @Override
2413 public int getCdmaEriIconMode(String callingPackage) {
2414 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002415 }
2416
Sanket Padawe356d7632015-06-22 14:03:32 -07002417 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002418 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002420 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002421 return -1;
2422 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423
2424 final long identity = Binder.clearCallingIdentity();
2425 try {
2426 final Phone phone = getPhone(subId);
2427 if (phone != null) {
2428 return phone.getCdmaEriIconMode();
2429 } else {
2430 return -1;
2431 }
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
2437 /**
2438 * Returns the CDMA ERI text,
2439 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002440 @Override
2441 public String getCdmaEriText(String callingPackage) {
2442 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002443 }
2444
Sanket Padawe356d7632015-06-22 14:03:32 -07002445 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002446 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002448 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002449 return null;
2450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451
2452 final long identity = Binder.clearCallingIdentity();
2453 try {
2454 final Phone phone = getPhone(subId);
2455 if (phone != null) {
2456 return phone.getCdmaEriText();
2457 } else {
2458 return null;
2459 }
2460 } finally {
2461 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464
2465 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002466 * Returns the CDMA MDN.
2467 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002468 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002469 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2471 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472
2473 final long identity = Binder.clearCallingIdentity();
2474 try {
2475 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002476 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 return phone.getLine1Number();
2478 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002479 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 return null;
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002484 }
2485 }
2486
2487 /**
2488 * Returns the CDMA MIN.
2489 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002490 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2493 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494
2495 final long identity = Binder.clearCallingIdentity();
2496 try {
2497 final Phone phone = getPhone(subId);
2498 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2499 return phone.getCdmaMin();
2500 } else {
2501 return null;
2502 }
2503 } finally {
2504 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002505 }
2506 }
2507
Hall Liud892bec2018-11-30 14:51:45 -08002508 @Override
2509 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2510 INumberVerificationCallback callback, String callingPackage) {
2511 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2512 != PERMISSION_GRANTED) {
2513 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2514 }
2515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2516
2517 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2518 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2519 throw new SecurityException("Calling package must be configured in the device config");
2520 }
2521
2522 if (range == null) {
2523 throw new NullPointerException("Range must be non-null");
2524 }
2525
2526 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002527 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002528
2529 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2530 }
2531
Junda Liuca05d5d2014-08-14 22:36:34 -07002532 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 * Returns true if CDMA provisioning needs to run.
2534 */
2535 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536 final long identity = Binder.clearCallingIdentity();
2537 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002538 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539 } finally {
2540 Binder.restoreCallingIdentity(identity);
2541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 }
2543
2544 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002545 * Sets the voice mail number of a given subId.
2546 */
2547 @Override
2548 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002549 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002550
2551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2554 new Pair<String, String>(alphaTag, number), new Integer(subId));
2555 return success;
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
2558 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002559 }
2560
Ta-wei Yen87c49842016-05-13 21:19:52 -07002561 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002562 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2563 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002564 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002565 if (!TextUtils.equals(callingPackage, systemDialer)) {
2566 throw new SecurityException("caller must be system dialer");
2567 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2572 if (phoneAccountHandle == null) {
2573 return null;
2574 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002575 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576 } finally {
2577 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002578 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002579 }
2580
2581 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002582 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002585 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002586 return null;
2587 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002589 final long identity = Binder.clearCallingIdentity();
2590 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002591 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002592 } finally {
2593 Binder.restoreCallingIdentity(identity);
2594 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002595 }
2596
2597 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002598 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2599 VisualVoicemailSmsFilterSettings settings) {
2600 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601
2602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002605 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 } finally {
2607 Binder.restoreCallingIdentity(identity);
2608 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002609 }
2610
2611 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002612 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2613 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002618 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002622 }
2623
2624 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002625 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2626 String callingPackage, int subId) {
2627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002632 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002636 }
2637
2638 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002639 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002640 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002645 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002649 }
2650
2651 @Override
2652 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2653 String number, int port, String text, PendingIntent sentIntent) {
2654 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002655 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002656 enforceSendSmsPermission();
2657 // Make the calls as the phone process.
2658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2661 if (port == 0) {
2662 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2663 sentIntent, null, false);
2664 } else {
2665 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2666 smsManager.sendDataMessageWithSelfPermissions(number, null,
2667 (short) port, data, sentIntent, null);
2668 }
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
2671 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002672 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002673 /**
fionaxu0152e512016-11-14 13:36:14 -08002674 * Sets the voice activation state of a given subId.
2675 */
2676 @Override
2677 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2679 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 final Phone phone = getPhone(subId);
2684 if (phone != null) {
2685 phone.setVoiceActivationState(activationState);
2686 } else {
2687 loge("setVoiceActivationState fails with invalid subId: " + subId);
2688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002691 }
2692 }
2693
2694 /**
2695 * Sets the data activation state of a given subId.
2696 */
2697 @Override
2698 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2700 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701
2702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 final Phone phone = getPhone(subId);
2705 if (phone != null) {
2706 phone.setDataActivationState(activationState);
2707 } else {
2708 loge("setVoiceActivationState fails with invalid subId: " + subId);
2709 }
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002712 }
2713 }
2714
2715 /**
2716 * Returns the voice activation state of a given subId.
2717 */
2718 @Override
2719 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002720 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721
fionaxu0152e512016-11-14 13:36:14 -08002722 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 if (phone != null) {
2726 return phone.getVoiceActivationState();
2727 } else {
2728 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2729 }
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002732 }
2733 }
2734
2735 /**
2736 * Returns the data activation state of a given subId.
2737 */
2738 @Override
2739 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002740 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741
fionaxu0152e512016-11-14 13:36:14 -08002742 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743 final long identity = Binder.clearCallingIdentity();
2744 try {
2745 if (phone != null) {
2746 return phone.getDataActivationState();
2747 } else {
2748 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2749 }
2750 } finally {
2751 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002752 }
2753 }
2754
2755 /**
Wink Saville36469e72014-06-11 15:17:00 -07002756 * Returns the unread count of voicemails for a subId
2757 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002759 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2761 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2762 return 0;
2763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 final Phone phone = getPhone(subId);
2767 if (phone != null) {
2768 return phone.getVoiceMessageCount();
2769 } else {
2770 return 0;
2771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 }
2776
2777 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002778 * returns true, if the device is in a state where both voice and data
2779 * are supported simultaneously. This can change based on location or network condition.
2780 */
2781 @Override
2782 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 final Phone phone = getPhone(subId);
2786 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
2789 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002790 }
2791
2792 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002793 * Send the dialer code if called from the current default dialer or the caller has
2794 * carrier privilege.
2795 * @param inputCode The dialer code to send
2796 */
2797 @Override
2798 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002799 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002801 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2802 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002803 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002804 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2805 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002810 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 } finally {
2812 Binder.restoreCallingIdentity(identity);
2813 }
fionaxu235cc5e2017-03-06 22:25:57 -08002814 }
2815
2816 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002817 * Returns the data network type.
2818 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 *
2820 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2821 */
2822 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002823 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 final Phone phone = getPhone(getDefaultSubscription());
2827 if (phone != null) {
2828 return phone.getServiceState().getDataNetworkType();
2829 } else {
2830 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2831 }
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002834 }
Wink Saville36469e72014-06-11 15:17:00 -07002835 }
2836
Pengquan Menga1bb6272018-09-06 09:59:22 -07002837 @Override
2838 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002839 if (!isActiveSubscription(subId)) {
2840 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2841 }
2842
Pengquan Menga1bb6272018-09-06 09:59:22 -07002843 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2844 }
2845
Brad Ebinger35c841c2018-10-01 10:40:55 -07002846 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002847 public boolean isInEmergencySmsMode() {
2848 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 for (Phone phone : PhoneFactory.getPhones()) {
2852 if (phone.isInEmergencySmsMode()) {
2853 return true;
2854 }
2855 }
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
2859 return false;
2860 }
2861
2862 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002863 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2864 throws RemoteException {
2865 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002866 final long token = Binder.clearCallingIdentity();
2867 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002869 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002870 .addRegistrationCallbackForSubscription(c, subId);
2871 } finally {
2872 Binder.restoreCallingIdentity(token);
2873 }
2874 }
2875
2876 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002877 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2878 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002879 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2880 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2881 }
2882 Binder.withCleanCallingIdentity(() -> {
2883 try {
2884 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002885 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002886 .removeRegistrationCallbackForSubscription(c, subId);
2887 } catch (IllegalArgumentException e) {
2888 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2889 + "is inactive, ignoring unregister.");
2890 // If the subscription is no longer active, just return, since the callback
2891 // will already have been removed internally.
2892 }
2893 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002894 }
2895
2896 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002897 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2898 throws RemoteException {
2899 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002900 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2901 final long token = Binder.clearCallingIdentity();
2902 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002903 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002904 .addCapabilitiesCallbackForSubscription(c, subId);
2905 } finally {
2906 Binder.restoreCallingIdentity(token);
2907 }
2908 }
2909
2910 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002911 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2912 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002913
2914 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2915 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2916 }
2917 Binder.withCleanCallingIdentity(() -> {
2918 try {
2919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002920 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002921 .removeCapabilitiesCallbackForSubscription(c, subId);
2922 } catch (IllegalArgumentException e) {
2923 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2924 + "is inactive, ignoring unregister.");
2925 // If the subscription is no longer active, just return, since the callback
2926 // will already have been removed internally.
2927 }
2928 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002929 }
2930
2931 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002932 public boolean isCapable(int subId, int capability, int regTech) {
2933 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2935 final long token = Binder.clearCallingIdentity();
2936 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002937 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002938 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2939 } catch (ImsException e) {
2940 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2941 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002942 } catch (IllegalArgumentException e) {
2943 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2944 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002945 } finally {
2946 Binder.restoreCallingIdentity(token);
2947 }
2948 }
2949
2950 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002951 public boolean isAvailable(int subId, int capability, int regTech) {
2952 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002953 final long token = Binder.clearCallingIdentity();
2954 try {
2955 Phone phone = getPhone(subId);
2956 if (phone == null) return false;
2957 return phone.isImsCapabilityAvailable(capability, regTech);
2958 } finally {
2959 Binder.restoreCallingIdentity(token);
2960 }
2961 }
2962
2963 @Override
2964 public boolean isAdvancedCallingSettingEnabled(int subId) {
2965 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2966 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2967 final long token = Binder.clearCallingIdentity();
2968 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002969 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002970 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2971 } finally {
2972 Binder.restoreCallingIdentity(token);
2973 }
2974 }
2975
2976 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002977 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002979 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002983 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002984 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
2988 }
2989
2990 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002991 public boolean isVtSettingEnabled(int subId) {
2992 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002997 getSlotIndexOrException(subId)).isVtEnabledByUser();
2998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
3001 }
3002
3003 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003004 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003006 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 final long identity = Binder.clearCallingIdentity();
3008 try {
3009 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003010 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
3014 }
3015
3016 @Override
3017 public boolean isVoWiFiSettingEnabled(int subId) {
3018 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003022 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003023 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
3027 }
3028
3029 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003030 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003032 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
3040 }
3041
3042 @Override
3043 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3044 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003048 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003049 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
3053 }
3054
3055 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003056 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003058 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003062 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003063 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3064 } finally {
3065 Binder.restoreCallingIdentity(identity);
3066 }
3067 }
3068
3069 @Override
3070 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3072 "setVoWiFiNonPersistent");
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003076 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003077 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
3081 }
3082
3083 @Override
3084 public int getVoWiFiModeSetting(int subId) {
3085 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003089 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003090 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
3094 }
3095
3096 @Override
3097 public void setVoWiFiModeSetting(int subId, int mode) {
3098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3099 "setVoWiFiModeSetting");
3100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003103 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003104 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
3108 }
3109
3110 @Override
3111 public int getVoWiFiRoamingModeSetting(int subId) {
3112 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003116 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3118 } finally {
3119 Binder.restoreCallingIdentity(identity);
3120 }
3121 }
3122
3123 @Override
3124 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3126 "setVoWiFiRoamingModeSetting");
3127 final long identity = Binder.clearCallingIdentity();
3128 try {
3129 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003130 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003131 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
3137 @Override
3138 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3140 "setRttCapabilityEnabled");
3141 final long identity = Binder.clearCallingIdentity();
3142 try {
3143 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003144 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
3148 }
3149 }
3150
3151 @Override
3152 public boolean isTtyOverVolteEnabled(int subId) {
3153 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003157 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003158 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
3161 }
3162 }
3163
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003164 @Override
3165 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3166 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3167 final long identity = Binder.clearCallingIdentity();
3168 try {
3169 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003170 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003171 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003172 } finally {
3173 Binder.restoreCallingIdentity(identity);
3174 }
3175 }
3176
3177 @Override
3178 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3179 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3180 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003181 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3182 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3183 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003184 try {
3185 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003186 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003187 .removeProvisioningCallbackForSubscription(callback, subId);
3188 } catch (IllegalArgumentException e) {
3189 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3190 + "is inactive, ignoring unregister.");
3191 // If the subscription is no longer active, just return, since the callback will already
3192 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
3196 }
3197
3198 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003199 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3200 boolean isProvisioned) {
3201 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3202 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3203 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3204 }
3205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3206 "setProvisioningStatusForCapability");
3207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3210 Phone phone = getPhone(subId);
3211 if (phone == null) {
3212 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3213 + subId);
3214 return;
3215 }
3216 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3217 return;
3218 }
3219
3220 // this capability requires provisioning, route to the correct API.
3221 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3222 switch (capability) {
3223 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3224 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3225 ims.setVolteProvisioned(isProvisioned);
3226 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3227 ims.setWfcProvisioned(isProvisioned);
3228 }
3229 break;
3230 }
3231 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3232 // There is currently no difference in VT provisioning type.
3233 ims.setVtProvisioned(isProvisioned);
3234 break;
3235 }
3236 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3237 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3238 // change the capability of the feature instead if needed.
3239 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3240 == isProvisioned) {
3241 // No change in provisioning.
3242 return;
3243 }
3244 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3245 try {
3246 ims.changeMmTelCapability(capability, tech, isProvisioned);
3247 } catch (ImsException e) {
3248 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3249 + ", Exception" + e.getMessage());
3250 }
3251 break;
3252 }
3253 default: {
3254 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3255 + capability + "', which does not require provisioning.");
3256 }
3257 }
3258
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
3262 }
3263
3264 @Override
3265 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3266 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3267 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3268 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3269 }
3270 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3274 Phone phone = getPhone(subId);
3275 if (phone == null) {
3276 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3277 + subId);
3278 // We will fail with "true" as the provisioning status because this is the default
3279 // if we do not require provisioning.
3280 return true;
3281 }
3282
3283 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3284 return true;
3285 }
3286
3287 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3288 switch (capability) {
3289 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3290 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3291 return ims.isVolteProvisionedOnDevice();
3292 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3293 return ims.isWfcProvisionedOnDevice();
3294 }
3295 // This should never happen, since we are checking tech above to make sure it
3296 // is either LTE or IWLAN.
3297 throw new IllegalArgumentException("Invalid radio technology for voice "
3298 + "capability.");
3299 }
3300 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3301 // There is currently no difference in VT provisioning type.
3302 return ims.isVtProvisionedOnDevice();
3303 }
3304 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3305 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3306 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3307 }
3308 default: {
3309 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3310 + capability + "', which does not require provisioning.");
3311 }
3312 }
3313
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
3317 }
3318
3319 @Override
3320 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3321 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3322 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3323 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3324 }
3325 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3326 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3327 return (provisionedBits & capability) > 0;
3328 }
3329
3330 @Override
3331 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3332 boolean isProvisioned) {
3333 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3334 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3335 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3336 }
3337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3338 "setProvisioningStatusForCapability");
3339 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3340 // If the current provisioning status for capability already matches isProvisioned,
3341 // do nothing.
3342 if (((provisionedBits & capability) > 0) == isProvisioned) {
3343 return;
3344 }
3345 if (isProvisioned) {
3346 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3347 } else {
3348 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3349 }
3350 }
3351
3352 /**
3353 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3354 * technology. The bitfield should mirror the bitfield defined by
3355 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3356 */
3357 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3358 String key = getMmTelProvisioningKey(subId, tech);
3359 // Default is no capabilities are provisioned.
3360 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3361 }
3362
3363 /**
3364 * Sets the MmTel capability provisioning bitfield (defined by
3365 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3366 * technology specified.
3367 *
3368 * Note: This is a synchronous command and should not be called on UI thread.
3369 */
3370 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3371 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3372 String key = getMmTelProvisioningKey(subId, tech);
3373 editor.putInt(key, newField);
3374 editor.commit();
3375 }
3376
3377 private static String getMmTelProvisioningKey(int subId, int tech) {
3378 // resulting key is provision_ims_mmtel_{subId}_{tech}
3379 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3380 }
3381
3382 /**
3383 * Query CarrierConfig to see if the specified capability requires provisioning for the
3384 * carrier associated with the subscription id.
3385 */
3386 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3387 int capability) {
3388 CarrierConfigManager configManager = new CarrierConfigManager(context);
3389 PersistableBundle c = configManager.getConfigForSubId(subId);
3390 boolean requireUtProvisioning = c.getBoolean(
3391 // By default, this config is true (even if there is no SIM). We also check to make
3392 // sure the subscription needs provisioning here, so we do not need to check for
3393 // the no-SIM case, where we would normally shortcut this to false.
3394 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3395 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3396 false);
3397 boolean requireVoiceVtProvisioning = c.getBoolean(
3398 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3399
3400 // First check to make sure that the capability requires provisioning.
3401 switch (capability) {
3402 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3403 // intentional fallthrough
3404 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3405 if (requireVoiceVtProvisioning) {
3406 // Voice and Video requires provisioning
3407 return true;
3408 }
3409 break;
3410 }
3411 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3412 if (requireUtProvisioning) {
3413 // UT requires provisioning
3414 return true;
3415 }
3416 break;
3417 }
3418 }
3419 return false;
3420 }
3421
3422 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003423 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003424 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3425 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3426 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003427 enforceReadPrivilegedPermission("getImsProvisioningInt");
3428 final long identity = Binder.clearCallingIdentity();
3429 try {
3430 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003431 int slotId = getSlotIndex(subId);
3432 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3433 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3434 + subId + "' for key:" + key);
3435 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3436 }
3437 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003438 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003439 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3440 + subId + "' for key:" + key);
3441 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
3445 }
3446
3447 @Override
3448 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003449 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3450 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3451 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003452 enforceReadPrivilegedPermission("getImsProvisioningString");
3453 final long identity = Binder.clearCallingIdentity();
3454 try {
3455 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003456 int slotId = getSlotIndex(subId);
3457 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3458 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3459 + subId + "' for key:" + key);
3460 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3461 }
3462 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003463 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003464 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3465 + subId + "' for key:" + key);
3466 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
3470 }
3471
3472 @Override
3473 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003474 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3475 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3476 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3478 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003482 int slotId = getSlotIndex(subId);
3483 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3484 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3485 + subId + "' for key:" + key);
3486 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3487 }
3488 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003489 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003490 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3491 + "' for key:" + key);
3492 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
3496 }
3497
3498 @Override
3499 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003500 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3501 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3502 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3504 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003508 int slotId = getSlotIndex(subId);
3509 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3510 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3511 + subId + "' for key:" + key);
3512 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3513 }
3514 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003515 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003516 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3517 + "' for key:" + key);
3518 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003519 } finally {
3520 Binder.restoreCallingIdentity(identity);
3521 }
3522 }
3523
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3525 int slotId = SubscriptionManager.getSlotIndex(subId);
3526 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003527 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 }
3529 return slotId;
3530 }
3531
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003532 private int getSlotIndex(int subId) {
3533 int slotId = SubscriptionManager.getSlotIndex(subId);
3534 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3535 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3536 }
3537 return slotId;
3538 }
3539
Wink Saville36469e72014-06-11 15:17:00 -07003540 /**
3541 * Returns the network type for a subId
3542 */
3543 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003544 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003546 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003547 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3548 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 final Phone phone = getPhone(subId);
3553 if (phone != null) {
3554 return phone.getServiceState().getDataNetworkType();
3555 } else {
3556 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3557 }
3558 } finally {
3559 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003561 }
3562
3563 /**
3564 * Returns the data network type
3565 */
3566 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003567 public int getDataNetworkType(String callingPackage) {
3568 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003569 }
3570
3571 /**
3572 * Returns the data network type for a subId
3573 */
3574 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003575 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003577 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003578 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3579 }
3580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 final Phone phone = getPhone(subId);
3584 if (phone != null) {
3585 return phone.getServiceState().getDataNetworkType();
3586 } else {
3587 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3588 }
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003592 }
3593
3594 /**
Wink Saville36469e72014-06-11 15:17:00 -07003595 * Returns the Voice network type for a subId
3596 */
3597 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003598 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003600 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003601 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3602 }
3603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 final Phone phone = getPhone(subId);
3607 if (phone != null) {
3608 return phone.getServiceState().getVoiceNetworkType();
3609 } else {
3610 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3611 }
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003615 }
3616
3617 /**
3618 * @return true if a ICC card is present
3619 */
3620 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003621 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003622 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3623 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003624 }
3625
3626 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003627 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003628 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003629 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003630 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 final Phone phone = PhoneFactory.getPhone(slotIndex);
3634 if (phone != null) {
3635 return phone.getIccCard().hasIccCard();
3636 } else {
3637 return false;
3638 }
3639 } finally {
3640 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003642 }
3643
3644 /**
3645 * Return if the current radio is LTE on CDMA. This
3646 * is a tri-state return value as for a period of time
3647 * the mode may be unknown.
3648 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003649 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003650 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003651 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003652 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003653 @Override
3654 public int getLteOnCdmaMode(String callingPackage) {
3655 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003656 }
3657
Sanket Padawe356d7632015-06-22 14:03:32 -07003658 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003659 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003661 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003662 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3663 }
3664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 final Phone phone = getPhone(subId);
3668 if (phone == null) {
3669 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3670 } else {
3671 return phone.getLteOnCdmaMode();
3672 }
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003675 }
Wink Saville36469e72014-06-11 15:17:00 -07003676 }
3677
Wink Saville36469e72014-06-11 15:17:00 -07003678 /**
3679 * {@hide}
3680 * Returns Default subId, 0 in the case of single standby.
3681 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003682 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003683 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003684 }
3685
Shishir Agrawala9f32182016-04-12 12:00:16 -07003686 private int getSlotForDefaultSubscription() {
3687 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3688 }
3689
Wink Savilleb564aae2014-10-23 10:18:09 -07003690 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003691 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003692 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003693
Pengquan Menge92a50d2018-09-21 15:54:48 -07003694 private boolean isActiveSubscription(int subId) {
3695 return mSubscriptionController.isActiveSubId(subId);
3696 }
3697
Ihab Awadf2177b72013-11-25 13:33:23 -08003698 /**
3699 * @see android.telephony.TelephonyManager.WifiCallingChoices
3700 */
3701 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702 final long identity = Binder.clearCallingIdentity();
3703 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003704 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3706 getWhenToMakeWifiCallsDefaultPreference());
3707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003710 }
3711
3712 /**
3713 * @see android.telephony.TelephonyManager.WifiCallingChoices
3714 */
3715 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003719 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003724 }
3725
Sailesh Nepald1e68152013-12-12 19:08:02 -08003726 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003727 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003728 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003729 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003730
Jordan Liu4c733742019-02-28 12:03:40 -08003731 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3732 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3733 if (phoneId == -1) {
3734 throw new IllegalArgumentException("Given slot index: " + slotIndex
3735 + " does not correspond to an active phone");
3736 }
3737 return PhoneFactory.getPhone(phoneId);
3738 }
3739
Shishir Agrawal566b7612013-10-28 14:41:00 -07003740 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003741 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3742 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3744 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003746 if (DBG) {
3747 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3748 }
3749 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3750 p2);
3751 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003752
Jordan Liu4c733742019-02-28 12:03:40 -08003753
3754 @Override
3755 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3756 int slotIndex, String callingPackage, String aid, int p2) {
3757 enforceModifyPermission();
3758 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3759 if (DBG) {
3760 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3761 }
3762 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3763 callingPackage, aid, p2);
3764 }
3765
3766 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3767 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 if (TextUtils.equals(ISDR_AID, aid)) {
3771 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003772 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3773 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774 if (bestComponent == null
3775 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3776 loge("The calling package is not allowed to access ISD-R.");
3777 throw new SecurityException(
3778 "The calling package is not allowed to access ISD-R.");
3779 }
Derek Tan740e1672017-06-27 14:56:27 -07003780 }
Derek Tan740e1672017-06-27 14:56:27 -07003781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003783 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3784 null /* workSource */);
3785 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786 return response;
3787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003790 }
3791
3792 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003793 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3795 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003796 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3797 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3798 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003799
Jordan Liu4c733742019-02-28 12:03:40 -08003800 @Override
3801 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3802 enforceModifyPermission();
3803 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3804 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3805 channel);
3806 }
3807
3808 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 if (channel < 0) {
3812 return false;
3813 }
Jordan Liu4c733742019-02-28 12:03:40 -08003814 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3815 null /* workSource */);
3816 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 return success;
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003820 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003821 }
3822
3823 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003824 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003825 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3827 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003828 if (DBG) {
3829 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3830 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3831 + p3 + " data=" + data);
3832 }
3833 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3834 command, p1, p2, p3, data);
3835 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003836
Jordan Liu4c733742019-02-28 12:03:40 -08003837 @Override
3838 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3839 int command, int p1, int p2, int p3, String data) {
3840 enforceModifyPermission();
3841 if (DBG) {
3842 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3843 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3844 + p3 + " data=" + data);
3845 }
3846 return iccTransmitApduLogicalChannelWithPermission(
3847 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3848 data);
3849 }
3850
3851 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3852 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853 final long identity = Binder.clearCallingIdentity();
3854 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855 if (channel < 0) {
3856 return "";
3857 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003859 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003860 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3861 null /* workSource */);
3862 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864 // Append the returned status code to the end of the response payload.
3865 String s = Integer.toHexString(
3866 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3867 if (response.payload != null) {
3868 s = IccUtils.bytesToHexString(response.payload) + s;
3869 }
3870 return s;
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003873 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003874 }
Jake Hambye994d462014-02-03 13:10:13 -08003875
Evan Charltonc66da362014-05-16 14:06:40 -07003876 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003877 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3878 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3880 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003881 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003882 if (DBG) {
3883 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3884 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3885 }
3886 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3887 cla, command, p1, p2, p3, data);
3888 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003889
Jordan Liu4c733742019-02-28 12:03:40 -08003890 @Override
3891 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3892 int command, int p1, int p2, int p3, String data) {
3893 enforceModifyPermission();
3894 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3895 if (DBG) {
3896 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3897 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3898 + " data=" + data);
3899 }
3900
3901 return iccTransmitApduBasicChannelWithPermission(
3902 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3903 p2, p3, data);
3904 }
3905
3906 // open APDU basic channel assuming the caller has sufficient permissions
3907 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3908 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909 final long identity = Binder.clearCallingIdentity();
3910 try {
3911 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3912 && TextUtils.equals(ISDR_AID, data)) {
3913 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003914 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3915 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003916 if (bestComponent == null
3917 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3918 loge("The calling package is not allowed to select ISD-R.");
3919 throw new SecurityException(
3920 "The calling package is not allowed to select ISD-R.");
3921 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003922 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003924 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003925 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3926 null /* workSource */);
3927 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003929 // Append the returned status code to the end of the response payload.
3930 String s = Integer.toHexString(
3931 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3932 if (response.payload != null) {
3933 s = IccUtils.bytesToHexString(response.payload) + s;
3934 }
3935 return s;
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003938 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003939 }
3940
3941 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003942 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003943 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3945 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 if (DBG) {
3950 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3951 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3952 }
3953
3954 IccIoResult response =
3955 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3956 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3957 subId);
3958
3959 if (DBG) {
3960 log("Exchange SIM_IO [R]" + response);
3961 }
3962
3963 byte[] result = null;
3964 int length = 2;
3965 if (response.payload != null) {
3966 length = 2 + response.payload.length;
3967 result = new byte[length];
3968 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3969 } else {
3970 result = new byte[length];
3971 }
3972
3973 result[length - 1] = (byte) response.sw2;
3974 result[length - 2] = (byte) response.sw1;
3975 return result;
3976 } finally {
3977 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003978 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003979 }
3980
Nathan Haroldb3014052017-01-25 15:57:32 -08003981 /**
3982 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3983 * on a particular subscription
3984 */
sqianb6e41952018-03-12 14:54:01 -07003985 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3987 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3988 return null;
3989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990
3991 final long identity = Binder.clearCallingIdentity();
3992 try {
3993 if (appType != TelephonyManager.APPTYPE_USIM
3994 && appType != TelephonyManager.APPTYPE_SIM) {
3995 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3996 return null;
3997 }
3998 Object response = sendRequest(
3999 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4000 if (response instanceof String[]) {
4001 return (String[]) response;
4002 }
4003 // Response is an Exception of some kind,
4004 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004005 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004006 } finally {
4007 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004008 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004009 }
4010
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004011 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004012 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4014 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4019 if (response.payload == null) {
4020 return "";
4021 }
Evan Charltonc66da362014-05-16 14:06:40 -07004022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 // Append the returned status code to the end of the response payload.
4024 String s = Integer.toHexString(
4025 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4026 s = IccUtils.bytesToHexString(response.payload) + s;
4027 return s;
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
Evan Charltonc66da362014-05-16 14:06:40 -07004031 }
4032
Jake Hambye994d462014-02-03 13:10:13 -08004033 /**
4034 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4035 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4036 *
4037 * @param itemID the ID of the item to read
4038 * @return the NV item as a String, or null on error.
4039 */
4040 @Override
4041 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004042 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4044 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045
4046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004049 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4051 return value;
4052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
Jake Hambye994d462014-02-03 13:10:13 -08004055 }
4056
4057 /**
4058 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4059 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4060 *
4061 * @param itemID the ID of the item to read
4062 * @param itemValue the value to write, as a String
4063 * @return true on success; false on any failure
4064 */
4065 @Override
4066 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004067 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4069 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070
4071 final long identity = Binder.clearCallingIdentity();
4072 try {
4073 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4074 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004075 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004076 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4077 return success;
4078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
Jake Hambye994d462014-02-03 13:10:13 -08004081 }
4082
4083 /**
4084 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4085 * Used for device configuration by some CDMA operators.
4086 *
4087 * @param preferredRoamingList byte array containing the new PRL
4088 * @return true on success; false on any failure
4089 */
4090 @Override
4091 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4093 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094
4095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4098 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4099 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4100 return success;
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
Jake Hambye994d462014-02-03 13:10:13 -08004104 }
4105
4106 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004107 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004108 * Used for device configuration by some CDMA operators.
4109 *
chen xu6dac5ab2018-10-26 17:39:23 -07004110 * @param slotIndex - device slot.
4111 *
Jake Hambye994d462014-02-03 13:10:13 -08004112 * @return true on success; false on any failure
4113 */
4114 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004115 public boolean resetModemConfig(int slotIndex) {
4116 Phone phone = PhoneFactory.getPhone(slotIndex);
4117 if (phone != null) {
4118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4119 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120
chen xu6dac5ab2018-10-26 17:39:23 -07004121 final long identity = Binder.clearCallingIdentity();
4122 try {
4123 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4124 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4125 return success;
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129 }
chen xu6dac5ab2018-10-26 17:39:23 -07004130 return false;
4131 }
4132
4133 /**
4134 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4135 *
4136 * @param slotIndex - device slot.
4137 *
4138 * @return true on success; false on any failure
4139 */
4140 @Override
4141 public boolean rebootModem(int slotIndex) {
4142 Phone phone = PhoneFactory.getPhone(slotIndex);
4143 if (phone != null) {
4144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4145 mApp, phone.getSubId(), "rebootModem");
4146
4147 final long identity = Binder.clearCallingIdentity();
4148 try {
4149 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4150 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4151 return success;
4152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
4155 }
4156 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004157 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004158
Svet Ganovb320e182015-04-16 12:30:10 -07004159 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004160 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004162 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004163 return new String[0];
4164 }
4165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 final long identity = Binder.clearCallingIdentity();
4167 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004168 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
Wink Saville36469e72014-06-11 15:17:00 -07004172 }
4173
Brad Ebinger51f743a2017-01-23 13:50:20 -08004174 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004175 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4176 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004177 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004178 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004179 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180
4181 final long identity = Binder.clearCallingIdentity();
4182 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004183 ImsResolver resolver = PhoneFactory.getImsResolver();
4184 if (resolver == null) {
4185 // may happen if the device does not support IMS.
4186 return;
4187 }
4188 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004192 }
4193
4194 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004195 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4196 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004197 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004198 public void disableIms(int slotId) {
4199 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200
4201 final long identity = Binder.clearCallingIdentity();
4202 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004203 ImsResolver resolver = PhoneFactory.getImsResolver();
4204 if (resolver == null) {
4205 // may happen if the device does not support IMS.
4206 return;
4207 }
4208 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004212 }
4213
4214 /**
4215 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4216 * feature or {@link null} if the service is not available. If the feature is available, the
4217 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4218 */
4219 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004220 IImsServiceFeatureCallback callback) {
4221 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004222
4223 final long identity = Binder.clearCallingIdentity();
4224 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004225 ImsResolver resolver = PhoneFactory.getImsResolver();
4226 if (resolver == null) {
4227 // may happen if the device does not support IMS.
4228 return null;
4229 }
4230 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231 } finally {
4232 Binder.restoreCallingIdentity(identity);
4233 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004234 }
4235
4236 /**
4237 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4238 * feature during emergency calling or {@link null} if the service is not available. If the
4239 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4240 * listener for feature updates.
4241 */
4242 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4243 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004244
4245 final long identity = Binder.clearCallingIdentity();
4246 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004247 ImsResolver resolver = PhoneFactory.getImsResolver();
4248 if (resolver == null) {
4249 // may happen if the device does not support IMS.
4250 return null;
4251 }
4252 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004256 }
4257
Brad Ebinger5f64b052017-12-14 14:26:15 -08004258 /**
4259 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004260 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004261 */
4262 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4263 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264
4265 final long identity = Binder.clearCallingIdentity();
4266 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004267 ImsResolver resolver = PhoneFactory.getImsResolver();
4268 if (resolver == null) {
4269 // may happen if the device does not support IMS.
4270 return null;
4271 }
4272 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 } finally {
4274 Binder.restoreCallingIdentity(identity);
4275 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004276 }
4277
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004278 /**
4279 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004280 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004281 */
4282 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4283 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284
4285 final long identity = Binder.clearCallingIdentity();
4286 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004287 ImsResolver resolver = PhoneFactory.getImsResolver();
4288 if (resolver == null) {
4289 // may happen if the device does not support IMS.
4290 return null;
4291 }
4292 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004296 }
4297
Brad Ebinger884c07b2018-02-15 16:17:40 -08004298 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004299 * Sets the ImsService Package Name that Telephony will bind to.
4300 *
4301 * @param slotId the slot ID that the ImsService should bind for.
4302 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4303 * ImsService is the device default ImsService.
4304 * @param packageName The package name of the application that contains the ImsService to bind
4305 * to.
4306 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4307 * @hide
4308 */
4309 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004310 int[] subIds = SubscriptionManager.getSubId(slotId);
4311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4312 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4313 "setImsService");
4314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315 final long identity = Binder.clearCallingIdentity();
4316 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004317 ImsResolver resolver = PhoneFactory.getImsResolver();
4318 if (resolver == null) {
4319 // may happen if the device does not support IMS.
4320 return false;
4321 }
4322 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4323 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004327 }
4328
4329 /**
4330 * Return the ImsService configuration.
4331 *
4332 * @param slotId The slot that the ImsService is associated with.
4333 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4334 * the device default.
4335 * @return the package name of the ImsService configuration.
4336 */
4337 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004338 int[] subIds = SubscriptionManager.getSubId(slotId);
4339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4340 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4341 "getImsService");
4342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 final long identity = Binder.clearCallingIdentity();
4344 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004345 ImsResolver resolver = PhoneFactory.getImsResolver();
4346 if (resolver == null) {
4347 // may happen if the device does not support IMS.
4348 return "";
4349 }
4350 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351 } finally {
4352 Binder.restoreCallingIdentity(identity);
4353 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004354 }
4355
Wink Saville36469e72014-06-11 15:17:00 -07004356 public void setImsRegistrationState(boolean registered) {
4357 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358
4359 final long identity = Binder.clearCallingIdentity();
4360 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004361 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004362 } finally {
4363 Binder.restoreCallingIdentity(identity);
4364 }
Wink Saville36469e72014-06-11 15:17:00 -07004365 }
4366
4367 /**
Stuart Scott54788802015-03-30 13:18:01 -07004368 * Set the network selection mode to automatic.
4369 *
4370 */
4371 @Override
4372 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4374 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375
Pengquan Menge92a50d2018-09-21 15:54:48 -07004376 if (!isActiveSubscription(subId)) {
4377 return;
4378 }
4379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 final long identity = Binder.clearCallingIdentity();
4381 try {
4382 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4383 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4384 } finally {
4385 Binder.restoreCallingIdentity(identity);
4386 }
Stuart Scott54788802015-03-30 13:18:01 -07004387 }
4388
Pengquan Mengea84e042018-09-20 14:57:26 -07004389 /**
4390 * Ask the radio to connect to the input network and change selection mode to manual.
4391 *
4392 * @param subId the id of the subscription.
4393 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4394 * the operator to attach to.
4395 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4396 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4397 * normal network selection next time.
4398 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004399 */
4400 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004401 public boolean setNetworkSelectionModeManual(
4402 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4404 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004405
4406 if (!isActiveSubscription(subId)) {
4407 return false;
4408 }
4409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 final long identity = Binder.clearCallingIdentity();
4411 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004412 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004414 if (DBG) {
4415 log("setNetworkSelectionModeManual: subId: " + subId
4416 + " operator: " + operatorInfo);
4417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004422 }
4423
4424 /**
4425 * Scans for available networks.
4426 */
4427 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004428 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4430 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004431 LocationAccessPolicy.LocationPermissionResult locationResult =
4432 LocationAccessPolicy.checkLocationPermission(mApp,
4433 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4434 .setCallingPackage(callingPackage)
4435 .setCallingPid(Binder.getCallingPid())
4436 .setCallingUid(Binder.getCallingUid())
4437 .setMethod("getCellNetworkScanResults")
4438 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4439 .build());
4440 switch (locationResult) {
4441 case DENIED_HARD:
4442 throw new SecurityException("Not allowed to access scan results -- location");
4443 case DENIED_SOFT:
4444 return null;
4445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446
Pengquan Menga1bb6272018-09-06 09:59:22 -07004447 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 try {
4449 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004450 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004451 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004455 }
4456
4457 /**
yinxub1bed742017-04-17 11:45:04 -07004458 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004459 *
yinxub1bed742017-04-17 11:45:04 -07004460 * @param subId id of the subscription
4461 * @param request contains the radio access networks with bands/channels to scan
4462 * @param messenger callback messenger for scan results or errors
4463 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004464 * @return the id of the requested scan which can be used to stop the scan.
4465 */
4466 @Override
4467 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004468 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4470 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004471 LocationAccessPolicy.LocationPermissionResult locationResult =
4472 LocationAccessPolicy.checkLocationPermission(mApp,
4473 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4474 .setCallingPackage(callingPackage)
4475 .setCallingPid(Binder.getCallingPid())
4476 .setCallingUid(Binder.getCallingUid())
4477 .setMethod("requestNetworkScan")
4478 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4479 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004480 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4481 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4482 if (e != null) {
4483 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4484 throw e;
4485 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004486 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004487 return TelephonyScanManager.INVALID_SCAN_ID;
4488 }
4489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 }
Hall Liu912dfd32019-04-25 14:02:26 -07004491 int callingUid = Binder.getCallingUid();
4492 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004493 final long identity = Binder.clearCallingIdentity();
4494 try {
4495 return mNetworkScanRequestTracker.startNetworkScan(
4496 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004497 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
yinxu504e1392017-04-12 16:03:22 -07004501 }
4502
Hall Liub2ac8ef2019-02-28 15:56:23 -08004503 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4504 NetworkScanRequest request) {
4505 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4506 != PERMISSION_GRANTED) {
4507 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4508 + " without location access.");
4509 }
4510
4511 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4512 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004513 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4514 return new SecurityException("Specific channels must not be"
4515 + " scanned without location access.");
4516 }
4517 }
4518 }
4519
Hall Liub2ac8ef2019-02-28 15:56:23 -08004520 return null;
4521 }
4522
yinxu504e1392017-04-12 16:03:22 -07004523 /**
4524 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004525 *
4526 * @param subId id of the subscription
4527 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004528 */
4529 @Override
4530 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4532 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533
Hall Liu912dfd32019-04-25 14:02:26 -07004534 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 final long identity = Binder.clearCallingIdentity();
4536 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004537 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
yinxu504e1392017-04-12 16:03:22 -07004541 }
4542
4543 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004544 * Get the calculated preferred network type.
4545 * Used for debugging incorrect network type.
4546 *
4547 * @return the preferred network type, defined in RILConstants.java.
4548 */
4549 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004550 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004551 final Phone defaultPhone = getDefaultPhone();
4552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4553 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004554 return RILConstants.PREFERRED_NETWORK_MODE;
4555 }
4556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 final long identity = Binder.clearCallingIdentity();
4558 try {
4559 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004560 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
Junda Liu84d15a22014-07-02 11:21:04 -07004564 }
4565
4566 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004567 * Get the preferred network type.
4568 * Used for device configuration by some CDMA operators.
4569 *
4570 * @return the preferred network type, defined in RILConstants.java.
4571 */
4572 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004573 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004574 TelephonyPermissions
4575 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4576 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577
4578 final long identity = Binder.clearCallingIdentity();
4579 try {
4580 if (DBG) log("getPreferredNetworkType");
4581 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4582 int networkType = (result != null ? result[0] : -1);
4583 if (DBG) log("getPreferredNetworkType: " + networkType);
4584 return networkType;
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
4587 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004588 }
4589
4590 /**
4591 * Set the preferred network type.
4592 * Used for device configuration by some CDMA operators.
4593 *
4594 * @param networkType the preferred network type, defined in RILConstants.java.
4595 * @return true on success; false on any failure.
4596 */
4597 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004598 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4600 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601
4602 final long identity = Binder.clearCallingIdentity();
4603 try {
4604 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4605 Boolean success = (Boolean) sendRequest(
4606 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4607 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4608 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004609 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4611 }
4612 return success;
4613 } finally {
4614 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004615 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004616 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004617
4618 /**
Miaoa84611c2019-03-15 09:21:10 +08004619 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004620 *
Miaoa84611c2019-03-15 09:21:10 +08004621 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004622 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004623 * @hide
4624 */
4625 @Override
Miaoa84611c2019-03-15 09:21:10 +08004626 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004627 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004629 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630 try {
Miaoa84611c2019-03-15 09:21:10 +08004631 if (phone != null) {
4632 return phone.hasMatchedTetherApnSetting();
4633 } else {
4634 return false;
4635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636 } finally {
4637 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004638 }
Junda Liu475951f2014-11-07 16:45:03 -08004639 }
4640
4641 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004642 * Set mobile data enabled
4643 * Used by the user through settings etc to turn on/off mobile data
4644 *
4645 * @param enable {@code true} turn turn data on, else {@code false}
4646 */
4647 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004648 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4650 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651
4652 final long identity = Binder.clearCallingIdentity();
4653 try {
4654 int phoneId = mSubscriptionController.getPhoneId(subId);
4655 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4656 Phone phone = PhoneFactory.getPhone(phoneId);
4657 if (phone != null) {
4658 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004659 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004661 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 }
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004665 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004666 }
4667
4668 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004669 * Get the user enabled state of Mobile Data.
4670 *
4671 * TODO: remove and use isUserDataEnabled.
4672 * This can't be removed now because some vendor codes
4673 * calls through ITelephony directly while they should
4674 * use TelephonyManager.
4675 *
4676 * @return true on enabled
4677 */
4678 @Override
4679 public boolean getDataEnabled(int subId) {
4680 return isUserDataEnabled(subId);
4681 }
4682
4683 /**
4684 * Get whether mobile data is enabled per user setting.
4685 *
4686 * There are other factors deciding whether mobile data is actually enabled, but they are
4687 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004688 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004689 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004690 *
4691 * @return {@code true} if data is enabled else {@code false}
4692 */
4693 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004694 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004695 try {
4696 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4697 null);
4698 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4700 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702
4703 final long identity = Binder.clearCallingIdentity();
4704 try {
4705 int phoneId = mSubscriptionController.getPhoneId(subId);
4706 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4707 Phone phone = PhoneFactory.getPhone(phoneId);
4708 if (phone != null) {
4709 boolean retVal = phone.isUserDataEnabled();
4710 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4711 return retVal;
4712 } else {
4713 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4714 return false;
4715 }
4716 } finally {
4717 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004718 }
4719 }
4720
4721 /**
4722 * Get whether mobile data is enabled.
4723 *
4724 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4725 * whether mobile data is actually enabled.
4726 *
4727 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4728 *
4729 * @return {@code true} if data is enabled else {@code false}
4730 */
4731 @Override
4732 public boolean isDataEnabled(int subId) {
4733 try {
4734 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4735 null);
4736 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4738 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740
4741 final long identity = Binder.clearCallingIdentity();
4742 try {
4743 int phoneId = mSubscriptionController.getPhoneId(subId);
4744 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4745 Phone phone = PhoneFactory.getPhone(phoneId);
4746 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004747 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004748 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4749 return retVal;
4750 } else {
4751 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4752 return false;
4753 }
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004756 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004757 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004758
4759 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004760 public int getCarrierPrivilegeStatus(int subId) {
4761 final Phone phone = getPhone(subId);
4762 if (phone == null) {
4763 loge("getCarrierPrivilegeStatus: Invalid subId");
4764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4765 }
4766 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004767 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004768 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004769 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4770 }
4771 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004772 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004773 }
Junda Liu29340342014-07-10 15:23:27 -07004774
4775 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004776 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4777 final Phone phone = getPhone(subId);
4778 if (phone == null) {
4779 loge("getCarrierPrivilegeStatus: Invalid subId");
4780 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4781 }
4782 UiccProfile profile =
4783 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4784 if (profile == null) {
4785 loge("getCarrierPrivilegeStatus: No UICC");
4786 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4787 }
4788 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4789 }
4790
4791 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004792 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004793 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004794 if (TextUtils.isEmpty(pkgName))
4795 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004796 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004797 if (card == null) {
4798 loge("checkCarrierPrivilegesForPackage: No UICC");
4799 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4800 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004801 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4802 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004803 }
4804
4805 @Override
4806 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004807 if (TextUtils.isEmpty(pkgName))
4808 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004809 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4810 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4811 UiccCard card = UiccController.getInstance().getUiccCard(i);
4812 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004813 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004814 continue;
4815 }
4816
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004817 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004818 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4819 break;
4820 }
4821 }
4822
4823 return result;
Junda Liu29340342014-07-10 15:23:27 -07004824 }
Derek Tan89e89d42014-07-08 17:00:10 -07004825
4826 @Override
Junda Liue64de782015-04-16 17:19:16 -07004827 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4828 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4829 loge("phoneId " + phoneId + " is not valid.");
4830 return null;
4831 }
4832 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004833 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004834 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004835 return null ;
4836 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004837 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004838 }
4839
Amith Yamasani6e118872016-02-19 12:53:51 -08004840 @Override
4841 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004842 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004843 List<String> privilegedPackages = new ArrayList<>();
4844 List<PackageInfo> packages = null;
4845 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4846 UiccCard card = UiccController.getInstance().getUiccCard(i);
4847 if (card == null) {
4848 // No UICC in that slot.
4849 continue;
4850 }
4851 if (card.hasCarrierPrivilegeRules()) {
4852 if (packages == null) {
4853 // Only check packages in user 0 for now
4854 packages = pm.getInstalledPackagesAsUser(
4855 PackageManager.MATCH_DISABLED_COMPONENTS
4856 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4857 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4858 }
4859 for (int p = packages.size() - 1; p >= 0; p--) {
4860 PackageInfo pkgInfo = packages.get(p);
4861 if (pkgInfo != null && pkgInfo.packageName != null
4862 && card.getCarrierPrivilegeStatus(pkgInfo)
4863 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4864 privilegedPackages.add(pkgInfo.packageName);
4865 }
4866 }
4867 }
4868 }
4869 return privilegedPackages;
4870 }
4871
Wink Savilleb564aae2014-10-23 10:18:09 -07004872 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004873 final Phone phone = getPhone(subId);
4874 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004875 if (card == null) {
4876 loge("getIccId: No UICC");
4877 return null;
4878 }
4879 String iccId = card.getIccId();
4880 if (TextUtils.isEmpty(iccId)) {
4881 loge("getIccId: ICC ID is null or empty.");
4882 return null;
4883 }
4884 return iccId;
4885 }
4886
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004887 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004888 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4889 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004890 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4891 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893 final long identity = Binder.clearCallingIdentity();
4894 try {
4895 final String iccId = getIccId(subId);
4896 final Phone phone = getPhone(subId);
4897 if (phone == null) {
4898 return false;
4899 }
4900 final String subscriberId = phone.getSubscriberId();
4901
4902 if (DBG_MERGE) {
4903 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4904 + subscriberId + " to " + number);
4905 }
4906
4907 if (TextUtils.isEmpty(iccId)) {
4908 return false;
4909 }
4910
4911 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4912
4913 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4914 if (alphaTag == null) {
4915 editor.remove(alphaTagPrefKey);
4916 } else {
4917 editor.putString(alphaTagPrefKey, alphaTag);
4918 }
4919
4920 // Record both the line number and IMSI for this ICCID, since we need to
4921 // track all merged IMSIs based on line number
4922 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4923 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4924 if (number == null) {
4925 editor.remove(numberPrefKey);
4926 editor.remove(subscriberPrefKey);
4927 } else {
4928 editor.putString(numberPrefKey, number);
4929 editor.putString(subscriberPrefKey, subscriberId);
4930 }
4931
4932 editor.commit();
4933 return true;
4934 } finally {
4935 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004936 }
Derek Tan7226c842014-07-02 17:42:23 -07004937 }
4938
4939 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004940 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004941 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004943 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004944 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004945 return null;
4946 }
Derek Tan97ebb422014-09-05 16:55:38 -07004947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 final long identity = Binder.clearCallingIdentity();
4949 try {
4950 String iccId = getIccId(subId);
4951 if (iccId != null) {
4952 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4953 if (DBG_MERGE) {
4954 log("getLine1NumberForDisplay returning "
4955 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4956 }
4957 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4960 return null;
4961 } finally {
4962 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004963 }
Derek Tan7226c842014-07-02 17:42:23 -07004964 }
4965
4966 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004967 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004968 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004969 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004970 return null;
4971 }
Derek Tan97ebb422014-09-05 16:55:38 -07004972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 final long identity = Binder.clearCallingIdentity();
4974 try {
4975 String iccId = getIccId(subId);
4976 if (iccId != null) {
4977 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4978 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4979 }
4980 return null;
4981 } finally {
4982 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004983 }
Derek Tan7226c842014-07-02 17:42:23 -07004984 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004985
4986 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004987 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004988 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4989 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004991 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4992 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004993 return null;
4994 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004995
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004996 final long identity = Binder.clearCallingIdentity();
4997 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004998 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 final TelephonyManager tele = TelephonyManager.from(context);
5000 final SubscriptionManager sub = SubscriptionManager.from(context);
5001
5002 // Figure out what subscribers are currently active
5003 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
5004 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5005 // the process, where TelephonyManager was instantiated.
5006 // Otherwise AppOps check will fail.
5007
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005008 final int[] subIds = sub.getActiveSubscriptionIdList();
5009 for (int subId : subIds) {
5010 activeSubscriberIds.add(tele.getSubscriberId(subId));
5011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012
5013 // First pass, find a number override for an active subscriber
5014 String mergeNumber = null;
5015 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5016 for (String key : prefs.keySet()) {
5017 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5018 final String subscriberId = (String) prefs.get(key);
5019 if (activeSubscriberIds.contains(subscriberId)) {
5020 final String iccId = key.substring(
5021 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5022 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5023 mergeNumber = (String) prefs.get(numberKey);
5024 if (DBG_MERGE) {
5025 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5026 + " for active subscriber " + subscriberId);
5027 }
5028 if (!TextUtils.isEmpty(mergeNumber)) {
5029 break;
5030 }
5031 }
5032 }
5033 }
5034
5035 // Shortcut when no active merged subscribers
5036 if (TextUtils.isEmpty(mergeNumber)) {
5037 return null;
5038 }
5039
5040 // Second pass, find all subscribers under that line override
5041 final ArraySet<String> result = new ArraySet<>();
5042 for (String key : prefs.keySet()) {
5043 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5044 final String number = (String) prefs.get(key);
5045 if (mergeNumber.equals(number)) {
5046 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5047 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5048 final String subscriberId = (String) prefs.get(subscriberKey);
5049 if (!TextUtils.isEmpty(subscriberId)) {
5050 result.add(subscriberId);
5051 }
5052 }
5053 }
5054 }
5055
5056 final String[] resultArray = result.toArray(new String[result.size()]);
5057 Arrays.sort(resultArray);
5058 if (DBG_MERGE) {
5059 Slog.d(LOG_TAG,
5060 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5061 }
5062 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005063 } finally {
5064 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005065 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005066 }
5067
5068 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005069 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005070 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5071 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005072
5073 final long identity = Binder.clearCallingIdentity();
5074 try {
5075 final Phone phone = getPhone(subId);
5076 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
5079 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005080 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005081
5082 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005083 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005084 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5085 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005086 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087
5088 final long identity = Binder.clearCallingIdentity();
5089 try {
5090 final Phone phone = getPhone(subId);
5091 if (phone == null) {
5092 return false;
5093 }
5094 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5095 cdmaNonRoamingList);
5096 } finally {
5097 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005098 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005099 }
5100
5101 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005102 @Deprecated
5103 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5104 enforceModifyPermission();
5105
5106 int returnValue = 0;
5107 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005108 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005109 if(result.exception == null) {
5110 if (result.result != null) {
5111 byte[] responseData = (byte[])(result.result);
5112 if(responseData.length > oemResp.length) {
5113 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5114 responseData.length + "bytes. Buffer Size is " +
5115 oemResp.length + "bytes.");
5116 }
5117 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5118 returnValue = responseData.length;
5119 }
5120 } else {
5121 CommandException ex = (CommandException) result.exception;
5122 returnValue = ex.getCommandError().ordinal();
5123 if(returnValue > 0) returnValue *= -1;
5124 }
5125 } catch (RuntimeException e) {
5126 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5127 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5128 if(returnValue > 0) returnValue *= -1;
5129 }
5130
5131 return returnValue;
5132 }
5133
5134 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005135 public void setRadioCapability(RadioAccessFamily[] rafs) {
5136 try {
5137 ProxyController.getInstance().setRadioCapability(rafs);
5138 } catch (RuntimeException e) {
5139 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5140 }
5141 }
5142
5143 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005144 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005145 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005146 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005147 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005148 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005149 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 final long identity = Binder.clearCallingIdentity();
5151 try {
chen xub97461a2018-10-26 14:17:57 -07005152 TelephonyPermissions
5153 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5154 mApp, phone.getSubId(), "getRadioAccessFamily");
5155 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 } finally {
5157 Binder.restoreCallingIdentity(identity);
5158 }
chen xub97461a2018-10-26 14:17:57 -07005159 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005160 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005161
5162 @Override
5163 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005164 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005165 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166
5167 final long identity = Binder.clearCallingIdentity();
5168 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005169 ImsManager.getInstance(defaultPhone.getContext(),
5170 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 } finally {
5172 Binder.restoreCallingIdentity(identity);
5173 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005174 }
5175
5176 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005177 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005178 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005180 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005181 return false;
5182 }
Svet Ganovb320e182015-04-16 12:30:10 -07005183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 // Check the user preference and the system-level IMS setting. Even if the user has
5187 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5188 // In the long run, we may instead need to check if there exists a connection service
5189 // which can support video calling.
5190 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005191 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 return imsManager.isVtEnabledByPlatform()
5193 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5194 && imsManager.isVtEnabledByUser();
5195 } finally {
5196 Binder.restoreCallingIdentity(identity);
5197 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005198 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005199
Andrew Leea1239f22015-03-02 17:44:07 -08005200 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5203 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5204 return false;
5205 }
5206
5207 final long identity = Binder.clearCallingIdentity();
5208 try {
5209 CarrierConfigManager configManager =
5210 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005211 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
Andrew Leea1239f22015-03-02 17:44:07 -08005216 }
5217
5218 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 public boolean isWorldPhone(int subId, String callingPackage) {
5220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5221 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5222 return false;
5223 }
5224
5225 final long identity = Binder.clearCallingIdentity();
5226 try {
5227 CarrierConfigManager configManager =
5228 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005229 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
Andrew Leea1239f22015-03-02 17:44:07 -08005234 }
5235
Andrew Lee9431b832015-03-09 18:46:45 -07005236 @Override
5237 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005238 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005239 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005240 }
5241
5242 @Override
5243 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 final long identity = Binder.clearCallingIdentity();
5245 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005246 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
Andrew Lee9431b832015-03-09 18:46:45 -07005250 }
5251
Hall Liuf6668912018-10-31 17:05:23 -07005252 /**
5253 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5254 * support for the feature and device firmware support.
5255 *
5256 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5257 */
5258 @Override
5259 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005261 final Phone phone = getPhone(subscriptionId);
5262 if (phone == null) {
5263 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5264 return false;
5265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005267 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5269 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005270 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 return isCarrierSupported && isDeviceSupported;
5272 } finally {
5273 Binder.restoreCallingIdentity(identity);
5274 }
Hall Liu98187582018-01-22 19:15:32 -08005275 }
5276
Hall Liuf6668912018-10-31 17:05:23 -07005277 /**
5278 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5279 * both also support RTT.
5280 */
5281 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 final long identity = Binder.clearCallingIdentity();
5283 try {
Hall Liuf6668912018-10-31 17:05:23 -07005284 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005285 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005289 }
5290
Sanket Padawe7310cc72015-01-14 09:53:20 -08005291 /**
5292 * Returns the unique device ID of phone, for example, the IMEI for
5293 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5294 *
5295 * <p>Requires Permission:
5296 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5297 */
5298 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005299 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005300 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005301 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005302 return null;
5303 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005304 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005305 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5306 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005307 return null;
5308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309
5310 final long identity = Binder.clearCallingIdentity();
5311 try {
5312 return phone.getDeviceId();
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005316 }
5317
Ping Sunc67b7c22016-03-02 19:16:45 +08005318 /**
5319 * {@hide}
5320 * Returns the IMS Registration Status on a particular subid
5321 *
5322 * @param subId
5323 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005324 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005325 Phone phone = getPhone(subId);
5326 if (phone != null) {
5327 return phone.isImsRegistered();
5328 } else {
5329 return false;
5330 }
5331 }
5332
Santos Cordon7a1885b2015-02-03 11:15:19 -08005333 @Override
5334 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 final long identity = Binder.clearCallingIdentity();
5336 try {
5337 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005341 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005342
Tyler Gunnf70ed162019-04-03 15:28:53 -07005343 @Override
5344 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5345 final long identity = Binder.clearCallingIdentity();
5346 try {
5347 Phone phone = getPhone(subscriptionId);
5348 if (phone == null) {
5349 return null;
5350 }
5351 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
5355 }
5356
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005357 /**
5358 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005359 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005360 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 final long identity = Binder.clearCallingIdentity();
5362 try {
5363 Phone phone = getPhone(subId);
5364 if (phone != null) {
5365 return phone.isWifiCallingEnabled();
5366 } else {
5367 return false;
5368 }
5369 } finally {
5370 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005371 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005372 }
5373
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005374 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005375 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005376 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005377 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 final long identity = Binder.clearCallingIdentity();
5379 try {
5380 Phone phone = getPhone(subId);
5381 if (phone != null) {
5382 return phone.isVideoEnabled();
5383 } else {
5384 return false;
5385 }
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005388 }
5389 }
5390
5391 /**
5392 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5393 * defined in {@link ImsRegistrationImplBase}.
5394 */
5395 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 final long identity = Binder.clearCallingIdentity();
5397 try {
5398 Phone phone = getPhone(subId);
5399 if (phone != null) {
5400 return phone.getImsRegistrationTech();
5401 } else {
5402 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5403 }
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005406 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005407 }
5408
Stuart Scott8eef64f2015-04-08 15:13:54 -07005409 @Override
5410 public void factoryReset(int subId) {
5411 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005412 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5413 return;
5414 }
5415
Svet Ganovcc087f82015-05-12 20:35:54 -07005416 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005417
Svet Ganovcc087f82015-05-12 20:35:54 -07005418 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005419 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5420 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005421 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005422 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005423 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005424 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5425 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005426 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005427 // There has been issues when Sms raw table somehow stores orphan
5428 // fragments. They lead to garbled message when new fragments come
5429 // in and combined with those stale ones. In case this happens again,
5430 // user can reset all network settings which will clean up this table.
5431 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005432 } finally {
5433 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005434 }
5435 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005436
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005437 private void cleanUpSmsRawTable(Context context) {
5438 ContentResolver resolver = context.getContentResolver();
5439 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5440 resolver.delete(uri, null, null);
5441 }
5442
Narayan Kamath1c496c22015-04-16 14:40:19 +01005443 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005444 public String getSimLocaleForSubscriber(int subId) {
5445 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5446 final Phone phone = getPhone(subId);
5447 if (phone == null) {
5448 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005449 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451 final long identity = Binder.clearCallingIdentity();
5452 try {
chen xu5d3637b2019-01-21 23:31:38 -08005453 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5454 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005455 if (info == null) {
5456 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5457 return null;
5458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 // Try and fetch the locale from the carrier properties or from the SIM language
5460 // preferences (EF-PL and EF-LI)...
5461 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005463 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5464 if (localeFromDefaultSim != null) {
5465 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5466 if (DBG) log("Using locale from subId: " + subId + " locale: "
5467 + localeFromDefaultSim);
5468 return localeFromDefaultSim.toLanguageTag();
5469 } else {
5470 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 }
5472 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 // The SIM language preferences only store a language (e.g. fr = French), not an
5475 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5476 // the SIM and carrier preferences does not include a country we add the country
5477 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005478 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005480 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 return mccLocale.toLanguageTag();
5482 }
5483
5484 if (DBG) log("No locale found - returning null");
5485 return null;
5486 } finally {
5487 Binder.restoreCallingIdentity(identity);
5488 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005489 }
5490
5491 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005492 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005493 }
5494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 /**
5496 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5497 */
5498 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005499 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005500 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005501
Chenjie Yu1ba97252018-01-11 18:16:20 -08005502 private final ModemActivityInfo mLastModemActivityInfo =
5503 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5504
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005505 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005506 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5507 * representing the state of the modem.
5508 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005509 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5510 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005511 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005512 */
5513 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005514 public void requestModemActivityInfo(ResultReceiver result) {
5515 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005516 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517
5518 final long identity = Binder.clearCallingIdentity();
5519 try {
5520 ModemActivityInfo ret = null;
5521 synchronized (mLastModemActivityInfo) {
5522 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5523 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005524 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005525 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5527 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005528 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5529 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 }
5531 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005532 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5533 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 mLastModemActivityInfo.setIdleTimeMillis(
5535 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5536 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5537 mLastModemActivityInfo.setRxTimeMillis(
5538 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5539 mLastModemActivityInfo.setEnergyUsed(
5540 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5543 mLastModemActivityInfo.getSleepTimeMillis(),
5544 mLastModemActivityInfo.getIdleTimeMillis(),
5545 mLastModemActivityInfo.getTxTimeMillis(),
5546 mLastModemActivityInfo.getRxTimeMillis(),
5547 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 Bundle bundle = new Bundle();
5550 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5551 result.send(0, bundle);
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005554 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005555 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005556
Siddharth Rayb8114062018-06-17 15:02:38 -07005557 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5558 // less than total activity duration.
5559 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5560 if (info == null) {
5561 return false;
5562 }
5563 int activityDurationMs =
5564 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5565 int totalTxTimeMs = 0;
5566 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5567 totalTxTimeMs += info.getTxTimeMillis()[i];
5568 }
5569 return (info.isValid()
5570 && (info.getSleepTimeMillis() <= activityDurationMs)
5571 && (info.getIdleTimeMillis() <= activityDurationMs)
5572 && (info.getRxTimeMillis() <= activityDurationMs)
5573 && (totalTxTimeMs <= activityDurationMs));
5574 }
5575
Jack Yu85bd38a2015-11-09 11:34:32 -08005576 /**
5577 * {@hide}
5578 * Returns the service state information on specified subscription.
5579 */
5580 @Override
5581 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005583 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005584 return null;
5585 }
5586
Hall Liuf19c44f2018-11-27 14:38:17 -08005587 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5588 LocationAccessPolicy.checkLocationPermission(mApp,
5589 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5590 .setCallingPackage(callingPackage)
5591 .setCallingPid(Binder.getCallingPid())
5592 .setCallingUid(Binder.getCallingUid())
5593 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005594 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005595 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5596 .build());
5597
5598 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5599 LocationAccessPolicy.checkLocationPermission(mApp,
5600 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5601 .setCallingPackage(callingPackage)
5602 .setCallingPid(Binder.getCallingPid())
5603 .setCallingUid(Binder.getCallingUid())
5604 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005605 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005606 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5607 .build());
5608 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5609 boolean hasFinePermission =
5610 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5611 boolean hasCoarsePermission =
5612 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 final long identity = Binder.clearCallingIdentity();
5615 try {
5616 final Phone phone = getPhone(subId);
5617 if (phone == null) {
5618 return null;
5619 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005620
Hall Liuf19c44f2018-11-27 14:38:17 -08005621 ServiceState ss = phone.getServiceState();
5622
5623 // Scrub out the location info in ServiceState depending on what level of access
5624 // the caller has.
5625 if (hasFinePermission) return ss;
5626 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5627 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 } finally {
5629 Binder.restoreCallingIdentity(identity);
5630 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005631 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005632
5633 /**
5634 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5635 *
5636 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5637 * voicemail ringtone.
5638 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5639 * PhoneAccount.
5640 */
5641 @Override
5642 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5646 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005647 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5651 } finally {
5652 Binder.restoreCallingIdentity(identity);
5653 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005654 }
5655
5656 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005657 * Sets the per-account voicemail ringtone.
5658 *
5659 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5660 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5661 *
5662 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5663 * voicemail ringtone.
5664 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5665 * PhoneAccount.
5666 */
5667 @Override
5668 public void setVoicemailRingtoneUri(String callingPackage,
5669 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005670 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005671 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5672 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005673 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5675 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5676 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005677 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678
5679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5682 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005683 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 }
5685 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5686 } finally {
5687 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005688 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005689 }
5690
5691 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005692 * Returns whether vibration is set for voicemail notification in Phone settings.
5693 *
5694 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5695 * voicemail vibration setting.
5696 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5697 */
5698 @Override
5699 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 final long identity = Binder.clearCallingIdentity();
5701 try {
5702 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5703 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005704 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005711 }
5712
Youhan Wange64578a2016-05-02 15:32:42 -07005713 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005714 * Sets the per-account voicemail vibration.
5715 *
5716 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5717 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5718 *
5719 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5720 * voicemail vibration setting.
5721 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5722 * specific PhoneAccount.
5723 */
5724 @Override
5725 public void setVoicemailVibrationEnabled(String callingPackage,
5726 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005727 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5729 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005730 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5732 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5733 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005734 }
5735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5739 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005740 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 }
5742 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5743 } finally {
5744 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005745 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005746 }
5747
5748 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005749 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5750 *
5751 * @throws SecurityException if the caller does not have the required permission
5752 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005753 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005754 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005755 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005756 }
5757
5758 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005759 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5760 * permission.
5761 *
5762 * @throws SecurityException if the caller does not have the required permission
5763 */
5764 private void enforceSendSmsPermission() {
5765 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5766 }
5767
5768 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005769 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005770 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005771 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005772 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005773 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 final long identity = Binder.clearCallingIdentity();
5775 try {
5776 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005777 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 if (componentName == null) {
5779 throw new SecurityException(
5780 "Caller not current active visual voicemail package[null]");
5781 }
5782 String vvmPackage = componentName.getPackageName();
5783 if (!callingPackage.equals(vvmPackage)) {
5784 throw new SecurityException("Caller not current active visual voicemail package["
5785 + vvmPackage + "]");
5786 }
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005789 }
5790 }
5791
5792 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005793 * Return the application ID for the app type.
5794 *
5795 * @param subId the subscription ID that this request applies to.
5796 * @param appType the uicc app type.
5797 * @return Application ID for specificied app type, or null if no uicc.
5798 */
5799 @Override
5800 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005801 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005802 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803
5804 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005805 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 if (phone == null) {
5807 return null;
5808 }
5809 String aid = null;
5810 try {
5811 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5812 .getApplicationByType(appType).getAid();
5813 } catch (Exception e) {
5814 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5815 }
5816 return aid;
5817 } finally {
5818 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005819 }
Youhan Wange64578a2016-05-02 15:32:42 -07005820 }
5821
Youhan Wang4001d252016-05-11 10:29:41 -07005822 /**
5823 * Return the Electronic Serial Number.
5824 *
5825 * @param subId the subscription ID that this request applies to.
5826 * @return ESN or null if error.
5827 */
5828 @Override
5829 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005830 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005831 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832
5833 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005834 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 if (phone == null) {
5836 return null;
5837 }
5838 String esn = null;
5839 try {
5840 esn = phone.getEsn();
5841 } catch (Exception e) {
5842 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5843 }
5844 return esn;
5845 } finally {
5846 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005847 }
Youhan Wang4001d252016-05-11 10:29:41 -07005848 }
5849
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005850 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005851 * Return the Preferred Roaming List Version.
5852 *
5853 * @param subId the subscription ID that this request applies to.
5854 * @return PRLVersion or null if error.
5855 */
5856 @Override
5857 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005858 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005859 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860
5861 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005862 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 if (phone == null) {
5864 return null;
5865 }
5866 String cdmaPrlVersion = null;
5867 try {
5868 cdmaPrlVersion = phone.getCdmaPrlVersion();
5869 } catch (Exception e) {
5870 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5871 }
5872 return cdmaPrlVersion;
5873 } finally {
5874 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005875 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005876 }
5877
5878 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005879 * Get snapshot of Telephony histograms
5880 * @return List of Telephony histograms
5881 * @hide
5882 */
5883 @Override
5884 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5886 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887
5888 final long identity = Binder.clearCallingIdentity();
5889 try {
5890 return RIL.getTelephonyRILTimingHistograms();
5891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005894 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005895
5896 /**
5897 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005898 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5899 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005900 * Require system privileges. In the future we may add this to carrier APIs.
5901 *
Michele Berionne482f8202018-11-27 18:57:59 -08005902 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005903 */
5904 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005905 @TelephonyManager.SetCarrierRestrictionResult
5906 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005907 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005908 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005909
Michele Berionne482f8202018-11-27 18:57:59 -08005910 if (carrierRestrictionRules == null) {
5911 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005912 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 final long identity = Binder.clearCallingIdentity();
5915 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005916 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005917 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 } finally {
5919 Binder.restoreCallingIdentity(identity);
5920 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005921 }
5922
5923 /**
5924 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005925 * Get the allowed carrier list and the excluded carrier list, including the priority between
5926 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005927 * Require system privileges. In the future we may add this to carrier APIs.
5928 *
Michele Berionne482f8202018-11-27 18:57:59 -08005929 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005930 */
5931 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005932 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005933 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005934 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935
5936 final long identity = Binder.clearCallingIdentity();
5937 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005938 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5939 if (response instanceof CarrierRestrictionRules) {
5940 return (CarrierRestrictionRules) response;
5941 }
5942 // Response is an Exception of some kind,
5943 // which is signalled to the user as a NULL retval
5944 return null;
5945 } catch (Exception e) {
5946 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5947 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005951 }
5952
fionaxu59545b42016-05-25 15:53:37 -07005953 /**
5954 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5955 * @param subId the subscription ID that this action applies to.
5956 * @param enabled control enable or disable metered apns.
5957 * {@hide}
5958 */
5959 @Override
5960 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5961 enforceModifyPermission();
5962 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963
5964 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005965 if (phone == null) {
5966 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5967 return;
5968 }
5969 try {
5970 phone.carrierActionSetMeteredApnsEnabled(enabled);
5971 } catch (Exception e) {
5972 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 } finally {
5974 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005975 }
5976 }
5977
5978 /**
5979 * Action set from carrier signalling broadcast receivers to enable/disable radio
5980 * @param subId the subscription ID that this action applies to.
5981 * @param enabled control enable or disable radio.
5982 * {@hide}
5983 */
5984 @Override
5985 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5986 enforceModifyPermission();
5987 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988
5989 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005990 if (phone == null) {
5991 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5992 return;
5993 }
5994 try {
5995 phone.carrierActionSetRadioEnabled(enabled);
5996 } catch (Exception e) {
5997 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 } finally {
5999 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006000 }
6001 }
6002
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006003 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006004 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6005 * network status based on which carrier apps could apply actions accordingly,
6006 * enable/disable default url handler for example.
6007 *
6008 * @param subId the subscription ID that this action applies to.
6009 * @param report control start/stop reporting the default network status.
6010 * {@hide}
6011 */
6012 @Override
6013 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6014 enforceModifyPermission();
6015 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016
6017 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006018 if (phone == null) {
6019 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6020 return;
6021 }
6022 try {
6023 phone.carrierActionReportDefaultNetworkStatus(report);
6024 } catch (Exception e) {
6025 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 } finally {
6027 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006028 }
6029 }
6030
6031 /**
fionaxud9622282017-07-17 17:51:30 -07006032 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6033 * @param subId the subscription ID that this action applies to.
6034 * {@hide}
6035 */
6036 @Override
6037 public void carrierActionResetAll(int subId) {
6038 enforceModifyPermission();
6039 final Phone phone = getPhone(subId);
6040 if (phone == null) {
6041 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6042 return;
6043 }
6044 try {
6045 phone.carrierActionResetAll();
6046 } catch (Exception e) {
6047 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6048 }
6049 }
6050
6051 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006052 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6053 * bug report is being generated.
6054 */
6055 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006056 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006057 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6058 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006059 writer.println("Permission Denial: can't dump Phone from pid="
6060 + Binder.getCallingPid()
6061 + ", uid=" + Binder.getCallingUid()
6062 + "without permission "
6063 + android.Manifest.permission.DUMP);
6064 return;
6065 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006066 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006067 }
Jack Yueb89b242016-06-22 13:27:47 -07006068
Brad Ebingerdac2f002018-04-03 15:17:52 -07006069 @Override
6070 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6071 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6072 throws RemoteException {
6073 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6074 }
6075
Jack Yueb89b242016-06-22 13:27:47 -07006076 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006077 * Get aggregated video call data usage since boot.
6078 *
6079 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6080 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006081 * {@hide}
6082 */
6083 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006084 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006085 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6086 null);
6087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 final long identity = Binder.clearCallingIdentity();
6089 try {
6090 // NetworkStatsService keeps tracking the active network interface and identity. It
6091 // records the delta with the corresponding network identity.
6092 // We just return the total video call data usage snapshot since boot.
6093 Phone phone = getPhone(subId);
6094 if (phone != null) {
6095 return phone.getVtDataUsage(perUidStats);
6096 }
6097 return null;
6098 } finally {
6099 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006100 }
Jack Yueb89b242016-06-22 13:27:47 -07006101 }
Jack Yu75ab2952016-07-08 14:29:33 -07006102
6103 /**
6104 * Policy control of data connection. Usually used when data limit is passed.
6105 * @param enabled True if enabling the data, otherwise disabling.
6106 * @param subId Subscription index
6107 * {@hide}
6108 */
6109 @Override
6110 public void setPolicyDataEnabled(boolean enabled, int subId) {
6111 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112
6113 final long identity = Binder.clearCallingIdentity();
6114 try {
6115 Phone phone = getPhone(subId);
6116 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006117 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 }
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006121 }
6122 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006123
6124 /**
6125 * Get Client request stats
6126 * @return List of Client Request Stats
6127 * @hide
6128 */
6129 @Override
6130 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006131 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006132 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006133 return null;
6134 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006135 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 final long identity = Binder.clearCallingIdentity();
6138 try {
6139 if (phone != null) {
6140 return phone.getClientRequestStats();
6141 }
6142
6143 return null;
6144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006147 }
6148
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006149 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006150 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006151 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006152 }
Jack Yueb4124c2017-02-16 15:32:43 -08006153
6154 /**
Grace Chen70990072017-03-24 17:21:30 -07006155 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006156 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006157 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006158 * @param state State of SIM (power down, power up, pass through)
6159 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6160 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6161 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006162 *
6163 **/
6164 @Override
Grace Chen70990072017-03-24 17:21:30 -07006165 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006166 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006167 Phone phone = PhoneFactory.getPhone(slotIndex);
6168
vagdeviaf9a5b92018-08-15 16:01:53 -07006169 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 final long identity = Binder.clearCallingIdentity();
6172 try {
6173 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006174 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 }
6176 } finally {
6177 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006178 }
6179 }
Shuo Qiandd210312017-04-12 22:11:33 +00006180
Tyler Gunn65d45c22017-06-05 11:22:26 -07006181 private boolean isUssdApiAllowed(int subId) {
6182 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006183 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006184 if (configManager == null) {
6185 return false;
6186 }
6187 PersistableBundle pb = configManager.getConfigForSubId(subId);
6188 if (pb == null) {
6189 return false;
6190 }
6191 return pb.getBoolean(
6192 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6193 }
6194
Shuo Qiandd210312017-04-12 22:11:33 +00006195 /**
6196 * Check if phone is in emergency callback mode
6197 * @return true if phone is in emergency callback mode
6198 * @param subId sub id
6199 */
goneil9c5f4872017-12-05 14:07:56 -08006200 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006201 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006202 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006203 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204
6205 final long identity = Binder.clearCallingIdentity();
6206 try {
6207 if (phone != null) {
6208 return phone.isInEcm();
6209 } else {
6210 return false;
6211 }
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006214 }
6215 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006216
6217 /**
6218 * Get the current signal strength information for the given subscription.
6219 * Because this information is not updated when the device is in a low power state
6220 * it should not be relied-upon to be current.
6221 * @param subId Subscription index
6222 * @return the most recent cached signal strength info from the modem
6223 */
6224 @Override
6225 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 final long identity = Binder.clearCallingIdentity();
6227 try {
6228 Phone p = getPhone(subId);
6229 if (p == null) {
6230 return null;
6231 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 return p.getSignalStrength();
6234 } finally {
6235 Binder.restoreCallingIdentity(identity);
6236 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006237 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006238
Pengquan Meng77b7f132018-08-22 14:49:57 -07006239 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006240 * Get the current modem radio state for the given slot.
6241 * @param slotIndex slot index.
6242 * @param callingPackage the name of the package making the call.
6243 * @return the current radio power state from the modem
6244 */
6245 @Override
6246 public int getRadioPowerState(int slotIndex, String callingPackage) {
6247 Phone phone = PhoneFactory.getPhone(slotIndex);
6248 if (phone != null) {
6249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6250 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6251 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6252 }
6253
6254 final long identity = Binder.clearCallingIdentity();
6255 try {
6256 return phone.getRadioPowerState();
6257 } finally {
6258 Binder.restoreCallingIdentity(identity);
6259 }
6260 }
6261 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6262 }
6263
6264 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006265 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6266 *
6267 * <p>Requires one of the following permissions:
6268 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6269 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6270 * privileges.
6271 *
6272 * @param subId subscription id
6273 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6274 * {@code false}.
6275 */
6276 @Override
6277 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006278 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6279 null /* message */);
6280
Pengquan Menga1bb6272018-09-06 09:59:22 -07006281 boolean isEnabled = false;
6282 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006283 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006284 Phone phone = getPhone(subId);
6285 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006286 } catch (Exception e) {
6287 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6288 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006289 } finally {
6290 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006291 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006292 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006293 }
6294
6295
6296 /**
6297 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6298 *
6299 * <p> Requires permission:
6300 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6301 * privileges.
6302 *
6303 * @param subId subscription id
6304 * @param isEnabled {@code true} means enable, {@code false} means disable.
6305 */
6306 @Override
6307 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6309 mApp, subId, "setDataRoamingEnabled");
6310
Pengquan Menga1bb6272018-09-06 09:59:22 -07006311 final long identity = Binder.clearCallingIdentity();
6312 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006313 Phone phone = getPhone(subId);
6314 if (phone != null) {
6315 phone.setDataRoamingEnabled(isEnabled);
6316 }
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006319 }
6320 }
6321
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006322 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006323 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006324 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6325 mApp, subId, "isManualNetworkSelectionAllowed");
6326
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006327 boolean isAllowed = true;
6328 final long identity = Binder.clearCallingIdentity();
6329 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006330 Phone phone = getPhone(subId);
6331 if (phone != null) {
6332 isAllowed = phone.isCspPlmnEnabled();
6333 }
6334 } finally {
6335 Binder.restoreCallingIdentity(identity);
6336 }
6337 return isAllowed;
6338 }
6339
6340 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006341 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006342 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006343 try {
6344 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006345 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006346 } catch (SecurityException e) {
6347 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6348 // has carrier privileges on an active UICC
6349 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6350 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006351 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006352 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006353 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006354
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006357 UiccController uiccController = UiccController.getInstance();
6358 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006359 if (hasReadPermission) {
6360 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006361 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006362
6363 // Remove private info if the caller doesn't have access
6364 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6365 for (UiccCardInfo cardInfo : cardInfos) {
6366 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6367 // is available
6368 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6369 if (card == null || card.getUiccProfile() == null) {
6370 // assume no access if the card or profile is unavailable
6371 filteredInfos.add(cardInfo.getUnprivileged());
6372 continue;
6373 }
6374 UiccProfile profile = card.getUiccProfile();
6375 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6376 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6377 filteredInfos.add(cardInfo);
6378 } else {
6379 filteredInfos.add(cardInfo.getUnprivileged());
6380 }
6381 }
6382 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
6386 }
6387
6388 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006389 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006390 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392 final long identity = Binder.clearCallingIdentity();
6393 try {
6394 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6395 if (slots == null) {
6396 Rlog.i(LOG_TAG, "slots is null.");
6397 return null;
6398 }
6399
6400 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6401 for (int i = 0; i < slots.length; i++) {
6402 UiccSlot slot = slots[i];
6403 if (slot == null) {
6404 continue;
6405 }
6406
Jordan Liu7be7e652019-05-06 18:55:02 +00006407 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408 UiccCard card = slot.getUiccCard();
6409 if (card != null) {
6410 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006411 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 cardId = slot.getIccId();
6413 }
6414
6415 int cardState = 0;
6416 switch (slot.getCardState()) {
6417 case CARDSTATE_ABSENT:
6418 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6419 break;
6420 case CARDSTATE_PRESENT:
6421 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6422 break;
6423 case CARDSTATE_ERROR:
6424 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6425 break;
6426 case CARDSTATE_RESTRICTED:
6427 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6428 break;
6429 default:
6430 break;
6431
6432 }
6433
6434 infos[i] = new UiccSlotInfo(
6435 slot.isActive(),
6436 slot.isEuicc(),
6437 cardId,
6438 cardState,
6439 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006440 slot.isExtendedApduSupported(),
6441 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442 }
6443 return infos;
6444 } finally {
6445 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006446 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006447 }
6448
6449 @Override
6450 public boolean switchSlots(int[] physicalSlots) {
6451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452
6453 final long identity = Binder.clearCallingIdentity();
6454 try {
6455 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006459 }
Jack Yu4c988042018-02-27 15:30:01 -08006460
6461 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006462 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 return UiccController.getInstance().getCardIdForDefaultEuicc();
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
6469 }
6470
6471 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006472 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6473 enforceModifyPermission();
6474 final Phone phone = getPhone(subId);
6475 if (phone == null) {
6476 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6477 return;
6478 }
6479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 phone.setRadioIndicationUpdateMode(filters, mode);
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
Jack Yu4c988042018-02-27 15:30:01 -08006486 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006487
6488 /**
goneil47ffb6e2018-04-06 15:40:58 -07006489 * A test API to reload the UICC profile.
6490 *
6491 * <p>Requires that the calling app has permission
6492 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6493 * @hide
6494 */
6495 @Override
6496 public void refreshUiccProfile(int subId) {
6497 enforceModifyPermission();
6498
6499 final long identity = Binder.clearCallingIdentity();
6500 try {
6501 Phone phone = getPhone(subId);
6502 if (phone == null) {
6503 return;
6504 }
6505 UiccCard uiccCard = phone.getUiccCard();
6506 if (uiccCard == null) {
6507 return;
6508 }
6509 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6510 if (uiccProfile == null) {
6511 return;
6512 }
6513 uiccProfile.refresh();
6514 } finally {
6515 Binder.restoreCallingIdentity(identity);
6516 }
6517 }
6518
6519 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006520 * Returns false if the mobile data is disabled by default, otherwise return true.
6521 */
6522 private boolean getDefaultDataEnabled() {
6523 return "true".equalsIgnoreCase(
6524 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6525 }
6526
6527 /**
6528 * Returns true if the data roaming is enabled by default, i.e the system property
6529 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6530 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6531 */
6532 private boolean getDefaultDataRoamingEnabled(int subId) {
6533 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006534 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006535 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6536 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6537 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6538 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6539 return isDataRoamingEnabled;
6540 }
6541
6542 /**
6543 * Returns the default network type for the given {@code subId}, if the default network type is
6544 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6545 */
6546 private int getDefaultNetworkType(int subId) {
6547 return Integer.parseInt(
6548 TelephonyManager.getTelephonyProperty(
6549 mSubscriptionController.getPhoneId(subId),
6550 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6551 String.valueOf(Phone.PREFERRED_NT_MODE)));
6552 }
fionaxua13278b2018-03-21 00:08:13 -07006553
6554 @Override
6555 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006556 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558
6559 final long identity = Binder.clearCallingIdentity();
6560 try {
6561 final Phone phone = getPhone(subId);
6562 if (phone == null) {
6563 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6564 return;
6565 }
chen xueaba88a2019-03-15 13:15:10 -07006566 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6567 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 } finally {
6569 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006570 }
fionaxua13278b2018-03-21 00:08:13 -07006571 }
6572
6573 @Override
6574 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006575 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576
6577 final long identity = Binder.clearCallingIdentity();
6578 try {
6579 final Phone phone = getPhone(subId);
6580 if (phone == null) {
6581 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6582 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6583 }
6584 return phone.getCarrierIdListVersion();
6585 } finally {
6586 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006587 }
fionaxua13278b2018-03-21 00:08:13 -07006588 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006589
6590 @Override
6591 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6593 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6594 return -1;
6595 }
6596
6597 final long identity = Binder.clearCallingIdentity();
6598 try {
6599 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6600 } finally {
6601 Binder.restoreCallingIdentity(identity);
6602 }
6603 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006604
6605 @Override
6606 public int getCdmaRoamingMode(int subId) {
6607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6608 mApp, subId, "getCdmaRoamingMode");
6609
6610 final long identity = Binder.clearCallingIdentity();
6611 try {
6612 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6613 } finally {
6614 Binder.restoreCallingIdentity(identity);
6615 }
6616 }
6617
6618 @Override
6619 public boolean setCdmaRoamingMode(int subId, int mode) {
6620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6621 mApp, subId, "setCdmaRoamingMode");
6622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6626 } finally {
6627 Binder.restoreCallingIdentity(identity);
6628 }
6629 }
6630
6631 @Override
6632 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6634 mApp, subId, "setCdmaSubscriptionMode");
6635
6636 final long identity = Binder.clearCallingIdentity();
6637 try {
6638 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6639 } finally {
6640 Binder.restoreCallingIdentity(identity);
6641 }
6642 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006643
6644 private void ensureUserRunning(int userId) {
6645 if (!mUserManager.isUserRunning(userId)) {
6646 throw new IllegalStateException("User " + userId + " does not exist or not running");
6647 }
6648 }
6649
6650 /**
6651 * Returns a list of SMS apps on a given user.
6652 *
6653 * Only the shell user (UID 2000 or 0) can call it.
6654 * Target user must be running.
6655 */
6656 @Override
6657 public String[] getSmsApps(int userId) {
6658 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6659 ensureUserRunning(userId);
6660
6661 final Collection<SmsApplicationData> apps =
6662 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6663
6664 String[] ret = new String[apps.size()];
6665 int i = 0;
6666 for (SmsApplicationData app : apps) {
6667 ret[i++] = app.mPackageName;
6668 }
6669 return ret;
6670 }
6671
6672 /**
6673 * Returns the default SMS app package name on a given user.
6674 *
6675 * Only the shell user (UID 2000 or 0) can call it.
6676 * Target user must be running.
6677 */
6678 @Override
6679 public String getDefaultSmsApp(int userId) {
6680 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6681 ensureUserRunning(userId);
6682
6683 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6684 /* updateIfNeeded= */ true, userId);
6685 return cn == null ? null : cn.getPackageName();
6686 }
6687
6688 /**
6689 * Set a package as the default SMS app on a given user.
6690 *
6691 * Only the shell user (UID 2000 or 0) can call it.
6692 * Target user must be running.
6693 */
6694 @Override
6695 public void setDefaultSmsApp(int userId, String packageName) {
6696 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6697 ensureUserRunning(userId);
6698
6699 boolean found = false;
6700 for (String pkg : getSmsApps(userId)) {
6701 if (TextUtils.equals(packageName, pkg)) {
6702 found = true;
6703 break;
6704 }
6705 }
6706 if (!found) {
6707 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6708 }
6709
6710 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6711 }
sqianc5eccab2018-10-19 18:46:41 -07006712
6713 @Override
sqian8c685422019-02-22 15:55:18 -08006714 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006715 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006717 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006718 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6719 }
6720 final long identity = Binder.clearCallingIdentity();
6721 try {
sqian854d44b2018-12-12 16:48:18 -08006722 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6723 for (Phone phone: PhoneFactory.getPhones()) {
6724 if (phone.getEmergencyNumberTracker() != null
6725 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6726 emergencyNumberListInternal.put(
6727 phone.getSubId(),
6728 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6729 }
sqian11b7a0e2018-12-05 18:48:28 -08006730 }
sqian854d44b2018-12-12 16:48:18 -08006731 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
sqianc5eccab2018-10-19 18:46:41 -07006735 }
6736
6737 @Override
sqian8c685422019-02-22 15:55:18 -08006738 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006739 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006740 if (!exactMatch) {
6741 TelephonyPermissions
6742 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006743 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006744 }
6745 final long identity = Binder.clearCallingIdentity();
6746 try {
sqian854d44b2018-12-12 16:48:18 -08006747 for (Phone phone: PhoneFactory.getPhones()) {
6748 if (phone.getEmergencyNumberTracker() != null
6749 && phone.getEmergencyNumberTracker() != null) {
6750 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6751 number, exactMatch)) {
6752 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006753 }
6754 }
sqian11b7a0e2018-12-05 18:48:28 -08006755 }
6756 return false;
6757 } finally {
6758 Binder.restoreCallingIdentity(identity);
6759 }
6760 }
6761
sqianf4ca7ed2019-01-15 18:32:07 -08006762 /**
6763 * Update emergency number list for test mode.
6764 */
6765 @Override
6766 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6767 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6768 "updateEmergencyNumberListTestMode");
6769
6770 final long identity = Binder.clearCallingIdentity();
6771 try {
6772 for (Phone phone: PhoneFactory.getPhones()) {
6773 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6774 if (tracker != null) {
6775 tracker.executeEmergencyNumberTestModeCommand(action, num);
6776 }
6777 }
6778 } finally {
6779 Binder.restoreCallingIdentity(identity);
6780 }
6781 }
6782
6783 /**
6784 * Get the full emergency number list for test mode.
6785 */
6786 @Override
6787 public List<String> getEmergencyNumberListTestMode() {
6788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6789 "getEmergencyNumberListTestMode");
6790
6791 final long identity = Binder.clearCallingIdentity();
6792 try {
6793 Set<String> emergencyNumbers = new HashSet<>();
6794 for (Phone phone: PhoneFactory.getPhones()) {
6795 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6796 if (tracker != null) {
6797 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6798 emergencyNumbers.add(num.getNumber());
6799 }
6800 }
6801 }
6802 return new ArrayList<>(emergencyNumbers);
6803 } finally {
6804 Binder.restoreCallingIdentity(identity);
6805 }
6806 }
6807
chen xud6b45bd2018-10-30 22:27:10 -07006808 @Override
6809 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6810 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6811 Phone phone = getPhone(subId);
6812 if (phone == null) {
6813 return null;
6814 }
6815 final long identity = Binder.clearCallingIdentity();
6816 try {
6817 UiccProfile profile = UiccController.getInstance()
6818 .getUiccProfileForPhone(phone.getPhoneId());
6819 if (profile != null) {
6820 return profile.getCertsFromCarrierPrivilegeAccessRules();
6821 }
6822 } finally {
6823 Binder.restoreCallingIdentity(identity);
6824 }
6825 return null;
6826 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006827
6828 /**
6829 * Enable or disable a modem stack.
6830 */
6831 @Override
6832 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6833 enforceModifyPermission();
6834
6835 final long identity = Binder.clearCallingIdentity();
6836 try {
6837 Phone phone = PhoneFactory.getPhone(slotIndex);
6838 if (phone == null) {
6839 return false;
6840 } else {
6841 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6842 }
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
6846 }
Michelecea4cf22018-12-21 15:00:11 -08006847
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006848 /**
6849 * Whether a modem stack is enabled or not.
6850 */
6851 @Override
6852 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6853 Phone phone = PhoneFactory.getPhone(slotIndex);
6854 if (phone == null) return false;
6855
6856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6857 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6858 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6859 }
6860
6861 final long identity = Binder.clearCallingIdentity();
6862 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006863 try {
6864 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6865 } catch (NoSuchElementException ex) {
6866 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6867 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006868 } finally {
6869 Binder.restoreCallingIdentity(identity);
6870 }
6871 }
6872
Michelecea4cf22018-12-21 15:00:11 -08006873 @Override
Michele0ea7d782019-03-19 14:58:42 -07006874 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006875 enforceModifyPermission();
6876
6877 final long identity = Binder.clearCallingIdentity();
6878 try {
6879 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006880 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006881 .commit();
6882 } finally {
6883 Binder.restoreCallingIdentity(identity);
6884 }
6885 }
6886
6887 @Override
Michele0ea7d782019-03-19 14:58:42 -07006888 @TelephonyManager.IsMultiSimSupportedResult
6889 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006891 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6892 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006893 }
Michelecea4cf22018-12-21 15:00:11 -08006894
6895 final long identity = Binder.clearCallingIdentity();
6896 try {
Michele0ea7d782019-03-19 14:58:42 -07006897 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006898 } finally {
6899 Binder.restoreCallingIdentity(identity);
6900 }
6901 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006902
Michele0ea7d782019-03-19 14:58:42 -07006903 @TelephonyManager.IsMultiSimSupportedResult
6904 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006905 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6906 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6907 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006908 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6909 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006910 }
6911 // Check if the hardware supports multisim functionality. If usage of multisim is not
6912 // supported by the modem, indicate that it is restricted.
6913 PhoneCapability staticCapability =
6914 mPhoneConfigurationManager.getStaticPhoneCapability();
6915 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006916 loge("isMultiSimSupportedInternal: no static configuration available");
6917 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006918 }
6919 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006920 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6921 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006922 }
6923 // Check if support of multiple SIMs is restricted by carrier
6924 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006925 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006926 }
6927
Michele0ea7d782019-03-19 14:58:42 -07006928 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006929 }
6930
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006931 /**
6932 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006933 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6934 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6935 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006936 * @param numOfSims number of active sims we want to switch to
6937 */
6938 @Override
6939 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006940 if (numOfSims == 1) {
6941 enforceModifyPermission();
6942 } else {
6943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6944 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6945 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006946 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006947
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006948 try {
Michele30b57b22019-03-01 12:01:14 -08006949 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006950 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006951 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6952 return;
6953 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006954 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
6958 }
6959
6960 /**
chen xub4baa772019-04-03 10:23:41 -07006961 * Get whether making changes to modem configurations will trigger reboot.
6962 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006963 */
6964 @Override
chen xub4baa772019-04-03 10:23:41 -07006965 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6967 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6968 return false;
6969 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006970 final long identity = Binder.clearCallingIdentity();
6971 try {
6972 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6973 } finally {
6974 Binder.restoreCallingIdentity(identity);
6975 }
6976 }
6977
Nathan Harold29f5f052019-02-15 13:41:57 -08006978 private void updateModemStateMetrics() {
6979 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6980 // TODO: check the state for each modem if the api is ready.
6981 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6982 }
6983
Pengquan Meng3889a572019-01-23 11:16:29 -08006984 @Override
6985 public int[] getSlotsMapping() {
6986 enforceReadPrivilegedPermission("getSlotsMapping");
6987
6988 final long identity = Binder.clearCallingIdentity();
6989 try {
6990 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6991 // All logical slots should have a mapping to a physical slot.
6992 int[] logicalSlotsMapping = new int[phoneCount];
6993 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6994 for (int i = 0; i < slotInfos.length; i++) {
6995 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6996 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6997 }
6998 }
6999 return logicalSlotsMapping;
7000 } finally {
7001 Binder.restoreCallingIdentity(identity);
7002 }
7003 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007004
7005 /**
7006 * Get the IRadio HAL Version
7007 */
7008 @Override
7009 public int getRadioHalVersion() {
7010 Phone phone = getDefaultPhone();
7011 if (phone == null) return -1;
7012 HalVersion hv = phone.getHalVersion();
7013 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7014 return hv.major * 100 + hv.minor;
7015 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007016
7017 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007018 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7019 * corresponding network requests on a subId.
7020 *
7021 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007022 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007023 * 2) APN is un-metered for this subscription, or
7024 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7025 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7026 *
7027 * @return whether data is allowed for a apn type.
7028 *
7029 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007030 */
7031 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007032 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007033 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007034 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7035 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007036 }
7037
7038 // Now that all security checks passes, perform the operation as ourselves.
7039 final long identity = Binder.clearCallingIdentity();
7040 try {
7041 Phone phone = getPhone(subId);
7042 if (phone == null) return false;
7043
7044 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007045 apnType), phone);
7046 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
7050 }
7051
7052 @Override
7053 public boolean isApnMetered(int apnType, int subId) {
7054 enforceReadPrivilegedPermission("isApnMetered");
7055
7056 // Now that all security checks passes, perform the operation as ourselves.
7057 final long identity = Binder.clearCallingIdentity();
7058 try {
7059 Phone phone = getPhone(subId);
7060 if (phone == null) return true; // By default return true.
7061
7062 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
7063 apnType), phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007064 } finally {
7065 Binder.restoreCallingIdentity(identity);
7066 }
7067 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007068}