blob: bdc486bcf08d5305f11f438dbbbde7f3fb1c8fef [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;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080082import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070084import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070085import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080087import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000088import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070089import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070091import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080092import android.telephony.data.ApnSetting;
93import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070094import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080095import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070096import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080097import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070098import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080099import android.telephony.ims.aidl.IImsMmTelFeature;
100import android.telephony.ims.aidl.IImsRcsFeature;
101import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700102import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.feature.MmTelFeature;
104import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800105import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800107import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800109import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800110import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800111
Brad Ebinger35c841c2018-10-01 10:40:55 -0700112import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700113import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800114import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700115import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700116import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700117import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800118import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700120import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800122import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700123import com.android.internal.telephony.IIntegerConsumer;
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;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700142import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700143import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800144import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800145import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700146import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800147import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700148import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800149import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800150import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151import com.android.internal.telephony.uicc.IccIoResult;
152import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800153import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700154import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800155import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800157import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000158import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700159import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800160import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700161import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700162import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800163import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700164import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700165import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800166
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700167import java.io.FileDescriptor;
168import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800170import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700171import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800172import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800173import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800174import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100175import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800176import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700177import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179
180/**
181 * Implementation of the ITelephony interface.
182 */
Santos Cordon117fee72014-05-16 17:56:12 -0700183public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184 private static final String LOG_TAG = "PhoneInterfaceManager";
185 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
186 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800187 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
189 // Message codes used with mMainThreadHandler
190 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700191 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
192 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700193 private static final int CMD_OPEN_CHANNEL = 9;
194 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
195 private static final int CMD_CLOSE_CHANNEL = 11;
196 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800197 private static final int CMD_NV_READ_ITEM = 13;
198 private static final int EVENT_NV_READ_ITEM_DONE = 14;
199 private static final int CMD_NV_WRITE_ITEM = 15;
200 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
201 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
202 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700203 private static final int CMD_RESET_MODEM_CONFIG = 19;
204 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800205 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
206 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
207 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
208 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800209 private static final int CMD_SEND_ENVELOPE = 25;
210 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000211 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
212 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700213 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
214 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
215 private static final int CMD_EXCHANGE_SIM_IO = 31;
216 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800217 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
218 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700219 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
220 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700221 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
222 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700223 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
224 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
225 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
226 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700227 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
228 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
229 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
230 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700231 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800232 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
233 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000234 private static final int CMD_SWITCH_SLOTS = 50;
235 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700236 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
237 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
238 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
239 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
240 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
241 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
242 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
243 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700244 private static final int CMD_GET_ALL_CELL_INFO = 60;
245 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
246 private static final int CMD_GET_CELL_LOCATION = 62;
247 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700248 private static final int CMD_MODEM_REBOOT = 64;
249 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700250 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
251 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800252 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
253 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700254 private static final int CMD_GET_MODEM_STATUS = 70;
255 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800257 // Parameters of select command.
258 private static final int SELECT_COMMAND = 0xA4;
259 private static final int SELECT_P1 = 0x04;
260 private static final int SELECT_P2 = 0;
261 private static final int SELECT_P3 = 0x10;
262
Pengquan Meng85728fb2018-03-12 16:31:21 -0700263 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
264 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
265 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
266
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267 /** The singleton instance. */
268 private static PhoneInterfaceManager sInstance;
269
Wink Saville3ab207e2014-11-20 13:07:20 -0800270 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800271 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700272 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800273 private AppOpsManager mAppOps;
274 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800275 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800276 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700277 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278
Derek Tan97ebb422014-09-05 16:55:38 -0700279 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
280 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800281 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800282 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700283
Michelecea4cf22018-12-21 15:00:11 -0800284 // String to store multi SIM allowed
285 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
286
Derek Tan740e1672017-06-27 14:56:27 -0700287 // The AID of ISD-R.
288 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
289
yinxub1bed742017-04-17 11:45:04 -0700290 private NetworkScanRequestTracker mNetworkScanRequestTracker;
291
David Kelly5e06a7f2018-03-12 14:10:59 +0000292 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
293 private static final int MANUFACTURER_CODE_LENGTH = 8;
294
Derek Tan89e89d42014-07-08 17:00:10 -0700295 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700296 * A request object to use for transmitting data to an ICC.
297 */
298 private static final class IccAPDUArgument {
299 public int channel, cla, command, p1, p2, p3;
300 public String data;
301
302 public IccAPDUArgument(int channel, int cla, int command,
303 int p1, int p2, int p3, String data) {
304 this.channel = channel;
305 this.cla = cla;
306 this.command = command;
307 this.p1 = p1;
308 this.p2 = p2;
309 this.p3 = p3;
310 this.data = data;
311 }
312 }
313
314 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700315 * A request object to use for transmitting data to an ICC.
316 */
317 private static final class ManualNetworkSelectionArgument {
318 public OperatorInfo operatorInfo;
319 public boolean persistSelection;
320
321 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
322 this.operatorInfo = operatorInfo;
323 this.persistSelection = persistSelection;
324 }
325 }
326
327 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700328 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
329 * request after sending. The main thread will notify the request when it is complete.
330 */
331 private static final class MainThreadRequest {
332 /** The argument to use for the request */
333 public Object argument;
334 /** The result of the request that is run on the main thread */
335 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800336 // The subscriber id that this request applies to. Defaults to
337 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
338 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339
Nathan Harold92bed182018-10-12 18:16:49 -0700340 // In cases where subId is unavailable, the caller needs to specify the phone.
341 public Phone phone;
342
vagdeviaf9a5b92018-08-15 16:01:53 -0700343 public WorkSource workSource;
344
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 public MainThreadRequest(Object argument) {
346 this.argument = argument;
347 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800348
Nathan Harold92bed182018-10-12 18:16:49 -0700349 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
350 this.argument = argument;
351 if (phone != null) {
352 this.phone = phone;
353 }
354 this.workSource = workSource;
355 }
356
vagdeviaf9a5b92018-08-15 16:01:53 -0700357 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800358 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800359 if (subId != null) {
360 this.subId = subId;
361 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700362 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 }
365
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800366 private static final class IncomingThirdPartyCallArgs {
367 public final ComponentName component;
368 public final String callId;
369 public final String callerDisplayName;
370
371 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
372 String callerDisplayName) {
373 this.component = component;
374 this.callId = callId;
375 this.callerDisplayName = callerDisplayName;
376 }
377 }
378
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 /**
380 * A handler that processes messages on the main thread in the phone process. Since many
381 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
382 * inbound binder threads to the main thread in the phone process. The Binder thread
383 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
384 * on, which will be notified when the operation completes and will contain the result of the
385 * request.
386 *
387 * <p>If a MainThreadRequest object is provided in the msg.obj field,
388 * note that request.result must be set to something non-null for the calling thread to
389 * unblock.
390 */
391 private final class MainThreadHandler extends Handler {
392 @Override
393 public void handleMessage(Message msg) {
394 MainThreadRequest request;
395 Message onCompleted;
396 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800397 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700398 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800399 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400
401 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700402 case CMD_HANDLE_USSD_REQUEST: {
403 request = (MainThreadRequest) msg.obj;
404 final Phone phone = getPhoneFromRequest(request);
405 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
406 String ussdRequest = ussdObject.first;
407 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700408
Pengquan Menga1bb6272018-09-06 09:59:22 -0700409 if (!isUssdApiAllowed(request.subId)) {
410 // Carrier does not support use of this API, return failure.
411 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
412 UssdResponse response = new UssdResponse(ussdRequest, null);
413 Bundle returnData = new Bundle();
414 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
415 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700416
Pengquan Menga1bb6272018-09-06 09:59:22 -0700417 request.result = true;
418 notifyRequester(request);
419 return;
420 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700421
Pengquan Menga1bb6272018-09-06 09:59:22 -0700422 try {
423 request.result = phone != null
424 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
425 } catch (CallStateException cse) {
426 request.result = false;
427 }
428 // Wake up the requesting thread
429 notifyRequester(request);
430 break;
pkanwar32d516d2016-10-14 19:37:38 -0700431 }
432
Yorke Lee716f67e2015-06-17 15:39:16 -0700433 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700435 final Phone phone = getPhoneFromRequest(request);
436 request.result = phone != null ?
437 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
438 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800447 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700448 if (uiccCard == null) {
449 loge("iccTransmitApduLogicalChannel: No UICC");
450 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700452 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
454 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700455 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 iccArgument.channel, iccArgument.cla, iccArgument.command,
457 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700459 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 break;
461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 ar = (AsyncResult) msg.obj;
464 request = (MainThreadRequest) ar.userObj;
465 if (ar.exception == null && ar.result != null) {
466 request.result = ar.result;
467 } else {
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
469 if (ar.result == null) {
470 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800471 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800473 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 } else {
475 loge("iccTransmitApduLogicalChannel: Unknown exception");
476 }
477 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700478 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 break;
480
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
482 request = (MainThreadRequest) msg.obj;
483 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800484 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 if (uiccCard == null) {
486 loge("iccTransmitApduBasicChannel: No UICC");
487 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 } else {
490 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
491 request);
492 uiccCard.iccTransmitApduBasicChannel(
493 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
494 iccArgument.p3, iccArgument.data, onCompleted);
495 }
496 break;
497
498 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
499 ar = (AsyncResult) msg.obj;
500 request = (MainThreadRequest) ar.userObj;
501 if (ar.exception == null && ar.result != null) {
502 request.result = ar.result;
503 } else {
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
505 if (ar.result == null) {
506 loge("iccTransmitApduBasicChannel: Empty response");
507 } else if (ar.exception instanceof CommandException) {
508 loge("iccTransmitApduBasicChannel: CommandException: " +
509 ar.exception);
510 } else {
511 loge("iccTransmitApduBasicChannel: Unknown exception");
512 }
513 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 break;
516
517 case CMD_EXCHANGE_SIM_IO:
518 request = (MainThreadRequest) msg.obj;
519 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800520 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700521 if (uiccCard == null) {
522 loge("iccExchangeSimIO: No UICC");
523 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 } else {
526 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
527 request);
528 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
529 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
530 iccArgument.data, onCompleted);
531 }
532 break;
533
534 case EVENT_EXCHANGE_SIM_IO_DONE:
535 ar = (AsyncResult) msg.obj;
536 request = (MainThreadRequest) ar.userObj;
537 if (ar.exception == null && ar.result != null) {
538 request.result = ar.result;
539 } else {
540 request.result = new IccIoResult(0x6f, 0, (byte[])null);
541 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 break;
544
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 case CMD_SEND_ENVELOPE:
546 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800547 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700548 if (uiccCard == null) {
549 loge("sendEnvelopeWithStatus: No UICC");
550 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 } else {
553 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
554 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
555 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 break;
557
558 case EVENT_SEND_ENVELOPE_DONE:
559 ar = (AsyncResult) msg.obj;
560 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700561 if (ar.exception == null && ar.result != null) {
562 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
565 if (ar.result == null) {
566 loge("sendEnvelopeWithStatus: Empty response");
567 } else if (ar.exception instanceof CommandException) {
568 loge("sendEnvelopeWithStatus: CommandException: " +
569 ar.exception);
570 } else {
571 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
572 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800573 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700574 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800575 break;
576
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 case CMD_OPEN_CHANNEL:
578 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800579 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800580 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 if (uiccCard == null) {
582 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800583 request.result = new IccOpenLogicalChannelResponse(-1,
584 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 } else {
587 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800588 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
589 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 break;
592
593 case EVENT_OPEN_CHANNEL_DONE:
594 ar = (AsyncResult) msg.obj;
595 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 int[] result = (int[]) ar.result;
599 int channelId = result[0];
600 byte[] selectResponse = null;
601 if (result.length > 1) {
602 selectResponse = new byte[result.length - 1];
603 for (int i = 1; i < result.length; ++i) {
604 selectResponse[i - 1] = (byte) result[i];
605 }
606 }
607 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 if (ar.result == null) {
611 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 if (ar.exception != null) {
614 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
615 }
616
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700618 if (ar.exception instanceof CommandException) {
619 CommandException.Error error =
620 ((CommandException) (ar.exception)).getCommandError();
621 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700623 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 }
626 }
627 openChannelResp = new IccOpenLogicalChannelResponse(
628 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700630 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 break;
633
634 case CMD_CLOSE_CHANNEL:
635 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800636 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700637 if (uiccCard == null) {
638 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900639 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700641 } else {
642 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
643 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
644 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 break;
646
647 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800648 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
649 break;
650
651 case CMD_NV_READ_ITEM:
652 request = (MainThreadRequest) msg.obj;
653 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800654 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
655 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800656 break;
657
658 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 ar = (AsyncResult) msg.obj;
660 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800661 if (ar.exception == null && ar.result != null) {
662 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800664 request.result = "";
665 if (ar.result == null) {
666 loge("nvReadItem: Empty response");
667 } else if (ar.exception instanceof CommandException) {
668 loge("nvReadItem: CommandException: " +
669 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800671 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 }
673 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
Jake Hambye994d462014-02-03 13:10:13 -0800677 case CMD_NV_WRITE_ITEM:
678 request = (MainThreadRequest) msg.obj;
679 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
680 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800681 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700682 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800683 break;
684
685 case EVENT_NV_WRITE_ITEM_DONE:
686 handleNullReturnEvent(msg, "nvWriteItem");
687 break;
688
689 case CMD_NV_WRITE_CDMA_PRL:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800692 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800693 break;
694
695 case EVENT_NV_WRITE_CDMA_PRL_DONE:
696 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
697 break;
698
chen xu6dac5ab2018-10-26 17:39:23 -0700699 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800700 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700701 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800702 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800703 break;
704
chen xu6dac5ab2018-10-26 17:39:23 -0700705 case EVENT_RESET_MODEM_CONFIG_DONE:
706 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
Jake Hamby7c27be32014-03-03 13:25:59 -0800709 case CMD_GET_PREFERRED_NETWORK_TYPE:
710 request = (MainThreadRequest) msg.obj;
711 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700712 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 break;
714
715 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
716 ar = (AsyncResult) msg.obj;
717 request = (MainThreadRequest) ar.userObj;
718 if (ar.exception == null && ar.result != null) {
719 request.result = ar.result; // Integer
720 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800721 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 if (ar.result == null) {
723 loge("getPreferredNetworkType: Empty response");
724 } else if (ar.exception instanceof CommandException) {
725 loge("getPreferredNetworkType: CommandException: " +
726 ar.exception);
727 } else {
728 loge("getPreferredNetworkType: Unknown exception");
729 }
730 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700731 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800732 break;
733
734 case CMD_SET_PREFERRED_NETWORK_TYPE:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
737 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700738 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800739 break;
740
741 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
742 handleNullReturnEvent(msg, "setPreferredNetworkType");
743 break;
744
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000745 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
746 request = (MainThreadRequest)msg.obj;
747 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800748 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000749 break;
750
751 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
752 ar = (AsyncResult)msg.obj;
753 request = (MainThreadRequest)ar.userObj;
754 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700755 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000756 break;
757
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800758 case CMD_SET_VOICEMAIL_NUMBER:
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
761 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800762 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
763 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800764 break;
765
766 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
767 handleNullReturnEvent(msg, "setVoicemailNumber");
768 break;
769
Stuart Scott54788802015-03-30 13:18:01 -0700770 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
773 request);
774 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
775 break;
776
777 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
778 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
779 break;
780
Shishir Agrawal302c8692015-06-19 13:49:39 -0700781 case CMD_PERFORM_NETWORK_SCAN:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
784 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
785 break;
786
787 case EVENT_PERFORM_NETWORK_SCAN_DONE:
788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
790 CellNetworkScanResult cellScanResult;
791 if (ar.exception == null && ar.result != null) {
792 cellScanResult = new CellNetworkScanResult(
793 CellNetworkScanResult.STATUS_SUCCESS,
794 (List<OperatorInfo>) ar.result);
795 } else {
796 if (ar.result == null) {
797 loge("getCellNetworkScanResults: Empty response");
798 }
799 if (ar.exception != null) {
800 loge("getCellNetworkScanResults: Exception: " + ar.exception);
801 }
802 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
803 if (ar.exception instanceof CommandException) {
804 CommandException.Error error =
805 ((CommandException) (ar.exception)).getCommandError();
806 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
807 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
808 } else if (error == CommandException.Error.GENERIC_FAILURE) {
809 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
810 }
811 }
812 cellScanResult = new CellNetworkScanResult(errorCode, null);
813 }
814 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700815 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700816 break;
817
818 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
819 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700820 ManualNetworkSelectionArgument selArg =
821 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700822 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
823 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700824 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
825 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700826 break;
827
828 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700829 ar = (AsyncResult) msg.obj;
830 request = (MainThreadRequest) ar.userObj;
831 if (ar.exception == null) {
832 request.result = true;
833 } else {
834 request.result = false;
835 loge("setNetworkSelectionModeManual " + ar.exception);
836 }
837 notifyRequester(request);
838 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700839 break;
840
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700841 case CMD_GET_MODEM_ACTIVITY_INFO:
842 request = (MainThreadRequest) msg.obj;
843 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700844 if (defaultPhone != null) {
845 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
846 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700847 break;
848
849 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result;
854 } else {
855 if (ar.result == null) {
856 loge("queryModemActivityInfo: Empty response");
857 } else if (ar.exception instanceof CommandException) {
858 loge("queryModemActivityInfo: CommandException: " +
859 ar.exception);
860 } else {
861 loge("queryModemActivityInfo: Unknown exception");
862 }
863 }
Amit Mahajand4766222016-01-28 15:28:28 -0800864 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
865 if (request.result == null) {
866 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
867 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700868 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700869 break;
870
Meng Wang1a7c35a2016-05-05 20:56:15 -0700871 case CMD_SET_ALLOWED_CARRIERS:
872 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800873 CarrierRestrictionRules argument =
874 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800876 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 break;
878
879 case EVENT_SET_ALLOWED_CARRIERS_DONE:
880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
882 if (ar.exception == null && ar.result != null) {
883 request.result = ar.result;
884 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800885 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
886 if (ar.exception instanceof CommandException) {
887 loge("setAllowedCarriers: CommandException: " + ar.exception);
888 CommandException.Error error =
889 ((CommandException) (ar.exception)).getCommandError();
890 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
891 request.result =
892 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
893 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 } else {
895 loge("setAllowedCarriers: Unknown exception");
896 }
897 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700898 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700899 break;
900
901 case CMD_GET_ALLOWED_CARRIERS:
902 request = (MainThreadRequest) msg.obj;
903 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800904 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700905 break;
906
907 case EVENT_GET_ALLOWED_CARRIERS_DONE:
908 ar = (AsyncResult) msg.obj;
909 request = (MainThreadRequest) ar.userObj;
910 if (ar.exception == null && ar.result != null) {
911 request.result = ar.result;
912 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800913 request.result = new IllegalStateException(
914 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700915 if (ar.result == null) {
916 loge("getAllowedCarriers: Empty response");
917 } else if (ar.exception instanceof CommandException) {
918 loge("getAllowedCarriers: CommandException: " +
919 ar.exception);
920 } else {
921 loge("getAllowedCarriers: Unknown exception");
922 }
923 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700924 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700925 break;
926
Nathan Haroldb3014052017-01-25 15:57:32 -0800927 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
928 ar = (AsyncResult) msg.obj;
929 request = (MainThreadRequest) ar.userObj;
930 if (ar.exception == null && ar.result != null) {
931 request.result = ar.result;
932 } else {
933 request.result = new IllegalArgumentException(
934 "Failed to retrieve Forbidden Plmns");
935 if (ar.result == null) {
936 loge("getForbiddenPlmns: Empty response");
937 } else {
938 loge("getForbiddenPlmns: Unknown exception");
939 }
940 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700941 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800942 break;
943
944 case CMD_GET_FORBIDDEN_PLMNS:
945 request = (MainThreadRequest) msg.obj;
946 uiccCard = getUiccCardFromRequest(request);
947 if (uiccCard == null) {
948 loge("getForbiddenPlmns() UiccCard is null");
949 request.result = new IllegalArgumentException(
950 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700951 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800952 break;
953 }
954 Integer appType = (Integer) request.argument;
955 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
956 if (uiccApp == null) {
957 loge("getForbiddenPlmns() no app with specified type -- "
958 + appType);
959 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700960 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800961 break;
962 } else {
963 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
964 + " specified type -- " + appType);
965 }
966 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
967 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
968 onCompleted);
969 break;
970
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000971 case CMD_SWITCH_SLOTS:
972 request = (MainThreadRequest) msg.obj;
973 int[] physicalSlots = (int[]) request.argument;
974 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
975 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
976 break;
977
978 case EVENT_SWITCH_SLOTS_DONE:
979 ar = (AsyncResult) msg.obj;
980 request = (MainThreadRequest) ar.userObj;
981 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700982 notifyRequester(request);
983 break;
984 case CMD_GET_NETWORK_SELECTION_MODE:
985 request = (MainThreadRequest) msg.obj;
986 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
987 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
988 break;
989
990 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
993 if (ar.exception != null) {
994 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
995 } else {
996 int mode = ((int[]) ar.result)[0];
997 if (mode == 0) {
998 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
999 } else {
1000 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1001 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001002 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001003 notifyRequester(request);
1004 break;
1005 case CMD_GET_CDMA_ROAMING_MODE:
1006 request = (MainThreadRequest) msg.obj;
1007 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1008 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1009 break;
1010 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 if (ar.exception != null) {
1014 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1015 } else {
1016 request.result = ((int[]) ar.result)[0];
1017 }
1018 notifyRequester(request);
1019 break;
1020 case CMD_SET_CDMA_ROAMING_MODE:
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1023 int mode = (int) request.argument;
1024 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1025 break;
1026 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 request.result = ar.exception == null;
1030 notifyRequester(request);
1031 break;
1032 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1033 request = (MainThreadRequest) msg.obj;
1034 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1035 int subscriptionMode = (int) request.argument;
1036 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1037 break;
1038 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
1041 request.result = ar.exception == null;
1042 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001043 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001044 case CMD_GET_ALL_CELL_INFO:
1045 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001047 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 case EVENT_GET_ALL_CELL_INFO_DONE:
1050 ar = (AsyncResult) msg.obj;
1051 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001052 // If a timeout occurs, the response will be null
1053 request.result = (ar.exception == null && ar.result != null)
1054 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 synchronized (request) {
1056 request.notifyAll();
1057 }
1058 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001059 case CMD_REQUEST_CELL_INFO_UPDATE:
1060 request = (MainThreadRequest) msg.obj;
1061 request.phone.requestCellInfoUpdate(request.workSource,
1062 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1063 break;
1064 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
1067 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1068 try {
1069 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001070 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001071 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1072 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001075 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 } else {
1077 // use the result as returned
1078 cb.onCellInfo((List<CellInfo>) ar.result);
1079 }
1080 } catch (RemoteException re) {
1081 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1082 }
1083 break;
1084 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001085 request = (MainThreadRequest) msg.obj;
1086 WorkSource ws = (WorkSource) request.argument;
1087 Phone phone = getPhoneFromRequest(request);
1088 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1089 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001091 ar = (AsyncResult) msg.obj;
1092 request = (MainThreadRequest) ar.userObj;
1093 if (ar.exception == null) {
1094 request.result = ar.result;
1095 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001097 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1098 ? new CdmaCellLocation() : new GsmCellLocation();
1099 }
1100
1101 synchronized (request) {
1102 request.notifyAll();
1103 }
1104 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001105 case CMD_MODEM_REBOOT:
1106 request = (MainThreadRequest) msg.obj;
1107 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001108 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001109 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001110 case EVENT_CMD_MODEM_REBOOT_DONE:
1111 handleNullReturnEvent(msg, "rebootModem");
1112 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001113 case CMD_REQUEST_ENABLE_MODEM:
1114 request = (MainThreadRequest) msg.obj;
1115 boolean enable = (boolean) request.argument;
1116 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001117 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001118 PhoneConfigurationManager.getInstance()
1119 .enablePhone(request.phone, enable, onCompleted);
1120 break;
1121 case EVENT_ENABLE_MODEM_DONE:
1122 ar = (AsyncResult) msg.obj;
1123 request = (MainThreadRequest) ar.userObj;
1124 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001125 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001126 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001127 if ((boolean) request.result) {
1128 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1129 updateModemStateMetrics();
1130 } else {
1131 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1132 + ar.exception);
1133 }
1134 notifyRequester(request);
1135 break;
1136 case CMD_GET_MODEM_STATUS:
1137 request = (MainThreadRequest) msg.obj;
1138 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1139 PhoneConfigurationManager.getInstance()
1140 .getPhoneStatusFromModem(request.phone, onCompleted);
1141 break;
1142 case EVENT_GET_MODEM_STATUS_DONE:
1143 ar = (AsyncResult) msg.obj;
1144 request = (MainThreadRequest) ar.userObj;
1145 int id = request.phone.getPhoneId();
1146 if (ar.exception == null && ar.result != null) {
1147 request.result = ar.result;
1148 //update the cache as modem status has changed
1149 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1150 (boolean) request.result);
1151 } else {
1152 // Return true if modem status cannot be retrieved. For most cases,
1153 // modem status is on. And for older version modems, GET_MODEM_STATUS
1154 // and disable modem are not supported. Modem is always on.
1155 // TODO: this should be fixed in R to support a third
1156 // status UNKNOWN b/131631629
1157 request.result = true;
1158 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1159 + ar.exception);
1160 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001161 notifyRequester(request);
1162 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001163 default:
1164 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1165 break;
1166 }
1167 }
Jake Hambye994d462014-02-03 13:10:13 -08001168
Pengquan Menga1bb6272018-09-06 09:59:22 -07001169 private void notifyRequester(MainThreadRequest request) {
1170 synchronized (request) {
1171 request.notifyAll();
1172 }
1173 }
1174
Jake Hambye994d462014-02-03 13:10:13 -08001175 private void handleNullReturnEvent(Message msg, String command) {
1176 AsyncResult ar = (AsyncResult) msg.obj;
1177 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1178 if (ar.exception == null) {
1179 request.result = true;
1180 } else {
1181 request.result = false;
1182 if (ar.exception instanceof CommandException) {
1183 loge(command + ": CommandException: " + ar.exception);
1184 } else {
1185 loge(command + ": Unknown exception");
1186 }
1187 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001188 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 }
1191
1192 /**
1193 * Posts the specified command to be executed on the main thread,
1194 * waits for the request to complete, and returns the result.
1195 * @see #sendRequestAsync
1196 */
1197 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001198 return sendRequest(
1199 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001200 }
1201
1202 /**
1203 * Posts the specified command to be executed on the main thread,
1204 * waits for the request to complete, and returns the result.
1205 * @see #sendRequestAsync
1206 */
1207 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1208 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001209 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001210 }
1211
1212 /**
1213 * Posts the specified command to be executed on the main thread,
1214 * waits for the request to complete, and returns the result.
1215 * @see #sendRequestAsync
1216 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001217 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001218 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001219 }
1220
1221 /**
1222 * Posts the specified command to be executed on the main thread,
1223 * waits for the request to complete, and returns the result.
1224 * @see #sendRequestAsync
1225 */
Nathan Harold92bed182018-10-12 18:16:49 -07001226 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1227 return sendRequest(command, argument, subId, null, workSource);
1228 }
1229
1230 /**
1231 * Posts the specified command to be executed on the main thread,
1232 * waits for the request to complete, and returns the result.
1233 * @see #sendRequestAsync
1234 */
1235 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1236 return sendRequest(
1237 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1238 }
1239
1240 /**
1241 * Posts the specified command to be executed on the main thread,
1242 * waits for the request to complete, and returns the result.
1243 * @see #sendRequestAsync
1244 */
1245 private Object sendRequest(
1246 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1248 throw new RuntimeException("This method will deadlock if called from the main thread.");
1249 }
1250
Nathan Harold92bed182018-10-12 18:16:49 -07001251 MainThreadRequest request = null;
1252 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1253 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1254 } else if (phone != null) {
1255 request = new MainThreadRequest(argument, phone, workSource);
1256 } else {
1257 request = new MainThreadRequest(argument, subId, workSource);
1258 }
1259
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 Message msg = mMainThreadHandler.obtainMessage(command, request);
1261 msg.sendToTarget();
1262
1263 // Wait for the request to complete
1264 synchronized (request) {
1265 while (request.result == null) {
1266 try {
1267 request.wait();
1268 } catch (InterruptedException e) {
1269 // Do nothing, go back and wait until the request is complete
1270 }
1271 }
1272 }
1273 return request.result;
1274 }
1275
1276 /**
1277 * Asynchronous ("fire and forget") version of sendRequest():
1278 * Posts the specified command to be executed on the main thread, and
1279 * returns immediately.
1280 * @see #sendRequest
1281 */
1282 private void sendRequestAsync(int command) {
1283 mMainThreadHandler.sendEmptyMessage(command);
1284 }
1285
1286 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001287 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001288 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001289 */
1290 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001291 sendRequestAsync(command, argument, null, null);
1292 }
1293
1294 /**
1295 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1296 * @see {@link #sendRequest(int,Object)}
1297 */
1298 private void sendRequestAsync(
1299 int command, Object argument, Phone phone, WorkSource workSource) {
1300 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001301 Message msg = mMainThreadHandler.obtainMessage(command, request);
1302 msg.sendToTarget();
1303 }
1304
1305 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 * Initialize the singleton PhoneInterfaceManager instance.
1307 * This is only done once, at startup, from PhoneApp.onCreate().
1308 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001309 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 synchronized (PhoneInterfaceManager.class) {
1311 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001312 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 } else {
1314 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1315 }
1316 return sInstance;
1317 }
1318 }
1319
1320 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001321 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001324 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1326 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001327 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001328 mTelephonySharedPreferences =
1329 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001330 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001331 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001332
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 publish();
1334 }
1335
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001336 private Phone getDefaultPhone() {
1337 Phone thePhone = getPhone(getDefaultSubscription());
1338 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1339 }
1340
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341 private void publish() {
1342 if (DBG) log("publish: " + this);
1343
1344 ServiceManager.addService("phone", this);
1345 }
1346
Stuart Scott584921c2015-01-15 17:10:34 -08001347 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001348 if (request.phone != null) {
1349 return request.phone;
1350 } else {
1351 return getPhoneFromSubId(request.subId);
1352 }
1353 }
1354
1355 private Phone getPhoneFromSubId(int subId) {
1356 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1357 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001358 }
1359
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001360 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1361 Phone phone = getPhoneFromRequest(request);
1362 return phone == null ? null :
1363 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1364 }
1365
Wink Saville36469e72014-06-11 15:17:00 -07001366 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001367 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001368 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001370
1371 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001372 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001373 }
1374
Wink Savilleb564aae2014-10-23 10:18:09 -07001375 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 if (DBG) log("dial: " + number);
1377 // No permission check needed here: This is just a wrapper around the
1378 // ACTION_DIAL intent, which is available to any app since it puts up
1379 // the UI before it does anything.
1380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001381 final long identity = Binder.clearCallingIdentity();
1382 try {
1383 String url = createTelUrl(number);
1384 if (url == null) {
1385 return;
1386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001388 // PENDING: should we just silently fail if phone is offhook or ringing?
1389 PhoneConstants.State state = mCM.getState(subId);
1390 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1391 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1392 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1393 mApp.startActivity(intent);
1394 }
1395 } finally {
1396 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 }
1398 }
1399
1400 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001401 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001402 }
1403
Wink Savilleb564aae2014-10-23 10:18:09 -07001404 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 if (DBG) log("call: " + number);
1406
1407 // This is just a wrapper around the ACTION_CALL intent, but we still
1408 // need to do a permission check since we're calling startActivity()
1409 // from the context of the phone app.
1410 enforceCallPermission();
1411
1412 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1413 != AppOpsManager.MODE_ALLOWED) {
1414 return;
1415 }
1416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001417 final long identity = Binder.clearCallingIdentity();
1418 try {
1419 String url = createTelUrl(number);
1420 if (url == null) {
1421 return;
1422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001424 boolean isValid = false;
1425 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1426 if (slist != null) {
1427 for (SubscriptionInfo subInfoRecord : slist) {
1428 if (subInfoRecord.getSubscriptionId() == subId) {
1429 isValid = true;
1430 break;
1431 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001432 }
Wink Saville08874612014-08-31 19:19:58 -07001433 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001434 if (!isValid) {
1435 return;
1436 }
Wink Saville08874612014-08-31 19:19:58 -07001437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001438 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1439 intent.putExtra(SUBSCRIPTION_KEY, subId);
1440 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1441 mApp.startActivity(intent);
1442 } finally {
1443 Binder.restoreCallingIdentity(identity);
1444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 }
1446
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001448 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001449 }
1450
Wink Savilleb564aae2014-10-23 10:18:09 -07001451 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001452 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001453 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1454 }
1455
1456 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001457 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001458 }
1459
Wink Savilleb564aae2014-10-23 10:18:09 -07001460 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001461 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001462 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1463 }
1464
1465 /** {@hide} */
1466 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001467 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001468 }
1469
Wink Savilleb564aae2014-10-23 10:18:09 -07001470 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001472
1473 final long identity = Binder.clearCallingIdentity();
1474 try {
1475 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1476 checkSimPin.start();
1477 return checkSimPin.unlockSim(null, pin);
1478 } finally {
1479 Binder.restoreCallingIdentity(identity);
1480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482
Wink Saville9de0f752013-10-22 19:04:03 -07001483 /** {@hide} */
1484 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001486 }
1487
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001490
1491 final long identity = Binder.clearCallingIdentity();
1492 try {
1493 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1494 checkSimPuk.start();
1495 return checkSimPuk.unlockSim(puk, pin);
1496 } finally {
1497 Binder.restoreCallingIdentity(identity);
1498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 }
1500
1501 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001502 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001503 * a synchronous one.
1504 */
1505 private static class UnlockSim extends Thread {
1506
1507 private final IccCard mSimCard;
1508
1509 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001510 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1511 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512
1513 // For replies from SimCard interface
1514 private Handler mHandler;
1515
1516 // For async handler to identify request type
1517 private static final int SUPPLY_PIN_COMPLETE = 100;
1518
1519 public UnlockSim(IccCard simCard) {
1520 mSimCard = simCard;
1521 }
1522
1523 @Override
1524 public void run() {
1525 Looper.prepare();
1526 synchronized (UnlockSim.this) {
1527 mHandler = new Handler() {
1528 @Override
1529 public void handleMessage(Message msg) {
1530 AsyncResult ar = (AsyncResult) msg.obj;
1531 switch (msg.what) {
1532 case SUPPLY_PIN_COMPLETE:
1533 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1534 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001535 mRetryCount = msg.arg1;
1536 if (ar.exception != null) {
1537 if (ar.exception instanceof CommandException &&
1538 ((CommandException)(ar.exception)).getCommandError()
1539 == CommandException.Error.PASSWORD_INCORRECT) {
1540 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1541 } else {
1542 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1543 }
1544 } else {
1545 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 mDone = true;
1548 UnlockSim.this.notifyAll();
1549 }
1550 break;
1551 }
1552 }
1553 };
1554 UnlockSim.this.notifyAll();
1555 }
1556 Looper.loop();
1557 }
1558
1559 /*
1560 * Use PIN or PUK to unlock SIM card
1561 *
1562 * If PUK is null, unlock SIM card with PIN
1563 *
1564 * If PUK is not null, unlock SIM card with PUK and set PIN code
1565 */
Wink Saville9de0f752013-10-22 19:04:03 -07001566 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567
1568 while (mHandler == null) {
1569 try {
1570 wait();
1571 } catch (InterruptedException e) {
1572 Thread.currentThread().interrupt();
1573 }
1574 }
1575 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1576
1577 if (puk == null) {
1578 mSimCard.supplyPin(pin, callback);
1579 } else {
1580 mSimCard.supplyPuk(puk, pin, callback);
1581 }
1582
1583 while (!mDone) {
1584 try {
1585 Log.d(LOG_TAG, "wait for done");
1586 wait();
1587 } catch (InterruptedException e) {
1588 // Restore the interrupted status
1589 Thread.currentThread().interrupt();
1590 }
1591 }
1592 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001593 int[] resultArray = new int[2];
1594 resultArray[0] = mResult;
1595 resultArray[1] = mRetryCount;
1596 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 }
1598 }
1599
1600 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001601 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001602
1603 }
1604
Wink Savilleb564aae2014-10-23 10:18:09 -07001605 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 // No permission check needed here: this call is harmless, and it's
1607 // needed for the ServiceState.requestStateUpdate() call (which is
1608 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001609 final long identity = Binder.clearCallingIdentity();
1610 try {
1611 final Phone phone = getPhone(subId);
1612 if (phone != null) {
1613 phone.updateServiceLocation();
1614 }
1615 } finally {
1616 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 }
1619
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001620 @Override
1621 public boolean isRadioOn(String callingPackage) {
1622 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001623 }
1624
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001625 @Override
1626 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001628 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001629 return false;
1630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001631
1632 final long identity = Binder.clearCallingIdentity();
1633 try {
1634 return isRadioOnForSubscriber(subId);
1635 } finally {
1636 Binder.restoreCallingIdentity(identity);
1637 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001638 }
1639
1640 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001641 final long identity = Binder.clearCallingIdentity();
1642 try {
1643 final Phone phone = getPhone(subId);
1644 if (phone != null) {
1645 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1646 } else {
1647 return false;
1648 }
1649 } finally {
1650 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653
1654 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001655 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 }
Wink Saville36469e72014-06-11 15:17:00 -07001657
Wink Savilleb564aae2014-10-23 10:18:09 -07001658 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001660
1661 final long identity = Binder.clearCallingIdentity();
1662 try {
1663 final Phone phone = getPhone(subId);
1664 if (phone != null) {
1665 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1666 }
1667 } finally {
1668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001669 }
Wink Saville36469e72014-06-11 15:17:00 -07001670 }
1671
1672 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001673 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001674 }
1675
Wink Savilleb564aae2014-10-23 10:18:09 -07001676 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001677 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001678
1679 final long identity = Binder.clearCallingIdentity();
1680 try {
1681 final Phone phone = getPhone(subId);
1682 if (phone == null) {
1683 return false;
1684 }
1685 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1686 toggleRadioOnOffForSubscriber(subId);
1687 }
1688 return true;
1689 } finally {
1690 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 }
Wink Saville36469e72014-06-11 15:17:00 -07001693
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001694 public boolean needMobileRadioShutdown() {
1695 /*
1696 * If any of the Radios are available, it will need to be
1697 * shutdown. So return true if any Radio is available.
1698 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001699 final long identity = Binder.clearCallingIdentity();
1700 try {
1701 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1702 Phone phone = PhoneFactory.getPhone(i);
1703 if (phone != null && phone.isRadioAvailable()) return true;
1704 }
1705 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1706 return false;
1707 } finally {
1708 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001709 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001710 }
1711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001712 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001713 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001714 enforceModifyPermission();
1715
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1719 logv("Shutting down Phone " + i);
1720 shutdownRadioUsingPhoneId(i);
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001724 }
1725 }
1726
1727 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001728 Phone phone = PhoneFactory.getPhone(phoneId);
1729 if (phone != null && phone.isRadioAvailable()) {
1730 phone.shutdownRadio();
1731 }
1732 }
1733
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001735 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001736
1737 final long identity = Binder.clearCallingIdentity();
1738 try {
1739 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1740 if (defaultPhone != null) {
1741 defaultPhone.setRadioPower(turnOn);
1742 return true;
1743 } else {
1744 loge("There's no default phone.");
1745 return false;
1746 }
1747 } finally {
1748 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001749 }
Wink Saville36469e72014-06-11 15:17:00 -07001750 }
1751
Wink Savilleb564aae2014-10-23 10:18:09 -07001752 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001754
1755 final long identity = Binder.clearCallingIdentity();
1756 try {
1757 final Phone phone = getPhone(subId);
1758 if (phone != null) {
1759 phone.setRadioPower(turnOn);
1760 return true;
1761 } else {
1762 return false;
1763 }
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 }
1768
Wink Saville36469e72014-06-11 15:17:00 -07001769 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001770 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 public boolean enableDataConnectivity() {
1772 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001773
1774 final long identity = Binder.clearCallingIdentity();
1775 try {
1776 int subId = mSubscriptionController.getDefaultDataSubId();
1777 final Phone phone = getPhone(subId);
1778 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001779 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001780 return true;
1781 } else {
1782 return false;
1783 }
1784 } finally {
1785 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 }
1788
Wink Saville36469e72014-06-11 15:17:00 -07001789 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001790 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 public boolean disableDataConnectivity() {
1792 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001793
1794 final long identity = Binder.clearCallingIdentity();
1795 try {
1796 int subId = mSubscriptionController.getDefaultDataSubId();
1797 final Phone phone = getPhone(subId);
1798 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001799 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800 return true;
1801 } else {
1802 return false;
1803 }
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
1808
Sanket Padawe356d7632015-06-22 14:03:32 -07001809 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001810 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001811 final long identity = Binder.clearCallingIdentity();
1812 try {
1813 final Phone phone = getPhone(subId);
1814 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001815 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001816 } else {
1817 return false;
1818 }
1819 } finally {
1820 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 }
1823
1824 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001825 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001826 }
1827
pkanwarae03a6b2016-11-06 20:37:09 -08001828 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001829 enforceCallPermission();
1830
1831 final long identity = Binder.clearCallingIdentity();
1832 try {
1833 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1834 return;
1835 }
1836 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1837 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1838 } finally {
1839 Binder.restoreCallingIdentity(identity);
1840 }
pkanwar32d516d2016-10-14 19:37:38 -07001841 };
1842
Wink Savilleb564aae2014-10-23 10:18:09 -07001843 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001845
1846 final long identity = Binder.clearCallingIdentity();
1847 try {
1848 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1849 return false;
1850 }
1851 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1852 } finally {
1853 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855 }
1856
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001858 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001859 }
1860
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001861 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001862 final long identity = Binder.clearCallingIdentity();
1863 try {
1864 Phone phone = PhoneFactory.getPhone(slotIndex);
1865 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1866 PhoneConstantConversions.convertCallState(phone.getState());
1867 } finally {
1868 Binder.restoreCallingIdentity(identity);
1869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 }
1871
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001874 final long identity = Binder.clearCallingIdentity();
1875 try {
1876 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1877 if (phone != null) {
1878 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1879 } else {
1880 return PhoneConstantConversions.convertDataState(
1881 PhoneConstants.DataState.DISCONNECTED);
1882 }
1883 } finally {
1884 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 }
1887
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001890 final long identity = Binder.clearCallingIdentity();
1891 try {
1892 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1893 if (phone != null) {
1894 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1895 } else {
1896 return TelephonyManager.DATA_ACTIVITY_NONE;
1897 }
1898 } finally {
1899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 }
1902
1903 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001904 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001905 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001906 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001907
1908 LocationAccessPolicy.LocationPermissionResult locationResult =
1909 LocationAccessPolicy.checkLocationPermission(mApp,
1910 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1911 .setCallingPackage(callingPackage)
1912 .setCallingPid(Binder.getCallingPid())
1913 .setCallingUid(Binder.getCallingUid())
1914 .setMethod("getCellLocation")
1915 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1916 .build());
1917 switch (locationResult) {
1918 case DENIED_HARD:
1919 throw new SecurityException("Not allowed to access cell location");
1920 case DENIED_SOFT:
1921 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001924 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001925 final long identity = Binder.clearCallingIdentity();
1926 try {
1927 if (DBG_LOC) log("getCellLocation: is active user");
1928 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001929 int subId = mSubscriptionController.getDefaultDataSubId();
1930 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1931 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001932 return data;
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
1935 }
Svetoslav64fad262015-04-14 14:35:21 -07001936 }
1937
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001939 public String getNetworkCountryIsoForPhone(int phoneId) {
1940 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1941 // registered cell info, so return a NULL country instead.
1942 final long identity = Binder.clearCallingIdentity();
1943 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001944 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1945 // Get default phone in this case.
1946 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1947 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001948 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001949 // Todo: fix this when we can get the actual cellular network info when the device
1950 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001951 if (TelephonyManager.NETWORK_TYPE_IWLAN
1952 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1953 return "";
1954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 Phone phone = PhoneFactory.getPhone(phoneId);
1956 if (phone != null) {
1957 ServiceStateTracker sst = phone.getServiceStateTracker();
1958 if (sst != null) {
1959 LocaleTracker lt = sst.getLocaleTracker();
1960 if (lt != null) {
1961 return lt.getCurrentCountry();
1962 }
1963 }
1964 }
1965 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001966 } finally {
1967 Binder.restoreCallingIdentity(identity);
1968 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001969 }
1970
1971 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001973 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001974 }
1975
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001977 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 mApp.enforceCallingOrSelfPermission(
1979 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980
1981 final long identity = Binder.clearCallingIdentity();
1982 try {
1983 final Phone phone = getPhone(subId);
1984 if (phone != null) {
1985 phone.enableLocationUpdates();
1986 }
1987 } finally {
1988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 }
1991
1992 @Override
1993 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001994 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001995 }
1996
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001998 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 mApp.enforceCallingOrSelfPermission(
2000 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001
2002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 final Phone phone = getPhone(subId);
2005 if (phone != null) {
2006 phone.disableLocationUpdates();
2007 }
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
2012
Nathan Harold31d7ff32018-10-15 20:20:30 -07002013 /**
2014 * Returns the target SDK version number for a given package name.
2015 *
2016 * @return target SDK if the package is found or INT_MAX.
2017 */
2018 private int getTargetSdk(String packageName) {
2019 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002020 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2021 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002022 if (ai != null) return ai.targetSdkVersion;
2023 } catch (PackageManager.NameNotFoundException unexpected) {
2024 }
2025 return Integer.MAX_VALUE;
2026 }
2027
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 @Override
2029 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002030 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2031 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002032 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2033 throw new SecurityException(
2034 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2035 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002036
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2038 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2039 return null;
2040 }
Svetoslav64fad262015-04-14 14:35:21 -07002041
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002042 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043
Nathan Haroldf180aac2018-06-01 18:43:55 -07002044 List<CellInfo> info = getAllCellInfo(callingPackage);
2045 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046
Nathan Haroldf180aac2018-06-01 18:43:55 -07002047 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2048 for (CellInfo ci : info) {
2049 if (ci instanceof CellInfoGsm) {
2050 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2051 } else if (ci instanceof CellInfoWcdma) {
2052 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002055 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 }
2057
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002058 private List<CellInfo> getCachedCellInfo() {
2059 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2060 for (Phone phone : PhoneFactory.getPhones()) {
2061 List<CellInfo> info = phone.getAllCellInfo();
2062 if (info != null) cellInfos.addAll(info);
2063 }
2064 return cellInfos;
2065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066
2067 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002068 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002069 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002070 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002071
2072 LocationAccessPolicy.LocationPermissionResult locationResult =
2073 LocationAccessPolicy.checkLocationPermission(mApp,
2074 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2075 .setCallingPackage(callingPackage)
2076 .setCallingPid(Binder.getCallingPid())
2077 .setCallingUid(Binder.getCallingUid())
2078 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002079 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002080 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2081 .build());
2082 switch (locationResult) {
2083 case DENIED_HARD:
2084 throw new SecurityException("Not allowed to access cell info");
2085 case DENIED_SOFT:
2086 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 }
2088
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002089 final int targetSdk = getTargetSdk(callingPackage);
2090 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2091 return getCachedCellInfo();
2092 }
2093
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002094 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002095 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002096 final long identity = Binder.clearCallingIdentity();
2097 try {
2098 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2099 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002100 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002101 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102 if (info != null) cellInfos.addAll(info);
2103 }
2104 return cellInfos;
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 }
2108 }
2109
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002110 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002111 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2112 requestCellInfoUpdateInternal(
2113 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2114 }
2115
2116 @Override
2117 public void requestCellInfoUpdateWithWorkSource(
2118 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2119 enforceModifyPermission();
2120 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2121 }
2122
2123 private void requestCellInfoUpdateInternal(
2124 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002125 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002126 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002127
2128 LocationAccessPolicy.LocationPermissionResult locationResult =
2129 LocationAccessPolicy.checkLocationPermission(mApp,
2130 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2131 .setCallingPackage(callingPackage)
2132 .setCallingPid(Binder.getCallingPid())
2133 .setCallingUid(Binder.getCallingUid())
2134 .setMethod("requestCellInfoUpdate")
2135 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2136 .build());
2137 switch (locationResult) {
2138 case DENIED_HARD:
2139 throw new SecurityException("Not allowed to access cell info");
2140 case DENIED_SOFT:
Nathan Haroldb3c5da42019-05-09 10:26:08 -07002141 try {
2142 cb.onCellInfo(new ArrayList<CellInfo>());
2143 } catch (RemoteException re) {
2144 // Drop without consequences
2145 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002146 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002147 }
2148
Nathan Harold32e84c42019-05-09 10:13:47 -07002149
2150 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002151 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2152
2153 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2154 }
2155
2156 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002158 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002159 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160
2161 final long identity = Binder.clearCallingIdentity();
2162 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002163 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002164 } finally {
2165 Binder.restoreCallingIdentity(identity);
2166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
Shishir Agrawala9f32182016-04-12 12:00:16 -07002169 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002170 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002171 Phone phone = PhoneFactory.getPhone(slotIndex);
2172 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002173 return null;
2174 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002175 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002176 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2177 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002178 return null;
2179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180
2181 final long identity = Binder.clearCallingIdentity();
2182 try {
2183 return phone.getImei();
2184 } finally {
2185 Binder.restoreCallingIdentity(identity);
2186 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002187 }
2188
2189 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002190 public String getTypeAllocationCodeForSlot(int slotIndex) {
2191 Phone phone = PhoneFactory.getPhone(slotIndex);
2192 String tac = null;
2193 if (phone != null) {
2194 String imei = phone.getImei();
2195 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2196 }
2197 return tac;
2198 }
2199
2200 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002201 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002202 Phone phone = PhoneFactory.getPhone(slotIndex);
2203 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002204 return null;
2205 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002206
Jeff Davidson913390f2018-02-23 17:11:49 -08002207 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002208 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2209 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002210 return null;
2211 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002212
2213 final long identity = Binder.clearCallingIdentity();
2214 try {
2215 return phone.getMeid();
2216 } finally {
2217 Binder.restoreCallingIdentity(identity);
2218 }
Jack Yu2af8d712017-03-15 17:14:14 -07002219 }
2220
2221 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002222 public String getManufacturerCodeForSlot(int slotIndex) {
2223 Phone phone = PhoneFactory.getPhone(slotIndex);
2224 String manufacturerCode = null;
2225 if (phone != null) {
2226 String meid = phone.getMeid();
2227 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2228 }
2229 return manufacturerCode;
2230 }
2231
2232 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002233 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002234 Phone phone = PhoneFactory.getPhone(slotIndex);
2235 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002236 return null;
2237 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002238 int subId = phone.getSubId();
2239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2240 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2241 return null;
2242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243
2244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 return phone.getDeviceSvn();
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
2249 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002250 }
2251
fionaxu43304da2017-11-27 22:51:16 -08002252 @Override
2253 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002254 final long identity = Binder.clearCallingIdentity();
2255 try {
2256 final Phone phone = getPhone(subId);
2257 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2258 } finally {
2259 Binder.restoreCallingIdentity(identity);
2260 }
fionaxu43304da2017-11-27 22:51:16 -08002261 }
2262
2263 @Override
2264 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002265 final long identity = Binder.clearCallingIdentity();
2266 try {
2267 final Phone phone = getPhone(subId);
2268 return phone == null ? null : phone.getCarrierName();
2269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
fionaxu43304da2017-11-27 22:51:16 -08002272 }
2273
calvinpanffe225e2018-11-01 19:43:06 +08002274 @Override
chen xu0026ca62019-03-06 15:28:50 -08002275 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002276 final long identity = Binder.clearCallingIdentity();
2277 try {
2278 final Phone phone = getPhone(subId);
2279 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002280 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002281 } finally {
2282 Binder.restoreCallingIdentity(identity);
2283 }
2284 }
2285
2286 @Override
chen xu0026ca62019-03-06 15:28:50 -08002287 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002291 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002292 } finally {
2293 Binder.restoreCallingIdentity(identity);
2294 }
2295 }
2296
chen xu651eec72018-11-11 19:03:44 -08002297 @Override
chen xu864e11c2018-12-06 22:10:03 -08002298 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2299 if (!isSubscriptionMccMnc) {
2300 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2301 }
chen xu651eec72018-11-11 19:03:44 -08002302 final Phone phone = PhoneFactory.getPhone(slotIndex);
2303 if (phone == null) {
2304 return TelephonyManager.UNKNOWN_CARRIER_ID;
2305 }
2306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
2311 }
2312 }
2313
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 //
2315 // Internal helper methods.
2316 //
2317
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002318 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2320 *
2321 * @throws SecurityException if the caller does not have the required permission
2322 */
2323 private void enforceModifyPermission() {
2324 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2325 }
2326
2327 /**
2328 * Make sure the caller has the CALL_PHONE permission.
2329 *
2330 * @throws SecurityException if the caller does not have the required permission
2331 */
2332 private void enforceCallPermission() {
2333 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2334 }
2335
Stuart Scott8eef64f2015-04-08 15:13:54 -07002336 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002337 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002338 "ConnectivityService");
2339 }
2340
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 private String createTelUrl(String number) {
2342 if (TextUtils.isEmpty(number)) {
2343 return null;
2344 }
2345
Jake Hambye994d462014-02-03 13:10:13 -08002346 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 }
2348
Ihab Awadf9e92732013-12-05 18:02:52 -08002349 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2351 }
2352
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002353 private static void logv(String msg) {
2354 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2355 }
2356
Ihab Awadf9e92732013-12-05 18:02:52 -08002357 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2359 }
2360
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002361 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002363 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002364 }
2365
Sanket Padawe356d7632015-06-22 14:03:32 -07002366 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002367 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002368 final long identity = Binder.clearCallingIdentity();
2369 try {
2370 final Phone phone = PhoneFactory.getPhone(slotIndex);
2371 if (phone == null) {
2372 return PhoneConstants.PHONE_TYPE_NONE;
2373 } else {
2374 return phone.getPhoneType();
2375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 }
2380
2381 /**
2382 * Returns the CDMA ERI icon index to display
2383 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002384 @Override
2385 public int getCdmaEriIconIndex(String callingPackage) {
2386 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002387 }
2388
Sanket Padawe356d7632015-06-22 14:03:32 -07002389 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002390 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002392 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002393 return -1;
2394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002395
2396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 final Phone phone = getPhone(subId);
2399 if (phone != null) {
2400 return phone.getCdmaEriIconIndex();
2401 } else {
2402 return -1;
2403 }
2404 } finally {
2405 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 }
2408
2409 /**
2410 * Returns the CDMA ERI icon mode,
2411 * 0 - ON
2412 * 1 - FLASHING
2413 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002414 @Override
2415 public int getCdmaEriIconMode(String callingPackage) {
2416 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002417 }
2418
Sanket Padawe356d7632015-06-22 14:03:32 -07002419 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002420 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002422 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002423 return -1;
2424 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425
2426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 final Phone phone = getPhone(subId);
2429 if (phone != null) {
2430 return phone.getCdmaEriIconMode();
2431 } else {
2432 return -1;
2433 }
2434 } finally {
2435 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 }
2438
2439 /**
2440 * Returns the CDMA ERI text,
2441 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002442 @Override
2443 public String getCdmaEriText(String callingPackage) {
2444 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002445 }
2446
Sanket Padawe356d7632015-06-22 14:03:32 -07002447 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002448 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002449 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002450 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002451 return null;
2452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453
2454 final long identity = Binder.clearCallingIdentity();
2455 try {
2456 final Phone phone = getPhone(subId);
2457 if (phone != null) {
2458 return phone.getCdmaEriText();
2459 } else {
2460 return null;
2461 }
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 }
2466
2467 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002468 * Returns the CDMA MDN.
2469 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002470 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002471 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2473 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474
2475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002478 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002479 return phone.getLine1Number();
2480 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002481 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 return null;
2483 }
2484 } finally {
2485 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002486 }
2487 }
2488
2489 /**
2490 * Returns the CDMA MIN.
2491 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002492 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002493 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2495 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496
2497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 final Phone phone = getPhone(subId);
2500 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2501 return phone.getCdmaMin();
2502 } else {
2503 return null;
2504 }
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002507 }
2508 }
2509
Hall Liud892bec2018-11-30 14:51:45 -08002510 @Override
2511 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2512 INumberVerificationCallback callback, String callingPackage) {
2513 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2514 != PERMISSION_GRANTED) {
2515 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2516 }
2517 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2518
2519 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2520 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2521 throw new SecurityException("Calling package must be configured in the device config");
2522 }
2523
2524 if (range == null) {
2525 throw new NullPointerException("Range must be non-null");
2526 }
2527
2528 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002529 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002530
2531 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2532 }
2533
Junda Liuca05d5d2014-08-14 22:36:34 -07002534 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 * Returns true if CDMA provisioning needs to run.
2536 */
2537 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538 final long identity = Binder.clearCallingIdentity();
2539 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002540 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 } finally {
2542 Binder.restoreCallingIdentity(identity);
2543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002544 }
2545
2546 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002547 * Sets the voice mail number of a given subId.
2548 */
2549 @Override
2550 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002551 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2556 new Pair<String, String>(alphaTag, number), new Integer(subId));
2557 return success;
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
2560 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002561 }
2562
Ta-wei Yen87c49842016-05-13 21:19:52 -07002563 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002564 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2565 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002566 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002567 if (!TextUtils.equals(callingPackage, systemDialer)) {
2568 throw new SecurityException("caller must be system dialer");
2569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2574 if (phoneAccountHandle == null) {
2575 return null;
2576 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002577 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002580 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002581 }
2582
2583 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002584 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002587 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002588 return null;
2589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002591 final long identity = Binder.clearCallingIdentity();
2592 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002593 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002594 } finally {
2595 Binder.restoreCallingIdentity(identity);
2596 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002597 }
2598
2599 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002600 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2601 VisualVoicemailSmsFilterSettings settings) {
2602 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603
2604 final long identity = Binder.clearCallingIdentity();
2605 try {
2606 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002607 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608 } finally {
2609 Binder.restoreCallingIdentity(identity);
2610 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002611 }
2612
2613 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002614 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2615 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616
2617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002620 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 } finally {
2622 Binder.restoreCallingIdentity(identity);
2623 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002624 }
2625
2626 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002627 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2628 String callingPackage, int subId) {
2629 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630
2631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002634 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635 } finally {
2636 Binder.restoreCallingIdentity(identity);
2637 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002638 }
2639
2640 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002641 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002642 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643
2644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002647 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 } finally {
2649 Binder.restoreCallingIdentity(identity);
2650 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002651 }
2652
2653 @Override
2654 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2655 String number, int port, String text, PendingIntent sentIntent) {
2656 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002657 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002658 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002659 SmsController smsController = PhoneFactory.getSmsController();
2660 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2661 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002662 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002663
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002664 /**
fionaxu0152e512016-11-14 13:36:14 -08002665 * Sets the voice activation state of a given subId.
2666 */
2667 @Override
2668 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2670 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671
2672 final long identity = Binder.clearCallingIdentity();
2673 try {
2674 final Phone phone = getPhone(subId);
2675 if (phone != null) {
2676 phone.setVoiceActivationState(activationState);
2677 } else {
2678 loge("setVoiceActivationState fails with invalid subId: " + subId);
2679 }
2680 } finally {
2681 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002682 }
2683 }
2684
2685 /**
2686 * Sets the data activation state of a given subId.
2687 */
2688 @Override
2689 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2691 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692
2693 final long identity = Binder.clearCallingIdentity();
2694 try {
2695 final Phone phone = getPhone(subId);
2696 if (phone != null) {
2697 phone.setDataActivationState(activationState);
2698 } else {
2699 loge("setVoiceActivationState fails with invalid subId: " + subId);
2700 }
2701 } finally {
2702 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002703 }
2704 }
2705
2706 /**
2707 * Returns the voice activation state of a given subId.
2708 */
2709 @Override
2710 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002711 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712
fionaxu0152e512016-11-14 13:36:14 -08002713 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 if (phone != null) {
2717 return phone.getVoiceActivationState();
2718 } else {
2719 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2720 }
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002723 }
2724 }
2725
2726 /**
2727 * Returns the data activation state of a given subId.
2728 */
2729 @Override
2730 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002731 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732
fionaxu0152e512016-11-14 13:36:14 -08002733 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 if (phone != null) {
2737 return phone.getDataActivationState();
2738 } else {
2739 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2740 }
2741 } finally {
2742 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002743 }
2744 }
2745
2746 /**
Wink Saville36469e72014-06-11 15:17:00 -07002747 * Returns the unread count of voicemails for a subId
2748 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002749 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002750 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2752 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2753 return 0;
2754 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 final Phone phone = getPhone(subId);
2758 if (phone != null) {
2759 return phone.getVoiceMessageCount();
2760 } else {
2761 return 0;
2762 }
2763 } finally {
2764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 }
2767
2768 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002769 * returns true, if the device is in a state where both voice and data
2770 * are supported simultaneously. This can change based on location or network condition.
2771 */
2772 @Override
2773 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 final long identity = Binder.clearCallingIdentity();
2775 try {
2776 final Phone phone = getPhone(subId);
2777 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2778 } finally {
2779 Binder.restoreCallingIdentity(identity);
2780 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002781 }
2782
2783 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002784 * Send the dialer code if called from the current default dialer or the caller has
2785 * carrier privilege.
2786 * @param inputCode The dialer code to send
2787 */
2788 @Override
2789 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002790 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002791 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002792 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2793 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002794 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002795 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2796 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002801 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 } finally {
2803 Binder.restoreCallingIdentity(identity);
2804 }
fionaxu235cc5e2017-03-06 22:25:57 -08002805 }
2806
2807 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002808 * Returns the data network type.
2809 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 *
2811 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2812 */
2813 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002814 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 final Phone phone = getPhone(getDefaultSubscription());
2818 if (phone != null) {
2819 return phone.getServiceState().getDataNetworkType();
2820 } else {
2821 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2822 }
2823 } finally {
2824 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002825 }
Wink Saville36469e72014-06-11 15:17:00 -07002826 }
2827
Pengquan Menga1bb6272018-09-06 09:59:22 -07002828 @Override
2829 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002830 if (!isActiveSubscription(subId)) {
2831 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2832 }
2833
Pengquan Menga1bb6272018-09-06 09:59:22 -07002834 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2835 }
2836
Brad Ebinger35c841c2018-10-01 10:40:55 -07002837 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002838 public boolean isInEmergencySmsMode() {
2839 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 for (Phone phone : PhoneFactory.getPhones()) {
2843 if (phone.isInEmergencySmsMode()) {
2844 return true;
2845 }
2846 }
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
2849 }
2850 return false;
2851 }
2852
2853 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002854 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2855 throws RemoteException {
2856 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002857 final long token = Binder.clearCallingIdentity();
2858 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002860 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002861 .addRegistrationCallbackForSubscription(c, subId);
2862 } finally {
2863 Binder.restoreCallingIdentity(token);
2864 }
2865 }
2866
2867 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002868 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2869 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002870 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2871 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2872 }
2873 Binder.withCleanCallingIdentity(() -> {
2874 try {
2875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002876 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002877 .removeRegistrationCallbackForSubscription(c, subId);
2878 } catch (IllegalArgumentException e) {
2879 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2880 + "is inactive, ignoring unregister.");
2881 // If the subscription is no longer active, just return, since the callback
2882 // will already have been removed internally.
2883 }
2884 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002885 }
2886
2887 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002888 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2889 throws RemoteException {
2890 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2892 final long token = Binder.clearCallingIdentity();
2893 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002894 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002895 .addCapabilitiesCallbackForSubscription(c, subId);
2896 } finally {
2897 Binder.restoreCallingIdentity(token);
2898 }
2899 }
2900
2901 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002902 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2903 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002904
2905 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2906 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2907 }
2908 Binder.withCleanCallingIdentity(() -> {
2909 try {
2910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002911 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002912 .removeCapabilitiesCallbackForSubscription(c, subId);
2913 } catch (IllegalArgumentException e) {
2914 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2915 + "is inactive, ignoring unregister.");
2916 // If the subscription is no longer active, just return, since the callback
2917 // will already have been removed internally.
2918 }
2919 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002920 }
2921
2922 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002923 public boolean isCapable(int subId, int capability, int regTech) {
2924 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2926 final long token = Binder.clearCallingIdentity();
2927 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002928 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002929 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2930 } catch (ImsException e) {
2931 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2932 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002933 } catch (IllegalArgumentException e) {
2934 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2935 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002936 } finally {
2937 Binder.restoreCallingIdentity(token);
2938 }
2939 }
2940
2941 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002942 public boolean isAvailable(int subId, int capability, int regTech) {
2943 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002944 final long token = Binder.clearCallingIdentity();
2945 try {
2946 Phone phone = getPhone(subId);
2947 if (phone == null) return false;
2948 return phone.isImsCapabilityAvailable(capability, regTech);
2949 } finally {
2950 Binder.restoreCallingIdentity(token);
2951 }
2952 }
2953
2954 @Override
2955 public boolean isAdvancedCallingSettingEnabled(int subId) {
2956 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2958 final long token = Binder.clearCallingIdentity();
2959 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002960 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2962 } finally {
2963 Binder.restoreCallingIdentity(token);
2964 }
2965 }
2966
2967 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002968 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002970 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002974 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002975 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
2979 }
2980
2981 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002982 public boolean isVtSettingEnabled(int subId) {
2983 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 getSlotIndexOrException(subId)).isVtEnabledByUser();
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
2992 }
2993
2994 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002995 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002997 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003001 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
3005 }
3006
3007 @Override
3008 public boolean isVoWiFiSettingEnabled(int subId) {
3009 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003013 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003014 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
3018 }
3019
3020 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003021 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003023 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003027 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
3031 }
3032
3033 @Override
3034 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3035 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003039 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003040 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
3046 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003047 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003049 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003053 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003054 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3055 } finally {
3056 Binder.restoreCallingIdentity(identity);
3057 }
3058 }
3059
3060 @Override
3061 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3063 "setVoWiFiNonPersistent");
3064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003067 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003068 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
3072 }
3073
3074 @Override
3075 public int getVoWiFiModeSetting(int subId) {
3076 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3077 final long identity = Binder.clearCallingIdentity();
3078 try {
3079 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003080 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003081 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
3084 }
3085 }
3086
3087 @Override
3088 public void setVoWiFiModeSetting(int subId, int mode) {
3089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3090 "setVoWiFiModeSetting");
3091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003094 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003095 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
3099 }
3100
3101 @Override
3102 public int getVoWiFiRoamingModeSetting(int subId) {
3103 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003107 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
3112 }
3113
3114 @Override
3115 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3117 "setVoWiFiRoamingModeSetting");
3118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003121 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
3125 }
3126 }
3127
3128 @Override
3129 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3131 "setRttCapabilityEnabled");
3132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003135 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
3140 }
3141
3142 @Override
3143 public boolean isTtyOverVolteEnabled(int subId) {
3144 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003148 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
3153 }
3154
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003155 @Override
3156 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3157 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003161 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003162 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
3166 }
3167
3168 @Override
3169 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3170 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3171 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003172 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3173 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3174 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003175 try {
3176 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003178 .removeProvisioningCallbackForSubscription(callback, subId);
3179 } catch (IllegalArgumentException e) {
3180 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3181 + "is inactive, ignoring unregister.");
3182 // If the subscription is no longer active, just return, since the callback will already
3183 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
3187 }
3188
3189 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003190 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3191 boolean isProvisioned) {
3192 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3193 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3194 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3195 }
3196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3197 "setProvisioningStatusForCapability");
3198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3201 Phone phone = getPhone(subId);
3202 if (phone == null) {
3203 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3204 + subId);
3205 return;
3206 }
3207 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3208 return;
3209 }
3210
3211 // this capability requires provisioning, route to the correct API.
3212 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3213 switch (capability) {
3214 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3215 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3216 ims.setVolteProvisioned(isProvisioned);
3217 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3218 ims.setWfcProvisioned(isProvisioned);
3219 }
3220 break;
3221 }
3222 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3223 // There is currently no difference in VT provisioning type.
3224 ims.setVtProvisioned(isProvisioned);
3225 break;
3226 }
3227 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3228 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3229 // change the capability of the feature instead if needed.
3230 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3231 == isProvisioned) {
3232 // No change in provisioning.
3233 return;
3234 }
3235 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3236 try {
3237 ims.changeMmTelCapability(capability, tech, isProvisioned);
3238 } catch (ImsException e) {
3239 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3240 + ", Exception" + e.getMessage());
3241 }
3242 break;
3243 }
3244 default: {
3245 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3246 + capability + "', which does not require provisioning.");
3247 }
3248 }
3249
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
3252 }
3253 }
3254
3255 @Override
3256 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3257 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3258 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3259 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3260 }
3261 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3265 Phone phone = getPhone(subId);
3266 if (phone == null) {
3267 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3268 + subId);
3269 // We will fail with "true" as the provisioning status because this is the default
3270 // if we do not require provisioning.
3271 return true;
3272 }
3273
3274 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3275 return true;
3276 }
3277
3278 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3279 switch (capability) {
3280 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3281 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3282 return ims.isVolteProvisionedOnDevice();
3283 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3284 return ims.isWfcProvisionedOnDevice();
3285 }
3286 // This should never happen, since we are checking tech above to make sure it
3287 // is either LTE or IWLAN.
3288 throw new IllegalArgumentException("Invalid radio technology for voice "
3289 + "capability.");
3290 }
3291 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3292 // There is currently no difference in VT provisioning type.
3293 return ims.isVtProvisionedOnDevice();
3294 }
3295 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3296 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3297 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3298 }
3299 default: {
3300 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3301 + capability + "', which does not require provisioning.");
3302 }
3303 }
3304
3305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
3308 }
3309
3310 @Override
3311 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3312 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3313 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3314 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3315 }
3316 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3317 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3318 return (provisionedBits & capability) > 0;
3319 }
3320
3321 @Override
3322 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3323 boolean isProvisioned) {
3324 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3325 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3326 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3327 }
3328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3329 "setProvisioningStatusForCapability");
3330 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3331 // If the current provisioning status for capability already matches isProvisioned,
3332 // do nothing.
3333 if (((provisionedBits & capability) > 0) == isProvisioned) {
3334 return;
3335 }
3336 if (isProvisioned) {
3337 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3338 } else {
3339 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3340 }
3341 }
3342
3343 /**
3344 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3345 * technology. The bitfield should mirror the bitfield defined by
3346 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3347 */
3348 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3349 String key = getMmTelProvisioningKey(subId, tech);
3350 // Default is no capabilities are provisioned.
3351 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3352 }
3353
3354 /**
3355 * Sets the MmTel capability provisioning bitfield (defined by
3356 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3357 * technology specified.
3358 *
3359 * Note: This is a synchronous command and should not be called on UI thread.
3360 */
3361 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3362 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3363 String key = getMmTelProvisioningKey(subId, tech);
3364 editor.putInt(key, newField);
3365 editor.commit();
3366 }
3367
3368 private static String getMmTelProvisioningKey(int subId, int tech) {
3369 // resulting key is provision_ims_mmtel_{subId}_{tech}
3370 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3371 }
3372
3373 /**
3374 * Query CarrierConfig to see if the specified capability requires provisioning for the
3375 * carrier associated with the subscription id.
3376 */
3377 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3378 int capability) {
3379 CarrierConfigManager configManager = new CarrierConfigManager(context);
3380 PersistableBundle c = configManager.getConfigForSubId(subId);
3381 boolean requireUtProvisioning = c.getBoolean(
3382 // By default, this config is true (even if there is no SIM). We also check to make
3383 // sure the subscription needs provisioning here, so we do not need to check for
3384 // the no-SIM case, where we would normally shortcut this to false.
3385 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3386 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3387 false);
3388 boolean requireVoiceVtProvisioning = c.getBoolean(
3389 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3390
3391 // First check to make sure that the capability requires provisioning.
3392 switch (capability) {
3393 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3394 // intentional fallthrough
3395 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3396 if (requireVoiceVtProvisioning) {
3397 // Voice and Video requires provisioning
3398 return true;
3399 }
3400 break;
3401 }
3402 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3403 if (requireUtProvisioning) {
3404 // UT requires provisioning
3405 return true;
3406 }
3407 break;
3408 }
3409 }
3410 return false;
3411 }
3412
3413 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003414 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003415 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3416 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3417 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003418 enforceReadPrivilegedPermission("getImsProvisioningInt");
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003422 int slotId = getSlotIndex(subId);
3423 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3424 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3425 + subId + "' for key:" + key);
3426 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3427 }
3428 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003429 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003430 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3431 + subId + "' for key:" + key);
3432 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003433 } finally {
3434 Binder.restoreCallingIdentity(identity);
3435 }
3436 }
3437
3438 @Override
3439 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003440 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3441 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3442 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003443 enforceReadPrivilegedPermission("getImsProvisioningString");
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003447 int slotId = getSlotIndex(subId);
3448 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3449 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3450 + subId + "' for key:" + key);
3451 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3452 }
3453 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003454 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003455 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3456 + subId + "' for key:" + key);
3457 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003458 } finally {
3459 Binder.restoreCallingIdentity(identity);
3460 }
3461 }
3462
3463 @Override
3464 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003465 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3466 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3467 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3469 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003473 int slotId = getSlotIndex(subId);
3474 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3475 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3476 + subId + "' for key:" + key);
3477 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3478 }
3479 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003480 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003481 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3482 + "' for key:" + key);
3483 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003484 } finally {
3485 Binder.restoreCallingIdentity(identity);
3486 }
3487 }
3488
3489 @Override
3490 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003491 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3492 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3493 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3495 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003499 int slotId = getSlotIndex(subId);
3500 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3501 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3502 + subId + "' for key:" + key);
3503 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3504 }
3505 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003506 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003507 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3508 + "' for key:" + key);
3509 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003510 } finally {
3511 Binder.restoreCallingIdentity(identity);
3512 }
3513 }
3514
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3516 int slotId = SubscriptionManager.getSlotIndex(subId);
3517 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003518 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 }
3520 return slotId;
3521 }
3522
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003523 private int getSlotIndex(int subId) {
3524 int slotId = SubscriptionManager.getSlotIndex(subId);
3525 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3526 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3527 }
3528 return slotId;
3529 }
3530
Wink Saville36469e72014-06-11 15:17:00 -07003531 /**
3532 * Returns the network type for a subId
3533 */
3534 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003536 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003537 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003538 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3539 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 final Phone phone = getPhone(subId);
3544 if (phone != null) {
3545 return phone.getServiceState().getDataNetworkType();
3546 } else {
3547 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3548 }
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003552 }
3553
3554 /**
3555 * Returns the data network type
3556 */
3557 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003558 public int getDataNetworkType(String callingPackage) {
3559 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003560 }
3561
3562 /**
3563 * Returns the data network type for a subId
3564 */
3565 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003566 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003568 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003569 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3570 }
3571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 final Phone phone = getPhone(subId);
3575 if (phone != null) {
3576 return phone.getServiceState().getDataNetworkType();
3577 } else {
3578 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3579 }
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003583 }
3584
3585 /**
Wink Saville36469e72014-06-11 15:17:00 -07003586 * Returns the Voice network type for a subId
3587 */
3588 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003589 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003591 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003592 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3593 }
3594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 final Phone phone = getPhone(subId);
3598 if (phone != null) {
3599 return phone.getServiceState().getVoiceNetworkType();
3600 } else {
3601 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3602 }
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003606 }
3607
3608 /**
3609 * @return true if a ICC card is present
3610 */
3611 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003612 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003613 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3614 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003615 }
3616
3617 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003618 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003619 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003620 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003621 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = PhoneFactory.getPhone(slotIndex);
3625 if (phone != null) {
3626 return phone.getIccCard().hasIccCard();
3627 } else {
3628 return false;
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003633 }
3634
3635 /**
3636 * Return if the current radio is LTE on CDMA. This
3637 * is a tri-state return value as for a period of time
3638 * the mode may be unknown.
3639 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003640 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003641 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003642 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003643 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003644 @Override
3645 public int getLteOnCdmaMode(String callingPackage) {
3646 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003647 }
3648
Sanket Padawe356d7632015-06-22 14:03:32 -07003649 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003650 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003652 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003653 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3654 }
3655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656 final long identity = Binder.clearCallingIdentity();
3657 try {
3658 final Phone phone = getPhone(subId);
3659 if (phone == null) {
3660 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3661 } else {
3662 return phone.getLteOnCdmaMode();
3663 }
3664 } finally {
3665 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003666 }
Wink Saville36469e72014-06-11 15:17:00 -07003667 }
3668
Wink Saville36469e72014-06-11 15:17:00 -07003669 /**
3670 * {@hide}
3671 * Returns Default subId, 0 in the case of single standby.
3672 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003673 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003674 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003675 }
3676
Shishir Agrawala9f32182016-04-12 12:00:16 -07003677 private int getSlotForDefaultSubscription() {
3678 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3679 }
3680
Wink Savilleb564aae2014-10-23 10:18:09 -07003681 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003682 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003683 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003684
Pengquan Menge92a50d2018-09-21 15:54:48 -07003685 private boolean isActiveSubscription(int subId) {
3686 return mSubscriptionController.isActiveSubId(subId);
3687 }
3688
Ihab Awadf2177b72013-11-25 13:33:23 -08003689 /**
3690 * @see android.telephony.TelephonyManager.WifiCallingChoices
3691 */
3692 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003693 final long identity = Binder.clearCallingIdentity();
3694 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003695 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3697 getWhenToMakeWifiCallsDefaultPreference());
3698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003701 }
3702
3703 /**
3704 * @see android.telephony.TelephonyManager.WifiCallingChoices
3705 */
3706 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003710 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003715 }
3716
Sailesh Nepald1e68152013-12-12 19:08:02 -08003717 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003718 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003719 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003720 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003721
Jordan Liu4c733742019-02-28 12:03:40 -08003722 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3723 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3724 if (phoneId == -1) {
3725 throw new IllegalArgumentException("Given slot index: " + slotIndex
3726 + " does not correspond to an active phone");
3727 }
3728 return PhoneFactory.getPhone(phoneId);
3729 }
3730
Shishir Agrawal566b7612013-10-28 14:41:00 -07003731 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003732 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3733 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3735 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003737 if (DBG) {
3738 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3739 }
3740 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3741 p2);
3742 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003743
Jordan Liu4c733742019-02-28 12:03:40 -08003744
3745 @Override
3746 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3747 int slotIndex, String callingPackage, String aid, int p2) {
3748 enforceModifyPermission();
3749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3750 if (DBG) {
3751 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3752 }
3753 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3754 callingPackage, aid, p2);
3755 }
3756
3757 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3758 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 if (TextUtils.equals(ISDR_AID, aid)) {
3762 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003763 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3764 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765 if (bestComponent == null
3766 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3767 loge("The calling package is not allowed to access ISD-R.");
3768 throw new SecurityException(
3769 "The calling package is not allowed to access ISD-R.");
3770 }
Derek Tan740e1672017-06-27 14:56:27 -07003771 }
Derek Tan740e1672017-06-27 14:56:27 -07003772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003773 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003774 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3775 null /* workSource */);
3776 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777 return response;
3778 } finally {
3779 Binder.restoreCallingIdentity(identity);
3780 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003781 }
3782
3783 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003784 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3786 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003787 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3788 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3789 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003790
Jordan Liu4c733742019-02-28 12:03:40 -08003791 @Override
3792 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3793 enforceModifyPermission();
3794 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3795 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3796 channel);
3797 }
3798
3799 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 final long identity = Binder.clearCallingIdentity();
3801 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802 if (channel < 0) {
3803 return false;
3804 }
Jordan Liu4c733742019-02-28 12:03:40 -08003805 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3806 null /* workSource */);
3807 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808 return success;
3809 } finally {
3810 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003812 }
3813
3814 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003815 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003816 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3818 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003819 if (DBG) {
3820 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3821 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3822 + p3 + " data=" + data);
3823 }
3824 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3825 command, p1, p2, p3, data);
3826 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003827
Jordan Liu4c733742019-02-28 12:03:40 -08003828 @Override
3829 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3830 int command, int p1, int p2, int p3, String data) {
3831 enforceModifyPermission();
3832 if (DBG) {
3833 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3834 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3835 + p3 + " data=" + data);
3836 }
3837 return iccTransmitApduLogicalChannelWithPermission(
3838 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3839 data);
3840 }
3841
3842 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3843 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846 if (channel < 0) {
3847 return "";
3848 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003851 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3852 null /* workSource */);
3853 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855 // Append the returned status code to the end of the response payload.
3856 String s = Integer.toHexString(
3857 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3858 if (response.payload != null) {
3859 s = IccUtils.bytesToHexString(response.payload) + s;
3860 }
3861 return s;
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003864 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003865 }
Jake Hambye994d462014-02-03 13:10:13 -08003866
Evan Charltonc66da362014-05-16 14:06:40 -07003867 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003868 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3869 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3871 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003873 if (DBG) {
3874 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3875 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3876 }
3877 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3878 cla, command, p1, p2, p3, data);
3879 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003880
Jordan Liu4c733742019-02-28 12:03:40 -08003881 @Override
3882 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3883 int command, int p1, int p2, int p3, String data) {
3884 enforceModifyPermission();
3885 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3886 if (DBG) {
3887 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3888 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3889 + " data=" + data);
3890 }
3891
3892 return iccTransmitApduBasicChannelWithPermission(
3893 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3894 p2, p3, data);
3895 }
3896
3897 // open APDU basic channel assuming the caller has sufficient permissions
3898 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3899 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003900 final long identity = Binder.clearCallingIdentity();
3901 try {
3902 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3903 && TextUtils.equals(ISDR_AID, data)) {
3904 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003905 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3906 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003907 if (bestComponent == null
3908 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3909 loge("The calling package is not allowed to select ISD-R.");
3910 throw new SecurityException(
3911 "The calling package is not allowed to select ISD-R.");
3912 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003913 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003916 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3917 null /* workSource */);
3918 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 // Append the returned status code to the end of the response payload.
3921 String s = Integer.toHexString(
3922 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3923 if (response.payload != null) {
3924 s = IccUtils.bytesToHexString(response.payload) + s;
3925 }
3926 return s;
3927 } finally {
3928 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003929 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003930 }
3931
3932 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003933 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003934 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3936 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 if (DBG) {
3941 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3942 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3943 }
3944
3945 IccIoResult response =
3946 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3947 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3948 subId);
3949
3950 if (DBG) {
3951 log("Exchange SIM_IO [R]" + response);
3952 }
3953
3954 byte[] result = null;
3955 int length = 2;
3956 if (response.payload != null) {
3957 length = 2 + response.payload.length;
3958 result = new byte[length];
3959 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3960 } else {
3961 result = new byte[length];
3962 }
3963
3964 result[length - 1] = (byte) response.sw2;
3965 result[length - 2] = (byte) response.sw1;
3966 return result;
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003969 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003970 }
3971
Nathan Haroldb3014052017-01-25 15:57:32 -08003972 /**
3973 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3974 * on a particular subscription
3975 */
sqianb6e41952018-03-12 14:54:01 -07003976 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3978 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3979 return null;
3980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 if (appType != TelephonyManager.APPTYPE_USIM
3985 && appType != TelephonyManager.APPTYPE_SIM) {
3986 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3987 return null;
3988 }
3989 Object response = sendRequest(
3990 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3991 if (response instanceof String[]) {
3992 return (String[]) response;
3993 }
3994 // Response is an Exception of some kind,
3995 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003996 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003997 } finally {
3998 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003999 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004000 }
4001
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004002 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004003 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4005 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4010 if (response.payload == null) {
4011 return "";
4012 }
Evan Charltonc66da362014-05-16 14:06:40 -07004013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 // Append the returned status code to the end of the response payload.
4015 String s = Integer.toHexString(
4016 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4017 s = IccUtils.bytesToHexString(response.payload) + s;
4018 return s;
4019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
Evan Charltonc66da362014-05-16 14:06:40 -07004022 }
4023
Jake Hambye994d462014-02-03 13:10:13 -08004024 /**
4025 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4026 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4027 *
4028 * @param itemID the ID of the item to read
4029 * @return the NV item as a String, or null on error.
4030 */
4031 @Override
4032 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4035 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004036
4037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004040 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4042 return value;
4043 } finally {
4044 Binder.restoreCallingIdentity(identity);
4045 }
Jake Hambye994d462014-02-03 13:10:13 -08004046 }
4047
4048 /**
4049 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4050 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4051 *
4052 * @param itemID the ID of the item to read
4053 * @param itemValue the value to write, as a String
4054 * @return true on success; false on any failure
4055 */
4056 @Override
4057 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004058 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4060 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004061
4062 final long identity = Binder.clearCallingIdentity();
4063 try {
4064 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4065 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004066 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4068 return success;
4069 } finally {
4070 Binder.restoreCallingIdentity(identity);
4071 }
Jake Hambye994d462014-02-03 13:10:13 -08004072 }
4073
4074 /**
4075 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4076 * Used for device configuration by some CDMA operators.
4077 *
4078 * @param preferredRoamingList byte array containing the new PRL
4079 * @return true on success; false on any failure
4080 */
4081 @Override
4082 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4084 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4089 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4090 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4091 return success;
4092 } finally {
4093 Binder.restoreCallingIdentity(identity);
4094 }
Jake Hambye994d462014-02-03 13:10:13 -08004095 }
4096
4097 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004098 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004099 * Used for device configuration by some CDMA operators.
4100 *
chen xu6dac5ab2018-10-26 17:39:23 -07004101 * @param slotIndex - device slot.
4102 *
Jake Hambye994d462014-02-03 13:10:13 -08004103 * @return true on success; false on any failure
4104 */
4105 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004106 public boolean resetModemConfig(int slotIndex) {
4107 Phone phone = PhoneFactory.getPhone(slotIndex);
4108 if (phone != null) {
4109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4110 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111
chen xu6dac5ab2018-10-26 17:39:23 -07004112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4115 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4116 return success;
4117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120 }
chen xu6dac5ab2018-10-26 17:39:23 -07004121 return false;
4122 }
4123
4124 /**
4125 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4126 *
4127 * @param slotIndex - device slot.
4128 *
4129 * @return true on success; false on any failure
4130 */
4131 @Override
4132 public boolean rebootModem(int slotIndex) {
4133 Phone phone = PhoneFactory.getPhone(slotIndex);
4134 if (phone != null) {
4135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4136 mApp, phone.getSubId(), "rebootModem");
4137
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4141 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4142 return success;
4143 } finally {
4144 Binder.restoreCallingIdentity(identity);
4145 }
4146 }
4147 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004148 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004149
Svet Ganovb320e182015-04-16 12:30:10 -07004150 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004151 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004153 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004154 return new String[0];
4155 }
4156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157 final long identity = Binder.clearCallingIdentity();
4158 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004159 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
Wink Saville36469e72014-06-11 15:17:00 -07004163 }
4164
Brad Ebinger51f743a2017-01-23 13:50:20 -08004165 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004166 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4167 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004168 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004169 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004171
4172 final long identity = Binder.clearCallingIdentity();
4173 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004174 ImsResolver resolver = PhoneFactory.getImsResolver();
4175 if (resolver == null) {
4176 // may happen if the device does not support IMS.
4177 return;
4178 }
4179 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 } finally {
4181 Binder.restoreCallingIdentity(identity);
4182 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004183 }
4184
4185 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004186 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4187 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004188 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004189 public void disableIms(int slotId) {
4190 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004191
4192 final long identity = Binder.clearCallingIdentity();
4193 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004194 ImsResolver resolver = PhoneFactory.getImsResolver();
4195 if (resolver == null) {
4196 // may happen if the device does not support IMS.
4197 return;
4198 }
4199 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004203 }
4204
4205 /**
4206 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4207 * feature or {@link null} if the service is not available. If the feature is available, the
4208 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4209 */
4210 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004211 IImsServiceFeatureCallback callback) {
4212 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213
4214 final long identity = Binder.clearCallingIdentity();
4215 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004216 ImsResolver resolver = PhoneFactory.getImsResolver();
4217 if (resolver == null) {
4218 // may happen if the device does not support IMS.
4219 return null;
4220 }
4221 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004222 } finally {
4223 Binder.restoreCallingIdentity(identity);
4224 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004225 }
4226
4227 /**
4228 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4229 * feature during emergency calling or {@link null} if the service is not available. If the
4230 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4231 * listener for feature updates.
4232 */
4233 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4234 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235
4236 final long identity = Binder.clearCallingIdentity();
4237 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004238 ImsResolver resolver = PhoneFactory.getImsResolver();
4239 if (resolver == null) {
4240 // may happen if the device does not support IMS.
4241 return null;
4242 }
4243 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004247 }
4248
Brad Ebinger5f64b052017-12-14 14:26:15 -08004249 /**
4250 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004251 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004252 */
4253 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4254 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255
4256 final long identity = Binder.clearCallingIdentity();
4257 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004258 ImsResolver resolver = PhoneFactory.getImsResolver();
4259 if (resolver == null) {
4260 // may happen if the device does not support IMS.
4261 return null;
4262 }
4263 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004267 }
4268
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004269 /**
4270 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004271 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004272 */
4273 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4274 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004278 ImsResolver resolver = PhoneFactory.getImsResolver();
4279 if (resolver == null) {
4280 // may happen if the device does not support IMS.
4281 return null;
4282 }
4283 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004287 }
4288
Brad Ebinger884c07b2018-02-15 16:17:40 -08004289 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004290 * Sets the ImsService Package Name that Telephony will bind to.
4291 *
4292 * @param slotId the slot ID that the ImsService should bind for.
4293 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4294 * ImsService is the device default ImsService.
4295 * @param packageName The package name of the application that contains the ImsService to bind
4296 * to.
4297 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4298 * @hide
4299 */
4300 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004301 int[] subIds = SubscriptionManager.getSubId(slotId);
4302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4303 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4304 "setImsService");
4305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004306 final long identity = Binder.clearCallingIdentity();
4307 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004308 ImsResolver resolver = PhoneFactory.getImsResolver();
4309 if (resolver == null) {
4310 // may happen if the device does not support IMS.
4311 return false;
4312 }
4313 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4314 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004318 }
4319
4320 /**
4321 * Return the ImsService configuration.
4322 *
4323 * @param slotId The slot that the ImsService is associated with.
4324 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4325 * the device default.
4326 * @return the package name of the ImsService configuration.
4327 */
4328 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004329 int[] subIds = SubscriptionManager.getSubId(slotId);
4330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4331 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4332 "getImsService");
4333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 final long identity = Binder.clearCallingIdentity();
4335 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004336 ImsResolver resolver = PhoneFactory.getImsResolver();
4337 if (resolver == null) {
4338 // may happen if the device does not support IMS.
4339 return "";
4340 }
4341 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004345 }
4346
Wink Saville36469e72014-06-11 15:17:00 -07004347 public void setImsRegistrationState(boolean registered) {
4348 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349
4350 final long identity = Binder.clearCallingIdentity();
4351 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004352 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 } finally {
4354 Binder.restoreCallingIdentity(identity);
4355 }
Wink Saville36469e72014-06-11 15:17:00 -07004356 }
4357
4358 /**
Stuart Scott54788802015-03-30 13:18:01 -07004359 * Set the network selection mode to automatic.
4360 *
4361 */
4362 @Override
4363 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4365 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366
Pengquan Menge92a50d2018-09-21 15:54:48 -07004367 if (!isActiveSubscription(subId)) {
4368 return;
4369 }
4370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371 final long identity = Binder.clearCallingIdentity();
4372 try {
4373 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4374 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4375 } finally {
4376 Binder.restoreCallingIdentity(identity);
4377 }
Stuart Scott54788802015-03-30 13:18:01 -07004378 }
4379
Pengquan Mengea84e042018-09-20 14:57:26 -07004380 /**
4381 * Ask the radio to connect to the input network and change selection mode to manual.
4382 *
4383 * @param subId the id of the subscription.
4384 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4385 * the operator to attach to.
4386 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4387 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4388 * normal network selection next time.
4389 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004390 */
4391 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004392 public boolean setNetworkSelectionModeManual(
4393 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4395 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004396
4397 if (!isActiveSubscription(subId)) {
4398 return false;
4399 }
4400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004403 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004405 if (DBG) {
4406 log("setNetworkSelectionModeManual: subId: " + subId
4407 + " operator: " + operatorInfo);
4408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004413 }
4414
4415 /**
4416 * Scans for available networks.
4417 */
4418 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004419 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4421 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004422 LocationAccessPolicy.LocationPermissionResult locationResult =
4423 LocationAccessPolicy.checkLocationPermission(mApp,
4424 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4425 .setCallingPackage(callingPackage)
4426 .setCallingPid(Binder.getCallingPid())
4427 .setCallingUid(Binder.getCallingUid())
4428 .setMethod("getCellNetworkScanResults")
4429 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4430 .build());
4431 switch (locationResult) {
4432 case DENIED_HARD:
4433 throw new SecurityException("Not allowed to access scan results -- location");
4434 case DENIED_SOFT:
4435 return null;
4436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437
Pengquan Menga1bb6272018-09-06 09:59:22 -07004438 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004439 try {
4440 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004441 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004446 }
4447
4448 /**
yinxub1bed742017-04-17 11:45:04 -07004449 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004450 *
yinxub1bed742017-04-17 11:45:04 -07004451 * @param subId id of the subscription
4452 * @param request contains the radio access networks with bands/channels to scan
4453 * @param messenger callback messenger for scan results or errors
4454 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004455 * @return the id of the requested scan which can be used to stop the scan.
4456 */
4457 @Override
4458 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004459 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4461 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004462 LocationAccessPolicy.LocationPermissionResult locationResult =
4463 LocationAccessPolicy.checkLocationPermission(mApp,
4464 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4465 .setCallingPackage(callingPackage)
4466 .setCallingPid(Binder.getCallingPid())
4467 .setCallingUid(Binder.getCallingUid())
4468 .setMethod("requestNetworkScan")
4469 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4470 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004471 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4472 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4473 if (e != null) {
4474 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4475 throw e;
4476 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004477 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004478 return TelephonyScanManager.INVALID_SCAN_ID;
4479 }
4480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 }
Hall Liu912dfd32019-04-25 14:02:26 -07004482 int callingUid = Binder.getCallingUid();
4483 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004484 final long identity = Binder.clearCallingIdentity();
4485 try {
4486 return mNetworkScanRequestTracker.startNetworkScan(
4487 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004488 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004489 } finally {
4490 Binder.restoreCallingIdentity(identity);
4491 }
yinxu504e1392017-04-12 16:03:22 -07004492 }
4493
Hall Liub2ac8ef2019-02-28 15:56:23 -08004494 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4495 NetworkScanRequest request) {
4496 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4497 != PERMISSION_GRANTED) {
4498 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4499 + " without location access.");
4500 }
4501
4502 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4503 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004504 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4505 return new SecurityException("Specific channels must not be"
4506 + " scanned without location access.");
4507 }
4508 }
4509 }
4510
Hall Liub2ac8ef2019-02-28 15:56:23 -08004511 return null;
4512 }
4513
yinxu504e1392017-04-12 16:03:22 -07004514 /**
4515 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004516 *
4517 * @param subId id of the subscription
4518 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004519 */
4520 @Override
4521 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4523 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004524
Hall Liu912dfd32019-04-25 14:02:26 -07004525 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 final long identity = Binder.clearCallingIdentity();
4527 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004528 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
yinxu504e1392017-04-12 16:03:22 -07004532 }
4533
4534 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004535 * Get the calculated preferred network type.
4536 * Used for debugging incorrect network type.
4537 *
4538 * @return the preferred network type, defined in RILConstants.java.
4539 */
4540 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004541 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004542 final Phone defaultPhone = getDefaultPhone();
4543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4544 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004545 return RILConstants.PREFERRED_NETWORK_MODE;
4546 }
4547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004548 final long identity = Binder.clearCallingIdentity();
4549 try {
4550 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004551 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004552 } finally {
4553 Binder.restoreCallingIdentity(identity);
4554 }
Junda Liu84d15a22014-07-02 11:21:04 -07004555 }
4556
4557 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004558 * Get the preferred network type.
4559 * Used for device configuration by some CDMA operators.
4560 *
4561 * @return the preferred network type, defined in RILConstants.java.
4562 */
4563 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004564 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004565 TelephonyPermissions
4566 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4567 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 if (DBG) log("getPreferredNetworkType");
4572 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4573 int networkType = (result != null ? result[0] : -1);
4574 if (DBG) log("getPreferredNetworkType: " + networkType);
4575 return networkType;
4576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004579 }
4580
4581 /**
4582 * Set the preferred network type.
4583 * Used for device configuration by some CDMA operators.
4584 *
4585 * @param networkType the preferred network type, defined in RILConstants.java.
4586 * @return true on success; false on any failure.
4587 */
4588 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004589 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4591 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592
4593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4596 Boolean success = (Boolean) sendRequest(
4597 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4598 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4599 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004600 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4602 }
4603 return success;
4604 } finally {
4605 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004606 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004607 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004608
4609 /**
Miaoa84611c2019-03-15 09:21:10 +08004610 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004611 *
Miaoa84611c2019-03-15 09:21:10 +08004612 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004613 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004614 * @hide
4615 */
4616 @Override
Miaoa84611c2019-03-15 09:21:10 +08004617 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004618 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004619 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004620 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 try {
Miaoa84611c2019-03-15 09:21:10 +08004622 if (phone != null) {
4623 return phone.hasMatchedTetherApnSetting();
4624 } else {
4625 return false;
4626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 } finally {
4628 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004629 }
Junda Liu475951f2014-11-07 16:45:03 -08004630 }
4631
4632 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004633 * Set mobile data enabled
4634 * Used by the user through settings etc to turn on/off mobile data
4635 *
4636 * @param enable {@code true} turn turn data on, else {@code false}
4637 */
4638 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004639 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4641 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642
4643 final long identity = Binder.clearCallingIdentity();
4644 try {
4645 int phoneId = mSubscriptionController.getPhoneId(subId);
4646 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4647 Phone phone = PhoneFactory.getPhone(phoneId);
4648 if (phone != null) {
4649 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004650 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004652 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 }
4654 } finally {
4655 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004656 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004657 }
4658
4659 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004660 * Get the user enabled state of Mobile Data.
4661 *
4662 * TODO: remove and use isUserDataEnabled.
4663 * This can't be removed now because some vendor codes
4664 * calls through ITelephony directly while they should
4665 * use TelephonyManager.
4666 *
4667 * @return true on enabled
4668 */
4669 @Override
4670 public boolean getDataEnabled(int subId) {
4671 return isUserDataEnabled(subId);
4672 }
4673
4674 /**
4675 * Get whether mobile data is enabled per user setting.
4676 *
4677 * There are other factors deciding whether mobile data is actually enabled, but they are
4678 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004679 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004680 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004681 *
4682 * @return {@code true} if data is enabled else {@code false}
4683 */
4684 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004685 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004686 try {
4687 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4688 null);
4689 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4691 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693
4694 final long identity = Binder.clearCallingIdentity();
4695 try {
4696 int phoneId = mSubscriptionController.getPhoneId(subId);
4697 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4698 Phone phone = PhoneFactory.getPhone(phoneId);
4699 if (phone != null) {
4700 boolean retVal = phone.isUserDataEnabled();
4701 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4702 return retVal;
4703 } else {
4704 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4705 return false;
4706 }
4707 } finally {
4708 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004709 }
4710 }
4711
4712 /**
4713 * Get whether mobile data is enabled.
4714 *
4715 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4716 * whether mobile data is actually enabled.
4717 *
4718 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4719 *
4720 * @return {@code true} if data is enabled else {@code false}
4721 */
4722 @Override
4723 public boolean isDataEnabled(int subId) {
4724 try {
4725 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4726 null);
4727 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4729 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731
4732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 int phoneId = mSubscriptionController.getPhoneId(subId);
4735 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4736 Phone phone = PhoneFactory.getPhone(phoneId);
4737 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004738 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4740 return retVal;
4741 } else {
4742 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4743 return false;
4744 }
4745 } finally {
4746 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004747 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004748 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004749
4750 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004751 public int getCarrierPrivilegeStatus(int subId) {
4752 final Phone phone = getPhone(subId);
4753 if (phone == null) {
4754 loge("getCarrierPrivilegeStatus: Invalid subId");
4755 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4756 }
4757 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004758 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004759 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004760 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4761 }
4762 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004763 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004764 }
Junda Liu29340342014-07-10 15:23:27 -07004765
4766 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004767 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4768 final Phone phone = getPhone(subId);
4769 if (phone == null) {
4770 loge("getCarrierPrivilegeStatus: Invalid subId");
4771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4772 }
4773 UiccProfile profile =
4774 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4775 if (profile == null) {
4776 loge("getCarrierPrivilegeStatus: No UICC");
4777 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4778 }
4779 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4780 }
4781
4782 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004783 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004784 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004785 if (TextUtils.isEmpty(pkgName))
4786 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004787 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004788 if (card == null) {
4789 loge("checkCarrierPrivilegesForPackage: No UICC");
4790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4791 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004792 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4793 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004794 }
4795
4796 @Override
4797 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004798 if (TextUtils.isEmpty(pkgName))
4799 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004800 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4802 UiccCard card = UiccController.getInstance().getUiccCard(i);
4803 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004804 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004805 continue;
4806 }
4807
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004808 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004809 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4810 break;
4811 }
4812 }
4813
4814 return result;
Junda Liu29340342014-07-10 15:23:27 -07004815 }
Derek Tan89e89d42014-07-08 17:00:10 -07004816
4817 @Override
Junda Liue64de782015-04-16 17:19:16 -07004818 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4819 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4820 loge("phoneId " + phoneId + " is not valid.");
4821 return null;
4822 }
4823 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004824 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004825 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004826 return null ;
4827 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004828 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004829 }
4830
Amith Yamasani6e118872016-02-19 12:53:51 -08004831 @Override
4832 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004833 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004834 List<String> privilegedPackages = new ArrayList<>();
4835 List<PackageInfo> packages = null;
4836 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4837 UiccCard card = UiccController.getInstance().getUiccCard(i);
4838 if (card == null) {
4839 // No UICC in that slot.
4840 continue;
4841 }
4842 if (card.hasCarrierPrivilegeRules()) {
4843 if (packages == null) {
4844 // Only check packages in user 0 for now
4845 packages = pm.getInstalledPackagesAsUser(
4846 PackageManager.MATCH_DISABLED_COMPONENTS
4847 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4848 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4849 }
4850 for (int p = packages.size() - 1; p >= 0; p--) {
4851 PackageInfo pkgInfo = packages.get(p);
4852 if (pkgInfo != null && pkgInfo.packageName != null
4853 && card.getCarrierPrivilegeStatus(pkgInfo)
4854 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4855 privilegedPackages.add(pkgInfo.packageName);
4856 }
4857 }
4858 }
4859 }
4860 return privilegedPackages;
4861 }
4862
Wink Savilleb564aae2014-10-23 10:18:09 -07004863 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004864 final Phone phone = getPhone(subId);
4865 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004866 if (card == null) {
4867 loge("getIccId: No UICC");
4868 return null;
4869 }
4870 String iccId = card.getIccId();
4871 if (TextUtils.isEmpty(iccId)) {
4872 loge("getIccId: ICC ID is null or empty.");
4873 return null;
4874 }
4875 return iccId;
4876 }
4877
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004878 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004879 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4880 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004881 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4882 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 final long identity = Binder.clearCallingIdentity();
4885 try {
4886 final String iccId = getIccId(subId);
4887 final Phone phone = getPhone(subId);
4888 if (phone == null) {
4889 return false;
4890 }
4891 final String subscriberId = phone.getSubscriberId();
4892
4893 if (DBG_MERGE) {
4894 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4895 + subscriberId + " to " + number);
4896 }
4897
4898 if (TextUtils.isEmpty(iccId)) {
4899 return false;
4900 }
4901
4902 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4903
4904 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4905 if (alphaTag == null) {
4906 editor.remove(alphaTagPrefKey);
4907 } else {
4908 editor.putString(alphaTagPrefKey, alphaTag);
4909 }
4910
4911 // Record both the line number and IMSI for this ICCID, since we need to
4912 // track all merged IMSIs based on line number
4913 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4914 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4915 if (number == null) {
4916 editor.remove(numberPrefKey);
4917 editor.remove(subscriberPrefKey);
4918 } else {
4919 editor.putString(numberPrefKey, number);
4920 editor.putString(subscriberPrefKey, subscriberId);
4921 }
4922
4923 editor.commit();
4924 return true;
4925 } finally {
4926 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004927 }
Derek Tan7226c842014-07-02 17:42:23 -07004928 }
4929
4930 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004931 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004932 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004934 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004935 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004936 return null;
4937 }
Derek Tan97ebb422014-09-05 16:55:38 -07004938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 final long identity = Binder.clearCallingIdentity();
4940 try {
4941 String iccId = getIccId(subId);
4942 if (iccId != null) {
4943 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4944 if (DBG_MERGE) {
4945 log("getLine1NumberForDisplay returning "
4946 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4947 }
4948 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4951 return null;
4952 } finally {
4953 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004954 }
Derek Tan7226c842014-07-02 17:42:23 -07004955 }
4956
4957 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004958 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004960 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004961 return null;
4962 }
Derek Tan97ebb422014-09-05 16:55:38 -07004963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 final long identity = Binder.clearCallingIdentity();
4965 try {
4966 String iccId = getIccId(subId);
4967 if (iccId != null) {
4968 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4969 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4970 }
4971 return null;
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004974 }
Derek Tan7226c842014-07-02 17:42:23 -07004975 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004976
4977 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07004978 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004979 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4980 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004982 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4983 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004984 return null;
4985 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004986
Jordan Liub49b04b2019-05-06 14:45:15 -07004987 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4988 // the process, where TelephonyManager was instantiated.
4989 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004990 final long identity = Binder.clearCallingIdentity();
4991 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004992 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 final TelephonyManager tele = TelephonyManager.from(context);
4994 final SubscriptionManager sub = SubscriptionManager.from(context);
4995
4996 // Figure out what subscribers are currently active
4997 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998
Jordan Liub49b04b2019-05-06 14:45:15 -07004999 // Only consider subs which match the current subId
5000 // This logic can be simplified. See b/131189269 for progress.
5001 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005002 activeSubscriberIds.add(tele.getSubscriberId(subId));
5003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004
5005 // First pass, find a number override for an active subscriber
5006 String mergeNumber = null;
5007 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5008 for (String key : prefs.keySet()) {
5009 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5010 final String subscriberId = (String) prefs.get(key);
5011 if (activeSubscriberIds.contains(subscriberId)) {
5012 final String iccId = key.substring(
5013 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5014 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5015 mergeNumber = (String) prefs.get(numberKey);
5016 if (DBG_MERGE) {
5017 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5018 + " for active subscriber " + subscriberId);
5019 }
5020 if (!TextUtils.isEmpty(mergeNumber)) {
5021 break;
5022 }
5023 }
5024 }
5025 }
5026
5027 // Shortcut when no active merged subscribers
5028 if (TextUtils.isEmpty(mergeNumber)) {
5029 return null;
5030 }
5031
5032 // Second pass, find all subscribers under that line override
5033 final ArraySet<String> result = new ArraySet<>();
5034 for (String key : prefs.keySet()) {
5035 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5036 final String number = (String) prefs.get(key);
5037 if (mergeNumber.equals(number)) {
5038 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5039 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5040 final String subscriberId = (String) prefs.get(subscriberKey);
5041 if (!TextUtils.isEmpty(subscriberId)) {
5042 result.add(subscriberId);
5043 }
5044 }
5045 }
5046 }
5047
5048 final String[] resultArray = result.toArray(new String[result.size()]);
5049 Arrays.sort(resultArray);
5050 if (DBG_MERGE) {
5051 Slog.d(LOG_TAG,
5052 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5053 }
5054 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005055 } finally {
5056 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005057 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005058 }
5059
5060 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005061 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005062 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5063 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064
5065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 final Phone phone = getPhone(subId);
5068 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005072 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005073
5074 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005075 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005076 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5077 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005078 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079
5080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 final Phone phone = getPhone(subId);
5083 if (phone == null) {
5084 return false;
5085 }
5086 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5087 cdmaNonRoamingList);
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005090 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005091 }
5092
5093 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005094 @Deprecated
5095 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5096 enforceModifyPermission();
5097
5098 int returnValue = 0;
5099 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005100 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005101 if(result.exception == null) {
5102 if (result.result != null) {
5103 byte[] responseData = (byte[])(result.result);
5104 if(responseData.length > oemResp.length) {
5105 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5106 responseData.length + "bytes. Buffer Size is " +
5107 oemResp.length + "bytes.");
5108 }
5109 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5110 returnValue = responseData.length;
5111 }
5112 } else {
5113 CommandException ex = (CommandException) result.exception;
5114 returnValue = ex.getCommandError().ordinal();
5115 if(returnValue > 0) returnValue *= -1;
5116 }
5117 } catch (RuntimeException e) {
5118 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5119 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5120 if(returnValue > 0) returnValue *= -1;
5121 }
5122
5123 return returnValue;
5124 }
5125
5126 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005127 public void setRadioCapability(RadioAccessFamily[] rafs) {
5128 try {
5129 ProxyController.getInstance().setRadioCapability(rafs);
5130 } catch (RuntimeException e) {
5131 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5132 }
5133 }
5134
5135 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005136 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005137 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005138 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005139 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005140 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 final long identity = Binder.clearCallingIdentity();
5143 try {
chen xub97461a2018-10-26 14:17:57 -07005144 TelephonyPermissions
5145 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5146 mApp, phone.getSubId(), "getRadioAccessFamily");
5147 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 } finally {
5149 Binder.restoreCallingIdentity(identity);
5150 }
chen xub97461a2018-10-26 14:17:57 -07005151 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005152 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005153
5154 @Override
5155 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005156 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005157 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158
5159 final long identity = Binder.clearCallingIdentity();
5160 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005161 ImsManager.getInstance(defaultPhone.getContext(),
5162 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 } finally {
5164 Binder.restoreCallingIdentity(identity);
5165 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005166 }
5167
5168 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005169 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005170 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005172 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005173 return false;
5174 }
Svet Ganovb320e182015-04-16 12:30:10 -07005175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 final long identity = Binder.clearCallingIdentity();
5177 try {
5178 // Check the user preference and the system-level IMS setting. Even if the user has
5179 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5180 // In the long run, we may instead need to check if there exists a connection service
5181 // which can support video calling.
5182 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005183 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 return imsManager.isVtEnabledByPlatform()
5185 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5186 && imsManager.isVtEnabledByUser();
5187 } finally {
5188 Binder.restoreCallingIdentity(identity);
5189 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005190 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005191
Andrew Leea1239f22015-03-02 17:44:07 -08005192 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5195 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5196 return false;
5197 }
5198
5199 final long identity = Binder.clearCallingIdentity();
5200 try {
5201 CarrierConfigManager configManager =
5202 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005203 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
Andrew Leea1239f22015-03-02 17:44:07 -08005208 }
5209
5210 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 public boolean isWorldPhone(int subId, String callingPackage) {
5212 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5213 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5214 return false;
5215 }
5216
5217 final long identity = Binder.clearCallingIdentity();
5218 try {
5219 CarrierConfigManager configManager =
5220 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005221 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
Andrew Leea1239f22015-03-02 17:44:07 -08005226 }
5227
Andrew Lee9431b832015-03-09 18:46:45 -07005228 @Override
5229 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005230 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005231 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005232 }
5233
5234 @Override
5235 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 final long identity = Binder.clearCallingIdentity();
5237 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005238 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241 }
Andrew Lee9431b832015-03-09 18:46:45 -07005242 }
5243
Hall Liuf6668912018-10-31 17:05:23 -07005244 /**
5245 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5246 * support for the feature and device firmware support.
5247 *
5248 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5249 */
5250 @Override
5251 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005253 final Phone phone = getPhone(subscriptionId);
5254 if (phone == null) {
5255 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5256 return false;
5257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005259 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5261 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005262 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 return isCarrierSupported && isDeviceSupported;
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
5266 }
Hall Liu98187582018-01-22 19:15:32 -08005267 }
5268
Hall Liuf6668912018-10-31 17:05:23 -07005269 /**
5270 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5271 * both also support RTT.
5272 */
5273 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 final long identity = Binder.clearCallingIdentity();
5275 try {
Hall Liuf6668912018-10-31 17:05:23 -07005276 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005277 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 } finally {
5279 Binder.restoreCallingIdentity(identity);
5280 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005281 }
5282
Sanket Padawe7310cc72015-01-14 09:53:20 -08005283 /**
5284 * Returns the unique device ID of phone, for example, the IMEI for
5285 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5286 *
5287 * <p>Requires Permission:
5288 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5289 */
5290 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005291 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005292 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005293 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005294 return null;
5295 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005296 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005297 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5298 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005299 return null;
5300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301
5302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 return phone.getDeviceId();
5305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005308 }
5309
Ping Sunc67b7c22016-03-02 19:16:45 +08005310 /**
5311 * {@hide}
5312 * Returns the IMS Registration Status on a particular subid
5313 *
5314 * @param subId
5315 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005316 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005317 Phone phone = getPhone(subId);
5318 if (phone != null) {
5319 return phone.isImsRegistered();
5320 } else {
5321 return false;
5322 }
5323 }
5324
Santos Cordon7a1885b2015-02-03 11:15:19 -08005325 @Override
5326 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 final long identity = Binder.clearCallingIdentity();
5328 try {
5329 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
5332 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005333 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005334
Tyler Gunnf70ed162019-04-03 15:28:53 -07005335 @Override
5336 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 Phone phone = getPhone(subscriptionId);
5340 if (phone == null) {
5341 return null;
5342 }
5343 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
5346 }
5347 }
5348
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005349 /**
5350 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005351 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005352 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 final long identity = Binder.clearCallingIdentity();
5354 try {
5355 Phone phone = getPhone(subId);
5356 if (phone != null) {
5357 return phone.isWifiCallingEnabled();
5358 } else {
5359 return false;
5360 }
5361 } finally {
5362 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005363 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005364 }
5365
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005366 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005367 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005368 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005369 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 final long identity = Binder.clearCallingIdentity();
5371 try {
5372 Phone phone = getPhone(subId);
5373 if (phone != null) {
5374 return phone.isVideoEnabled();
5375 } else {
5376 return false;
5377 }
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005380 }
5381 }
5382
5383 /**
5384 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5385 * defined in {@link ImsRegistrationImplBase}.
5386 */
5387 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 Phone phone = getPhone(subId);
5391 if (phone != null) {
5392 return phone.getImsRegistrationTech();
5393 } else {
5394 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5395 }
5396 } finally {
5397 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005398 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005399 }
5400
Stuart Scott8eef64f2015-04-08 15:13:54 -07005401 @Override
5402 public void factoryReset(int subId) {
5403 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005404 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5405 return;
5406 }
5407
Svet Ganovcc087f82015-05-12 20:35:54 -07005408 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005409
Svet Ganovcc087f82015-05-12 20:35:54 -07005410 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005411 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5412 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005413 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005414 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005415 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005416 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5417 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005418 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005419 // There has been issues when Sms raw table somehow stores orphan
5420 // fragments. They lead to garbled message when new fragments come
5421 // in and combined with those stale ones. In case this happens again,
5422 // user can reset all network settings which will clean up this table.
5423 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005424 } finally {
5425 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005426 }
5427 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005428
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005429 private void cleanUpSmsRawTable(Context context) {
5430 ContentResolver resolver = context.getContentResolver();
5431 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5432 resolver.delete(uri, null, null);
5433 }
5434
Narayan Kamath1c496c22015-04-16 14:40:19 +01005435 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005436 public String getSimLocaleForSubscriber(int subId) {
5437 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5438 final Phone phone = getPhone(subId);
5439 if (phone == null) {
5440 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005441 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 final long identity = Binder.clearCallingIdentity();
5444 try {
chen xu5d3637b2019-01-21 23:31:38 -08005445 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5446 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005447 if (info == null) {
5448 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5449 return null;
5450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451 // Try and fetch the locale from the carrier properties or from the SIM language
5452 // preferences (EF-PL and EF-LI)...
5453 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005455 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5456 if (localeFromDefaultSim != null) {
5457 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5458 if (DBG) log("Using locale from subId: " + subId + " locale: "
5459 + localeFromDefaultSim);
5460 return localeFromDefaultSim.toLanguageTag();
5461 } else {
5462 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 }
5464 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 // The SIM language preferences only store a language (e.g. fr = French), not an
5467 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5468 // the SIM and carrier preferences does not include a country we add the country
5469 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005470 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005472 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 return mccLocale.toLanguageTag();
5474 }
5475
5476 if (DBG) log("No locale found - returning null");
5477 return null;
5478 } finally {
5479 Binder.restoreCallingIdentity(identity);
5480 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005481 }
5482
5483 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005484 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005485 }
5486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 /**
5488 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5489 */
5490 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005491 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005492 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005493
Chenjie Yu1ba97252018-01-11 18:16:20 -08005494 private final ModemActivityInfo mLastModemActivityInfo =
5495 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5496
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005497 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005498 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5499 * representing the state of the modem.
5500 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005501 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5502 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005503 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005504 */
5505 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005506 public void requestModemActivityInfo(ResultReceiver result) {
5507 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005508 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509
5510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 ModemActivityInfo ret = null;
5513 synchronized (mLastModemActivityInfo) {
5514 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5515 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005516 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005517 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5519 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005520 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5521 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 }
5523 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005524 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5525 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 mLastModemActivityInfo.setIdleTimeMillis(
5527 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5528 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5529 mLastModemActivityInfo.setRxTimeMillis(
5530 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5531 mLastModemActivityInfo.setEnergyUsed(
5532 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5535 mLastModemActivityInfo.getSleepTimeMillis(),
5536 mLastModemActivityInfo.getIdleTimeMillis(),
5537 mLastModemActivityInfo.getTxTimeMillis(),
5538 mLastModemActivityInfo.getRxTimeMillis(),
5539 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541 Bundle bundle = new Bundle();
5542 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5543 result.send(0, bundle);
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005546 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005547 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005548
Siddharth Rayb8114062018-06-17 15:02:38 -07005549 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5550 // less than total activity duration.
5551 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5552 if (info == null) {
5553 return false;
5554 }
5555 int activityDurationMs =
5556 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5557 int totalTxTimeMs = 0;
5558 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5559 totalTxTimeMs += info.getTxTimeMillis()[i];
5560 }
5561 return (info.isValid()
5562 && (info.getSleepTimeMillis() <= activityDurationMs)
5563 && (info.getIdleTimeMillis() <= activityDurationMs)
5564 && (info.getRxTimeMillis() <= activityDurationMs)
5565 && (totalTxTimeMs <= activityDurationMs));
5566 }
5567
Jack Yu85bd38a2015-11-09 11:34:32 -08005568 /**
5569 * {@hide}
5570 * Returns the service state information on specified subscription.
5571 */
5572 @Override
5573 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005575 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005576 return null;
5577 }
5578
Hall Liuf19c44f2018-11-27 14:38:17 -08005579 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5580 LocationAccessPolicy.checkLocationPermission(mApp,
5581 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5582 .setCallingPackage(callingPackage)
5583 .setCallingPid(Binder.getCallingPid())
5584 .setCallingUid(Binder.getCallingUid())
5585 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005586 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005587 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5588 .build());
5589
5590 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5591 LocationAccessPolicy.checkLocationPermission(mApp,
5592 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5593 .setCallingPackage(callingPackage)
5594 .setCallingPid(Binder.getCallingPid())
5595 .setCallingUid(Binder.getCallingUid())
5596 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005597 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005598 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5599 .build());
5600 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5601 boolean hasFinePermission =
5602 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5603 boolean hasCoarsePermission =
5604 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 final long identity = Binder.clearCallingIdentity();
5607 try {
5608 final Phone phone = getPhone(subId);
5609 if (phone == null) {
5610 return null;
5611 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005612
Hall Liuf19c44f2018-11-27 14:38:17 -08005613 ServiceState ss = phone.getServiceState();
5614
5615 // Scrub out the location info in ServiceState depending on what level of access
5616 // the caller has.
5617 if (hasFinePermission) return ss;
5618 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5619 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005623 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005624
5625 /**
5626 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5627 *
5628 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5629 * voicemail ringtone.
5630 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5631 * PhoneAccount.
5632 */
5633 @Override
5634 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5638 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005639 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005646 }
5647
5648 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005649 * Sets the per-account voicemail ringtone.
5650 *
5651 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5652 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5653 *
5654 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5655 * voicemail ringtone.
5656 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5657 * PhoneAccount.
5658 */
5659 @Override
5660 public void setVoicemailRingtoneUri(String callingPackage,
5661 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005662 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5664 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005665 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5667 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5668 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670
5671 final long identity = Binder.clearCallingIdentity();
5672 try {
5673 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5674 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005675 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 }
5677 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5678 } finally {
5679 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005680 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005681 }
5682
5683 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005684 * Returns whether vibration is set for voicemail notification in Phone settings.
5685 *
5686 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5687 * voicemail vibration setting.
5688 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5689 */
5690 @Override
5691 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5695 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005696 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005703 }
5704
Youhan Wange64578a2016-05-02 15:32:42 -07005705 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005706 * Sets the per-account voicemail vibration.
5707 *
5708 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5709 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5710 *
5711 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5712 * voicemail vibration setting.
5713 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5714 * specific PhoneAccount.
5715 */
5716 @Override
5717 public void setVoicemailVibrationEnabled(String callingPackage,
5718 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005719 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5721 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005722 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5724 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5725 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005726 }
5727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5731 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005732 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 }
5734 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5735 } finally {
5736 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005737 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005738 }
5739
5740 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005741 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5742 *
5743 * @throws SecurityException if the caller does not have the required permission
5744 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005745 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005746 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005747 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005748 }
5749
5750 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005751 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5752 * permission.
5753 *
5754 * @throws SecurityException if the caller does not have the required permission
5755 */
5756 private void enforceSendSmsPermission() {
5757 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5758 }
5759
5760 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005761 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005762 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005763 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005764 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005765 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005769 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 if (componentName == null) {
5771 throw new SecurityException(
5772 "Caller not current active visual voicemail package[null]");
5773 }
5774 String vvmPackage = componentName.getPackageName();
5775 if (!callingPackage.equals(vvmPackage)) {
5776 throw new SecurityException("Caller not current active visual voicemail package["
5777 + vvmPackage + "]");
5778 }
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005781 }
5782 }
5783
5784 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005785 * Return the application ID for the app type.
5786 *
5787 * @param subId the subscription ID that this request applies to.
5788 * @param appType the uicc app type.
5789 * @return Application ID for specificied app type, or null if no uicc.
5790 */
5791 @Override
5792 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005793 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005794 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795
5796 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005797 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 if (phone == null) {
5799 return null;
5800 }
5801 String aid = null;
5802 try {
5803 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5804 .getApplicationByType(appType).getAid();
5805 } catch (Exception e) {
5806 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5807 }
5808 return aid;
5809 } finally {
5810 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005811 }
Youhan Wange64578a2016-05-02 15:32:42 -07005812 }
5813
Youhan Wang4001d252016-05-11 10:29:41 -07005814 /**
5815 * Return the Electronic Serial Number.
5816 *
5817 * @param subId the subscription ID that this request applies to.
5818 * @return ESN or null if error.
5819 */
5820 @Override
5821 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005822 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005823 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824
5825 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005826 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 if (phone == null) {
5828 return null;
5829 }
5830 String esn = null;
5831 try {
5832 esn = phone.getEsn();
5833 } catch (Exception e) {
5834 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5835 }
5836 return esn;
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005839 }
Youhan Wang4001d252016-05-11 10:29:41 -07005840 }
5841
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005842 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005843 * Return the Preferred Roaming List Version.
5844 *
5845 * @param subId the subscription ID that this request applies to.
5846 * @return PRLVersion or null if error.
5847 */
5848 @Override
5849 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005850 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005851 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852
5853 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005854 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855 if (phone == null) {
5856 return null;
5857 }
5858 String cdmaPrlVersion = null;
5859 try {
5860 cdmaPrlVersion = phone.getCdmaPrlVersion();
5861 } catch (Exception e) {
5862 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5863 }
5864 return cdmaPrlVersion;
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005867 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005868 }
5869
5870 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005871 * Get snapshot of Telephony histograms
5872 * @return List of Telephony histograms
5873 * @hide
5874 */
5875 @Override
5876 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5878 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879
5880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 return RIL.getTelephonyRILTimingHistograms();
5883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005886 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005887
5888 /**
5889 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005890 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5891 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005892 * Require system privileges. In the future we may add this to carrier APIs.
5893 *
Michele Berionne482f8202018-11-27 18:57:59 -08005894 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005895 */
5896 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005897 @TelephonyManager.SetCarrierRestrictionResult
5898 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005899 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005900 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005901
Michele Berionne482f8202018-11-27 18:57:59 -08005902 if (carrierRestrictionRules == null) {
5903 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005904 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 final long identity = Binder.clearCallingIdentity();
5907 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005908 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005909 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005913 }
5914
5915 /**
5916 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005917 * Get the allowed carrier list and the excluded carrier list, including the priority between
5918 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005919 * Require system privileges. In the future we may add this to carrier APIs.
5920 *
Michele Berionne482f8202018-11-27 18:57:59 -08005921 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005922 */
5923 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005924 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005925 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927
5928 final long identity = Binder.clearCallingIdentity();
5929 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005930 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5931 if (response instanceof CarrierRestrictionRules) {
5932 return (CarrierRestrictionRules) response;
5933 }
5934 // Response is an Exception of some kind,
5935 // which is signalled to the user as a NULL retval
5936 return null;
5937 } catch (Exception e) {
5938 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5939 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 } finally {
5941 Binder.restoreCallingIdentity(identity);
5942 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005943 }
5944
fionaxu59545b42016-05-25 15:53:37 -07005945 /**
5946 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5947 * @param subId the subscription ID that this action applies to.
5948 * @param enabled control enable or disable metered apns.
5949 * {@hide}
5950 */
5951 @Override
5952 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5953 enforceModifyPermission();
5954 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955
5956 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005957 if (phone == null) {
5958 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5959 return;
5960 }
5961 try {
5962 phone.carrierActionSetMeteredApnsEnabled(enabled);
5963 } catch (Exception e) {
5964 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005967 }
5968 }
5969
5970 /**
5971 * Action set from carrier signalling broadcast receivers to enable/disable radio
5972 * @param subId the subscription ID that this action applies to.
5973 * @param enabled control enable or disable radio.
5974 * {@hide}
5975 */
5976 @Override
5977 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5978 enforceModifyPermission();
5979 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980
5981 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005982 if (phone == null) {
5983 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5984 return;
5985 }
5986 try {
5987 phone.carrierActionSetRadioEnabled(enabled);
5988 } catch (Exception e) {
5989 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 } finally {
5991 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005992 }
5993 }
5994
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005995 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005996 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5997 * network status based on which carrier apps could apply actions accordingly,
5998 * enable/disable default url handler for example.
5999 *
6000 * @param subId the subscription ID that this action applies to.
6001 * @param report control start/stop reporting the default network status.
6002 * {@hide}
6003 */
6004 @Override
6005 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6006 enforceModifyPermission();
6007 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008
6009 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006010 if (phone == null) {
6011 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6012 return;
6013 }
6014 try {
6015 phone.carrierActionReportDefaultNetworkStatus(report);
6016 } catch (Exception e) {
6017 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 } finally {
6019 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006020 }
6021 }
6022
6023 /**
fionaxud9622282017-07-17 17:51:30 -07006024 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6025 * @param subId the subscription ID that this action applies to.
6026 * {@hide}
6027 */
6028 @Override
6029 public void carrierActionResetAll(int subId) {
6030 enforceModifyPermission();
6031 final Phone phone = getPhone(subId);
6032 if (phone == null) {
6033 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6034 return;
6035 }
6036 try {
6037 phone.carrierActionResetAll();
6038 } catch (Exception e) {
6039 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6040 }
6041 }
6042
6043 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006044 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6045 * bug report is being generated.
6046 */
6047 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006048 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006049 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6050 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006051 writer.println("Permission Denial: can't dump Phone from pid="
6052 + Binder.getCallingPid()
6053 + ", uid=" + Binder.getCallingUid()
6054 + "without permission "
6055 + android.Manifest.permission.DUMP);
6056 return;
6057 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006058 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006059 }
Jack Yueb89b242016-06-22 13:27:47 -07006060
Brad Ebingerdac2f002018-04-03 15:17:52 -07006061 @Override
6062 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6063 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6064 throws RemoteException {
6065 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6066 }
6067
Jack Yueb89b242016-06-22 13:27:47 -07006068 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006069 * Get aggregated video call data usage since boot.
6070 *
6071 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6072 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006073 * {@hide}
6074 */
6075 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006076 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006077 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6078 null);
6079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 final long identity = Binder.clearCallingIdentity();
6081 try {
6082 // NetworkStatsService keeps tracking the active network interface and identity. It
6083 // records the delta with the corresponding network identity.
6084 // We just return the total video call data usage snapshot since boot.
6085 Phone phone = getPhone(subId);
6086 if (phone != null) {
6087 return phone.getVtDataUsage(perUidStats);
6088 }
6089 return null;
6090 } finally {
6091 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006092 }
Jack Yueb89b242016-06-22 13:27:47 -07006093 }
Jack Yu75ab2952016-07-08 14:29:33 -07006094
6095 /**
6096 * Policy control of data connection. Usually used when data limit is passed.
6097 * @param enabled True if enabling the data, otherwise disabling.
6098 * @param subId Subscription index
6099 * {@hide}
6100 */
6101 @Override
6102 public void setPolicyDataEnabled(boolean enabled, int subId) {
6103 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
6107 Phone phone = getPhone(subId);
6108 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006109 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 }
6111 } finally {
6112 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006113 }
6114 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006115
6116 /**
6117 * Get Client request stats
6118 * @return List of Client Request Stats
6119 * @hide
6120 */
6121 @Override
6122 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006124 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006125 return null;
6126 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006127 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 final long identity = Binder.clearCallingIdentity();
6130 try {
6131 if (phone != null) {
6132 return phone.getClientRequestStats();
6133 }
6134
6135 return null;
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006139 }
6140
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006141 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006142 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006143 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006144 }
Jack Yueb4124c2017-02-16 15:32:43 -08006145
6146 /**
Grace Chen70990072017-03-24 17:21:30 -07006147 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006148 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006149 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006150 * @param state State of SIM (power down, power up, pass through)
6151 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6152 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6153 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006154 *
6155 **/
6156 @Override
Grace Chen70990072017-03-24 17:21:30 -07006157 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006158 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006159 Phone phone = PhoneFactory.getPhone(slotIndex);
6160
vagdeviaf9a5b92018-08-15 16:01:53 -07006161 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 final long identity = Binder.clearCallingIdentity();
6164 try {
6165 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006166 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 }
6168 } finally {
6169 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006170 }
6171 }
Shuo Qiandd210312017-04-12 22:11:33 +00006172
Tyler Gunn65d45c22017-06-05 11:22:26 -07006173 private boolean isUssdApiAllowed(int subId) {
6174 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006175 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006176 if (configManager == null) {
6177 return false;
6178 }
6179 PersistableBundle pb = configManager.getConfigForSubId(subId);
6180 if (pb == null) {
6181 return false;
6182 }
6183 return pb.getBoolean(
6184 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6185 }
6186
Shuo Qiandd210312017-04-12 22:11:33 +00006187 /**
6188 * Check if phone is in emergency callback mode
6189 * @return true if phone is in emergency callback mode
6190 * @param subId sub id
6191 */
goneil9c5f4872017-12-05 14:07:56 -08006192 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006193 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006194 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006195 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196
6197 final long identity = Binder.clearCallingIdentity();
6198 try {
6199 if (phone != null) {
6200 return phone.isInEcm();
6201 } else {
6202 return false;
6203 }
6204 } finally {
6205 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006206 }
6207 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006208
6209 /**
6210 * Get the current signal strength information for the given subscription.
6211 * Because this information is not updated when the device is in a low power state
6212 * it should not be relied-upon to be current.
6213 * @param subId Subscription index
6214 * @return the most recent cached signal strength info from the modem
6215 */
6216 @Override
6217 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006218 final long identity = Binder.clearCallingIdentity();
6219 try {
6220 Phone p = getPhone(subId);
6221 if (p == null) {
6222 return null;
6223 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225 return p.getSignalStrength();
6226 } finally {
6227 Binder.restoreCallingIdentity(identity);
6228 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006229 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006230
Pengquan Meng77b7f132018-08-22 14:49:57 -07006231 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006232 * Get the current modem radio state for the given slot.
6233 * @param slotIndex slot index.
6234 * @param callingPackage the name of the package making the call.
6235 * @return the current radio power state from the modem
6236 */
6237 @Override
6238 public int getRadioPowerState(int slotIndex, String callingPackage) {
6239 Phone phone = PhoneFactory.getPhone(slotIndex);
6240 if (phone != null) {
6241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6242 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6243 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6244 }
6245
6246 final long identity = Binder.clearCallingIdentity();
6247 try {
6248 return phone.getRadioPowerState();
6249 } finally {
6250 Binder.restoreCallingIdentity(identity);
6251 }
6252 }
6253 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6254 }
6255
6256 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006257 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6258 *
6259 * <p>Requires one of the following permissions:
6260 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6261 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6262 * privileges.
6263 *
6264 * @param subId subscription id
6265 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6266 * {@code false}.
6267 */
6268 @Override
6269 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006270 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6271 null /* message */);
6272
Pengquan Menga1bb6272018-09-06 09:59:22 -07006273 boolean isEnabled = false;
6274 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006275 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006276 Phone phone = getPhone(subId);
6277 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006278 } catch (Exception e) {
6279 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6280 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006281 } finally {
6282 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006283 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006284 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006285 }
6286
6287
6288 /**
6289 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6290 *
6291 * <p> Requires permission:
6292 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6293 * privileges.
6294 *
6295 * @param subId subscription id
6296 * @param isEnabled {@code true} means enable, {@code false} means disable.
6297 */
6298 @Override
6299 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6301 mApp, subId, "setDataRoamingEnabled");
6302
Pengquan Menga1bb6272018-09-06 09:59:22 -07006303 final long identity = Binder.clearCallingIdentity();
6304 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006305 Phone phone = getPhone(subId);
6306 if (phone != null) {
6307 phone.setDataRoamingEnabled(isEnabled);
6308 }
6309 } finally {
6310 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006311 }
6312 }
6313
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006314 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006315 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006316 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6317 mApp, subId, "isManualNetworkSelectionAllowed");
6318
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006319 boolean isAllowed = true;
6320 final long identity = Binder.clearCallingIdentity();
6321 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006322 Phone phone = getPhone(subId);
6323 if (phone != null) {
6324 isAllowed = phone.isCspPlmnEnabled();
6325 }
6326 } finally {
6327 Binder.restoreCallingIdentity(identity);
6328 }
6329 return isAllowed;
6330 }
6331
6332 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006333 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006334 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006335 try {
6336 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006337 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006338 } catch (SecurityException e) {
6339 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6340 // has carrier privileges on an active UICC
6341 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6342 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006343 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006344 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006345 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006346
6347 final long identity = Binder.clearCallingIdentity();
6348 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006349 UiccController uiccController = UiccController.getInstance();
6350 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006351 if (hasReadPermission) {
6352 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006353 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006354
6355 // Remove private info if the caller doesn't have access
6356 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6357 for (UiccCardInfo cardInfo : cardInfos) {
6358 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6359 // is available
6360 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6361 if (card == null || card.getUiccProfile() == null) {
6362 // assume no access if the card or profile is unavailable
6363 filteredInfos.add(cardInfo.getUnprivileged());
6364 continue;
6365 }
6366 UiccProfile profile = card.getUiccProfile();
6367 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6368 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6369 filteredInfos.add(cardInfo);
6370 } else {
6371 filteredInfos.add(cardInfo.getUnprivileged());
6372 }
6373 }
6374 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006375 } finally {
6376 Binder.restoreCallingIdentity(identity);
6377 }
6378 }
6379
6380 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006381 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006382 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 final long identity = Binder.clearCallingIdentity();
6385 try {
6386 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6387 if (slots == null) {
6388 Rlog.i(LOG_TAG, "slots is null.");
6389 return null;
6390 }
6391
6392 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6393 for (int i = 0; i < slots.length; i++) {
6394 UiccSlot slot = slots[i];
6395 if (slot == null) {
6396 continue;
6397 }
6398
Jordan Liu7be7e652019-05-06 18:55:02 +00006399 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 UiccCard card = slot.getUiccCard();
6401 if (card != null) {
6402 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006403 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404 cardId = slot.getIccId();
6405 }
6406
6407 int cardState = 0;
6408 switch (slot.getCardState()) {
6409 case CARDSTATE_ABSENT:
6410 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6411 break;
6412 case CARDSTATE_PRESENT:
6413 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6414 break;
6415 case CARDSTATE_ERROR:
6416 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6417 break;
6418 case CARDSTATE_RESTRICTED:
6419 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6420 break;
6421 default:
6422 break;
6423
6424 }
6425
6426 infos[i] = new UiccSlotInfo(
6427 slot.isActive(),
6428 slot.isEuicc(),
6429 cardId,
6430 cardState,
6431 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006432 slot.isExtendedApduSupported(),
6433 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434 }
6435 return infos;
6436 } finally {
6437 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006438 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006439 }
6440
6441 @Override
6442 public boolean switchSlots(int[] physicalSlots) {
6443 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444
6445 final long identity = Binder.clearCallingIdentity();
6446 try {
6447 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006451 }
Jack Yu4c988042018-02-27 15:30:01 -08006452
6453 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006454 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006455 final long identity = Binder.clearCallingIdentity();
6456 try {
6457 return UiccController.getInstance().getCardIdForDefaultEuicc();
6458 } finally {
6459 Binder.restoreCallingIdentity(identity);
6460 }
6461 }
6462
6463 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006464 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6465 enforceModifyPermission();
6466 final Phone phone = getPhone(subId);
6467 if (phone == null) {
6468 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6469 return;
6470 }
6471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 final long identity = Binder.clearCallingIdentity();
6473 try {
6474 phone.setRadioIndicationUpdateMode(filters, mode);
6475 } finally {
6476 Binder.restoreCallingIdentity(identity);
6477 }
Jack Yu4c988042018-02-27 15:30:01 -08006478 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006479
6480 /**
goneil47ffb6e2018-04-06 15:40:58 -07006481 * A test API to reload the UICC profile.
6482 *
6483 * <p>Requires that the calling app has permission
6484 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6485 * @hide
6486 */
6487 @Override
6488 public void refreshUiccProfile(int subId) {
6489 enforceModifyPermission();
6490
6491 final long identity = Binder.clearCallingIdentity();
6492 try {
6493 Phone phone = getPhone(subId);
6494 if (phone == null) {
6495 return;
6496 }
6497 UiccCard uiccCard = phone.getUiccCard();
6498 if (uiccCard == null) {
6499 return;
6500 }
6501 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6502 if (uiccProfile == null) {
6503 return;
6504 }
6505 uiccProfile.refresh();
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
6508 }
6509 }
6510
6511 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006512 * Returns false if the mobile data is disabled by default, otherwise return true.
6513 */
6514 private boolean getDefaultDataEnabled() {
6515 return "true".equalsIgnoreCase(
6516 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6517 }
6518
6519 /**
6520 * Returns true if the data roaming is enabled by default, i.e the system property
6521 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6522 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6523 */
6524 private boolean getDefaultDataRoamingEnabled(int subId) {
6525 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006526 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006527 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6528 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6529 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6530 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6531 return isDataRoamingEnabled;
6532 }
6533
6534 /**
6535 * Returns the default network type for the given {@code subId}, if the default network type is
6536 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6537 */
6538 private int getDefaultNetworkType(int subId) {
6539 return Integer.parseInt(
6540 TelephonyManager.getTelephonyProperty(
6541 mSubscriptionController.getPhoneId(subId),
6542 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6543 String.valueOf(Phone.PREFERRED_NT_MODE)));
6544 }
fionaxua13278b2018-03-21 00:08:13 -07006545
6546 @Override
6547 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006548 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
6553 final Phone phone = getPhone(subId);
6554 if (phone == null) {
6555 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6556 return;
6557 }
chen xueaba88a2019-03-15 13:15:10 -07006558 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6559 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 } finally {
6561 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006562 }
fionaxua13278b2018-03-21 00:08:13 -07006563 }
6564
6565 @Override
6566 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006567 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568
6569 final long identity = Binder.clearCallingIdentity();
6570 try {
6571 final Phone phone = getPhone(subId);
6572 if (phone == null) {
6573 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6574 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6575 }
6576 return phone.getCarrierIdListVersion();
6577 } finally {
6578 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006579 }
fionaxua13278b2018-03-21 00:08:13 -07006580 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006581
6582 @Override
6583 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6585 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6586 return -1;
6587 }
6588
6589 final long identity = Binder.clearCallingIdentity();
6590 try {
6591 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6592 } finally {
6593 Binder.restoreCallingIdentity(identity);
6594 }
6595 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006596
6597 @Override
6598 public int getCdmaRoamingMode(int subId) {
6599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6600 mApp, subId, "getCdmaRoamingMode");
6601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6605 } finally {
6606 Binder.restoreCallingIdentity(identity);
6607 }
6608 }
6609
6610 @Override
6611 public boolean setCdmaRoamingMode(int subId, int mode) {
6612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6613 mApp, subId, "setCdmaRoamingMode");
6614
6615 final long identity = Binder.clearCallingIdentity();
6616 try {
6617 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
6620 }
6621 }
6622
6623 @Override
6624 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6626 mApp, subId, "setCdmaSubscriptionMode");
6627
6628 final long identity = Binder.clearCallingIdentity();
6629 try {
6630 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6631 } finally {
6632 Binder.restoreCallingIdentity(identity);
6633 }
6634 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006635
6636 private void ensureUserRunning(int userId) {
6637 if (!mUserManager.isUserRunning(userId)) {
6638 throw new IllegalStateException("User " + userId + " does not exist or not running");
6639 }
6640 }
6641
6642 /**
6643 * Returns a list of SMS apps on a given user.
6644 *
6645 * Only the shell user (UID 2000 or 0) can call it.
6646 * Target user must be running.
6647 */
6648 @Override
6649 public String[] getSmsApps(int userId) {
6650 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6651 ensureUserRunning(userId);
6652
6653 final Collection<SmsApplicationData> apps =
6654 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6655
6656 String[] ret = new String[apps.size()];
6657 int i = 0;
6658 for (SmsApplicationData app : apps) {
6659 ret[i++] = app.mPackageName;
6660 }
6661 return ret;
6662 }
6663
6664 /**
6665 * Returns the default SMS app package name on a given user.
6666 *
6667 * Only the shell user (UID 2000 or 0) can call it.
6668 * Target user must be running.
6669 */
6670 @Override
6671 public String getDefaultSmsApp(int userId) {
6672 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6673 ensureUserRunning(userId);
6674
6675 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6676 /* updateIfNeeded= */ true, userId);
6677 return cn == null ? null : cn.getPackageName();
6678 }
6679
6680 /**
6681 * Set a package as the default SMS app on a given user.
6682 *
6683 * Only the shell user (UID 2000 or 0) can call it.
6684 * Target user must be running.
6685 */
6686 @Override
6687 public void setDefaultSmsApp(int userId, String packageName) {
6688 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6689 ensureUserRunning(userId);
6690
6691 boolean found = false;
6692 for (String pkg : getSmsApps(userId)) {
6693 if (TextUtils.equals(packageName, pkg)) {
6694 found = true;
6695 break;
6696 }
6697 }
6698 if (!found) {
6699 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6700 }
6701
6702 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6703 }
sqianc5eccab2018-10-19 18:46:41 -07006704
6705 @Override
sqian8c685422019-02-22 15:55:18 -08006706 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006707 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006709 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006710 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6711 }
6712 final long identity = Binder.clearCallingIdentity();
6713 try {
sqian854d44b2018-12-12 16:48:18 -08006714 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6715 for (Phone phone: PhoneFactory.getPhones()) {
6716 if (phone.getEmergencyNumberTracker() != null
6717 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6718 emergencyNumberListInternal.put(
6719 phone.getSubId(),
6720 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6721 }
sqian11b7a0e2018-12-05 18:48:28 -08006722 }
sqian854d44b2018-12-12 16:48:18 -08006723 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
sqianc5eccab2018-10-19 18:46:41 -07006727 }
6728
6729 @Override
sqian8c685422019-02-22 15:55:18 -08006730 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006731 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006732 if (!exactMatch) {
6733 TelephonyPermissions
6734 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006735 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006736 }
6737 final long identity = Binder.clearCallingIdentity();
6738 try {
sqian854d44b2018-12-12 16:48:18 -08006739 for (Phone phone: PhoneFactory.getPhones()) {
6740 if (phone.getEmergencyNumberTracker() != null
6741 && phone.getEmergencyNumberTracker() != null) {
6742 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6743 number, exactMatch)) {
6744 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006745 }
6746 }
sqian11b7a0e2018-12-05 18:48:28 -08006747 }
6748 return false;
6749 } finally {
6750 Binder.restoreCallingIdentity(identity);
6751 }
6752 }
6753
sqianf4ca7ed2019-01-15 18:32:07 -08006754 /**
6755 * Update emergency number list for test mode.
6756 */
6757 @Override
6758 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6759 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6760 "updateEmergencyNumberListTestMode");
6761
6762 final long identity = Binder.clearCallingIdentity();
6763 try {
6764 for (Phone phone: PhoneFactory.getPhones()) {
6765 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6766 if (tracker != null) {
6767 tracker.executeEmergencyNumberTestModeCommand(action, num);
6768 }
6769 }
6770 } finally {
6771 Binder.restoreCallingIdentity(identity);
6772 }
6773 }
6774
6775 /**
6776 * Get the full emergency number list for test mode.
6777 */
6778 @Override
6779 public List<String> getEmergencyNumberListTestMode() {
6780 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6781 "getEmergencyNumberListTestMode");
6782
6783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 Set<String> emergencyNumbers = new HashSet<>();
6786 for (Phone phone: PhoneFactory.getPhones()) {
6787 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6788 if (tracker != null) {
6789 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6790 emergencyNumbers.add(num.getNumber());
6791 }
6792 }
6793 }
6794 return new ArrayList<>(emergencyNumbers);
6795 } finally {
6796 Binder.restoreCallingIdentity(identity);
6797 }
6798 }
6799
chen xud6b45bd2018-10-30 22:27:10 -07006800 @Override
6801 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6802 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6803 Phone phone = getPhone(subId);
6804 if (phone == null) {
6805 return null;
6806 }
6807 final long identity = Binder.clearCallingIdentity();
6808 try {
6809 UiccProfile profile = UiccController.getInstance()
6810 .getUiccProfileForPhone(phone.getPhoneId());
6811 if (profile != null) {
6812 return profile.getCertsFromCarrierPrivilegeAccessRules();
6813 }
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
6816 }
6817 return null;
6818 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006819
6820 /**
6821 * Enable or disable a modem stack.
6822 */
6823 @Override
6824 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6825 enforceModifyPermission();
6826
6827 final long identity = Binder.clearCallingIdentity();
6828 try {
6829 Phone phone = PhoneFactory.getPhone(slotIndex);
6830 if (phone == null) {
6831 return false;
6832 } else {
6833 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6834 }
6835 } finally {
6836 Binder.restoreCallingIdentity(identity);
6837 }
6838 }
Michelecea4cf22018-12-21 15:00:11 -08006839
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006840 /**
6841 * Whether a modem stack is enabled or not.
6842 */
6843 @Override
6844 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6845 Phone phone = PhoneFactory.getPhone(slotIndex);
6846 if (phone == null) return false;
6847
6848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6849 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6850 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6851 }
6852
6853 final long identity = Binder.clearCallingIdentity();
6854 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006855 try {
6856 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6857 } catch (NoSuchElementException ex) {
6858 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6859 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006860 } finally {
6861 Binder.restoreCallingIdentity(identity);
6862 }
6863 }
6864
Michelecea4cf22018-12-21 15:00:11 -08006865 @Override
Michele0ea7d782019-03-19 14:58:42 -07006866 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006867 enforceModifyPermission();
6868
6869 final long identity = Binder.clearCallingIdentity();
6870 try {
6871 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006872 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006873 .commit();
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876 }
6877 }
6878
6879 @Override
Michele0ea7d782019-03-19 14:58:42 -07006880 @TelephonyManager.IsMultiSimSupportedResult
6881 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006882 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006883 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6884 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006885 }
Michelecea4cf22018-12-21 15:00:11 -08006886
6887 final long identity = Binder.clearCallingIdentity();
6888 try {
Michele0ea7d782019-03-19 14:58:42 -07006889 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006890 } finally {
6891 Binder.restoreCallingIdentity(identity);
6892 }
6893 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006894
Michele0ea7d782019-03-19 14:58:42 -07006895 @TelephonyManager.IsMultiSimSupportedResult
6896 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006897 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6898 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6899 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006900 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6901 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006902 }
6903 // Check if the hardware supports multisim functionality. If usage of multisim is not
6904 // supported by the modem, indicate that it is restricted.
6905 PhoneCapability staticCapability =
6906 mPhoneConfigurationManager.getStaticPhoneCapability();
6907 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006908 loge("isMultiSimSupportedInternal: no static configuration available");
6909 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006910 }
6911 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006912 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6913 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006914 }
6915 // Check if support of multiple SIMs is restricted by carrier
6916 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006917 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006918 }
6919
Michele0ea7d782019-03-19 14:58:42 -07006920 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006921 }
6922
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006923 /**
6924 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006925 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6926 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6927 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006928 * @param numOfSims number of active sims we want to switch to
6929 */
6930 @Override
6931 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006932 if (numOfSims == 1) {
6933 enforceModifyPermission();
6934 } else {
6935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6936 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6937 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006938 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006939
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006940 try {
Michele30b57b22019-03-01 12:01:14 -08006941 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006942 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006943 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6944 return;
6945 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006946 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
6949 }
6950 }
6951
6952 /**
chen xub4baa772019-04-03 10:23:41 -07006953 * Get whether making changes to modem configurations will trigger reboot.
6954 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006955 */
6956 @Override
chen xub4baa772019-04-03 10:23:41 -07006957 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6959 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6960 return false;
6961 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006962 final long identity = Binder.clearCallingIdentity();
6963 try {
6964 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6965 } finally {
6966 Binder.restoreCallingIdentity(identity);
6967 }
6968 }
6969
Nathan Harold29f5f052019-02-15 13:41:57 -08006970 private void updateModemStateMetrics() {
6971 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6972 // TODO: check the state for each modem if the api is ready.
6973 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6974 }
6975
Pengquan Meng3889a572019-01-23 11:16:29 -08006976 @Override
6977 public int[] getSlotsMapping() {
6978 enforceReadPrivilegedPermission("getSlotsMapping");
6979
6980 final long identity = Binder.clearCallingIdentity();
6981 try {
6982 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6983 // All logical slots should have a mapping to a physical slot.
6984 int[] logicalSlotsMapping = new int[phoneCount];
6985 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6986 for (int i = 0; i < slotInfos.length; i++) {
6987 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6988 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6989 }
6990 }
6991 return logicalSlotsMapping;
6992 } finally {
6993 Binder.restoreCallingIdentity(identity);
6994 }
6995 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006996
6997 /**
6998 * Get the IRadio HAL Version
6999 */
7000 @Override
7001 public int getRadioHalVersion() {
7002 Phone phone = getDefaultPhone();
7003 if (phone == null) return -1;
7004 HalVersion hv = phone.getHalVersion();
7005 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7006 return hv.major * 100 + hv.minor;
7007 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007008
7009 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007010 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7011 * corresponding network requests on a subId.
7012 *
7013 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007014 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007015 * 2) APN is un-metered for this subscription, or
7016 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7017 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7018 *
7019 * @return whether data is allowed for a apn type.
7020 *
7021 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007022 */
7023 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007024 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007026 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7027 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007028 }
7029
7030 // Now that all security checks passes, perform the operation as ourselves.
7031 final long identity = Binder.clearCallingIdentity();
7032 try {
7033 Phone phone = getPhone(subId);
7034 if (phone == null) return false;
7035
7036 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007037 apnType), phone);
7038 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7039 } finally {
7040 Binder.restoreCallingIdentity(identity);
7041 }
7042 }
7043
7044 @Override
7045 public boolean isApnMetered(int apnType, int subId) {
7046 enforceReadPrivilegedPermission("isApnMetered");
7047
7048 // Now that all security checks passes, perform the operation as ourselves.
7049 final long identity = Binder.clearCallingIdentity();
7050 try {
7051 Phone phone = getPhone(subId);
7052 if (phone == null) return true; // By default return true.
7053
7054 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
7055 apnType), phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007056 } finally {
7057 Binder.restoreCallingIdentity(identity);
7058 }
7059 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007060
7061 @Override
7062 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7063 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7064 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7065 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7066 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7067 }
7068 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7069 Intent intent = new Intent();
7070 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7071 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7072 // Bring up choose default SMS subscription dialog right now
7073 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7074 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7075 mApp.startActivity(intent);
7076 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007077}