blob: 7dca3cdb2cacda50118b00c953551933605d7a14 [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 Ebinger1ce9c432019-07-16 13:19:44 -070051import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070052import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070053import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080058import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070059import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080060import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080061import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070062import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070063import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080064import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070066import android.telephony.CellInfoGsm;
67import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070068import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070069import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070070import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070071import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080072import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070073import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080074import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070075import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080076import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080077import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070078import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080079import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070080import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080082import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070094import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080095import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070097import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080098import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070099import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700101import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800102import android.telephony.ims.aidl.IImsMmTelFeature;
103import android.telephony.ims.aidl.IImsRcsFeature;
104import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800106import android.telephony.ims.feature.MmTelFeature;
107import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800108import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800110import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800112import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800113import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800114
Andrew Lee312e8172014-10-23 17:01:36 -0700115import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800116import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700118import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700119import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800120import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700121import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800124import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700125import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800126import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800128import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700129import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100130import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700131import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700132import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700134import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800135import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700136import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700137import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700138import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700139import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700140import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700141import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700142import com.android.internal.telephony.SmsApplication;
143import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700144import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700145import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800146import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800147import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700148import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800149import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700150import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800151import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800152import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900153import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.uicc.IccIoResult;
155import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800156import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700157import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800158import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800160import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000161import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700162import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800163import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700165import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800166import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700167import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700168import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800169
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700170import java.io.FileDescriptor;
171import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800173import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700174import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800175import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800176import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800177import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100178import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700180import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182
183/**
184 * Implementation of the ITelephony interface.
185 */
Santos Cordon117fee72014-05-16 17:56:12 -0700186public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187 private static final String LOG_TAG = "PhoneInterfaceManager";
188 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
189 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800190 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191
192 // Message codes used with mMainThreadHandler
193 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700194 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
195 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196 private static final int CMD_OPEN_CHANNEL = 9;
197 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
198 private static final int CMD_CLOSE_CHANNEL = 11;
199 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800200 private static final int CMD_NV_READ_ITEM = 13;
201 private static final int EVENT_NV_READ_ITEM_DONE = 14;
202 private static final int CMD_NV_WRITE_ITEM = 15;
203 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
204 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
205 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700206 private static final int CMD_RESET_MODEM_CONFIG = 19;
207 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800208 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
209 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
210 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
211 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800212 private static final int CMD_SEND_ENVELOPE = 25;
213 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000214 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
215 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700216 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
217 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
218 private static final int CMD_EXCHANGE_SIM_IO = 31;
219 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800220 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
221 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700222 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
223 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700224 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
225 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700226 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
227 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
228 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
229 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700230 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
231 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
232 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
233 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700234 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800235 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
236 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000237 private static final int CMD_SWITCH_SLOTS = 50;
238 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700239 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
240 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
241 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
242 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
243 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
244 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
245 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
246 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700247 private static final int CMD_GET_ALL_CELL_INFO = 60;
248 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
249 private static final int CMD_GET_CELL_LOCATION = 62;
250 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700251 private static final int CMD_MODEM_REBOOT = 64;
252 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700253 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
254 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800255 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
256 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700257 private static final int CMD_GET_MODEM_STATUS = 70;
258 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800260 // Parameters of select command.
261 private static final int SELECT_COMMAND = 0xA4;
262 private static final int SELECT_P1 = 0x04;
263 private static final int SELECT_P2 = 0;
264 private static final int SELECT_P3 = 0x10;
265
Pengquan Meng85728fb2018-03-12 16:31:21 -0700266 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
267 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
268 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
269
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 /** The singleton instance. */
271 private static PhoneInterfaceManager sInstance;
272
Wink Saville3ab207e2014-11-20 13:07:20 -0800273 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800274 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700275 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800276 private AppOpsManager mAppOps;
277 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800278 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700280 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281
Derek Tan97ebb422014-09-05 16:55:38 -0700282 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
283 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800284 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800285 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700286
Michelecea4cf22018-12-21 15:00:11 -0800287 // String to store multi SIM allowed
288 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
289
Derek Tan740e1672017-06-27 14:56:27 -0700290 // The AID of ISD-R.
291 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
292
yinxub1bed742017-04-17 11:45:04 -0700293 private NetworkScanRequestTracker mNetworkScanRequestTracker;
294
David Kelly5e06a7f2018-03-12 14:10:59 +0000295 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
296 private static final int MANUFACTURER_CODE_LENGTH = 8;
297
Derek Tan89e89d42014-07-08 17:00:10 -0700298 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700299 * A request object to use for transmitting data to an ICC.
300 */
301 private static final class IccAPDUArgument {
302 public int channel, cla, command, p1, p2, p3;
303 public String data;
304
305 public IccAPDUArgument(int channel, int cla, int command,
306 int p1, int p2, int p3, String data) {
307 this.channel = channel;
308 this.cla = cla;
309 this.command = command;
310 this.p1 = p1;
311 this.p2 = p2;
312 this.p3 = p3;
313 this.data = data;
314 }
315 }
316
317 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700318 * A request object to use for transmitting data to an ICC.
319 */
320 private static final class ManualNetworkSelectionArgument {
321 public OperatorInfo operatorInfo;
322 public boolean persistSelection;
323
324 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
325 this.operatorInfo = operatorInfo;
326 this.persistSelection = persistSelection;
327 }
328 }
329
330 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
332 * request after sending. The main thread will notify the request when it is complete.
333 */
334 private static final class MainThreadRequest {
335 /** The argument to use for the request */
336 public Object argument;
337 /** The result of the request that is run on the main thread */
338 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800339 // The subscriber id that this request applies to. Defaults to
340 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
341 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
Nathan Harold92bed182018-10-12 18:16:49 -0700343 // In cases where subId is unavailable, the caller needs to specify the phone.
344 public Phone phone;
345
vagdeviaf9a5b92018-08-15 16:01:53 -0700346 public WorkSource workSource;
347
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 public MainThreadRequest(Object argument) {
349 this.argument = argument;
350 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800351
Nathan Harold92bed182018-10-12 18:16:49 -0700352 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
353 this.argument = argument;
354 if (phone != null) {
355 this.phone = phone;
356 }
357 this.workSource = workSource;
358 }
359
vagdeviaf9a5b92018-08-15 16:01:53 -0700360 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800361 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800362 if (subId != null) {
363 this.subId = subId;
364 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700365 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 }
368
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800369 private static final class IncomingThirdPartyCallArgs {
370 public final ComponentName component;
371 public final String callId;
372 public final String callerDisplayName;
373
374 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
375 String callerDisplayName) {
376 this.component = component;
377 this.callId = callId;
378 this.callerDisplayName = callerDisplayName;
379 }
380 }
381
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 /**
383 * A handler that processes messages on the main thread in the phone process. Since many
384 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
385 * inbound binder threads to the main thread in the phone process. The Binder thread
386 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
387 * on, which will be notified when the operation completes and will contain the result of the
388 * request.
389 *
390 * <p>If a MainThreadRequest object is provided in the msg.obj field,
391 * note that request.result must be set to something non-null for the calling thread to
392 * unblock.
393 */
394 private final class MainThreadHandler extends Handler {
395 @Override
396 public void handleMessage(Message msg) {
397 MainThreadRequest request;
398 Message onCompleted;
399 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800400 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800402 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403
404 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700405 case CMD_HANDLE_USSD_REQUEST: {
406 request = (MainThreadRequest) msg.obj;
407 final Phone phone = getPhoneFromRequest(request);
408 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
409 String ussdRequest = ussdObject.first;
410 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700411
Pengquan Menga1bb6272018-09-06 09:59:22 -0700412 if (!isUssdApiAllowed(request.subId)) {
413 // Carrier does not support use of this API, return failure.
414 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
415 UssdResponse response = new UssdResponse(ussdRequest, null);
416 Bundle returnData = new Bundle();
417 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
418 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700419
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 request.result = true;
421 notifyRequester(request);
422 return;
423 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700424
Pengquan Menga1bb6272018-09-06 09:59:22 -0700425 try {
426 request.result = phone != null
427 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
428 } catch (CallStateException cse) {
429 request.result = false;
430 }
431 // Wake up the requesting thread
432 notifyRequester(request);
433 break;
pkanwar32d516d2016-10-14 19:37:38 -0700434 }
435
Yorke Lee716f67e2015-06-17 15:39:16 -0700436 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700438 final Phone phone = getPhoneFromRequest(request);
439 request.result = phone != null ?
440 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
441 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700443 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800450 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700451 if (uiccCard == null) {
452 loge("iccTransmitApduLogicalChannel: No UICC");
453 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700455 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
457 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700458 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 iccArgument.channel, iccArgument.cla, iccArgument.command,
460 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 break;
464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 ar = (AsyncResult) msg.obj;
467 request = (MainThreadRequest) ar.userObj;
468 if (ar.exception == null && ar.result != null) {
469 request.result = ar.result;
470 } else {
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
472 if (ar.result == null) {
473 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800474 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800476 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 } else {
478 loge("iccTransmitApduLogicalChannel: Unknown exception");
479 }
480 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 break;
483
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
485 request = (MainThreadRequest) msg.obj;
486 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800487 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 if (uiccCard == null) {
489 loge("iccTransmitApduBasicChannel: No UICC");
490 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700491 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 } else {
493 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
494 request);
495 uiccCard.iccTransmitApduBasicChannel(
496 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
497 iccArgument.p3, iccArgument.data, onCompleted);
498 }
499 break;
500
501 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
502 ar = (AsyncResult) msg.obj;
503 request = (MainThreadRequest) ar.userObj;
504 if (ar.exception == null && ar.result != null) {
505 request.result = ar.result;
506 } else {
507 request.result = new IccIoResult(0x6F, 0, (byte[])null);
508 if (ar.result == null) {
509 loge("iccTransmitApduBasicChannel: Empty response");
510 } else if (ar.exception instanceof CommandException) {
511 loge("iccTransmitApduBasicChannel: CommandException: " +
512 ar.exception);
513 } else {
514 loge("iccTransmitApduBasicChannel: Unknown exception");
515 }
516 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 break;
519
520 case CMD_EXCHANGE_SIM_IO:
521 request = (MainThreadRequest) msg.obj;
522 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800523 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 if (uiccCard == null) {
525 loge("iccExchangeSimIO: No UICC");
526 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 } else {
529 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
530 request);
531 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
532 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
533 iccArgument.data, onCompleted);
534 }
535 break;
536
537 case EVENT_EXCHANGE_SIM_IO_DONE:
538 ar = (AsyncResult) msg.obj;
539 request = (MainThreadRequest) ar.userObj;
540 if (ar.exception == null && ar.result != null) {
541 request.result = ar.result;
542 } else {
543 request.result = new IccIoResult(0x6f, 0, (byte[])null);
544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 break;
547
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 case CMD_SEND_ENVELOPE:
549 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800550 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 if (uiccCard == null) {
552 loge("sendEnvelopeWithStatus: No UICC");
553 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700554 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 } else {
556 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
557 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
558 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 break;
560
561 case EVENT_SEND_ENVELOPE_DONE:
562 ar = (AsyncResult) msg.obj;
563 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700564 if (ar.exception == null && ar.result != null) {
565 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
568 if (ar.result == null) {
569 loge("sendEnvelopeWithStatus: Empty response");
570 } else if (ar.exception instanceof CommandException) {
571 loge("sendEnvelopeWithStatus: CommandException: " +
572 ar.exception);
573 } else {
574 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
575 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800576 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700577 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 break;
579
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 case CMD_OPEN_CHANNEL:
581 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800582 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800583 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 if (uiccCard == null) {
585 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800586 request.result = new IccOpenLogicalChannelResponse(-1,
587 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 } else {
590 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800591 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
592 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 break;
595
596 case EVENT_OPEN_CHANNEL_DONE:
597 ar = (AsyncResult) msg.obj;
598 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 int[] result = (int[]) ar.result;
602 int channelId = result[0];
603 byte[] selectResponse = null;
604 if (result.length > 1) {
605 selectResponse = new byte[result.length - 1];
606 for (int i = 1; i < result.length; ++i) {
607 selectResponse[i - 1] = (byte) result[i];
608 }
609 }
610 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 if (ar.result == null) {
614 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 if (ar.exception != null) {
617 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
618 }
619
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700620 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700621 if (ar.exception instanceof CommandException) {
622 CommandException.Error error =
623 ((CommandException) (ar.exception)).getCommandError();
624 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700626 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700627 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 }
629 }
630 openChannelResp = new IccOpenLogicalChannelResponse(
631 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700633 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 break;
636
637 case CMD_CLOSE_CHANNEL:
638 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800639 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 if (uiccCard == null) {
641 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900642 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 } else {
645 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
646 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
647 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 break;
649
650 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800651 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
652 break;
653
654 case CMD_NV_READ_ITEM:
655 request = (MainThreadRequest) msg.obj;
656 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800657 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
658 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800659 break;
660
661 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800667 request.result = "";
668 if (ar.result == null) {
669 loge("nvReadItem: Empty response");
670 } else if (ar.exception instanceof CommandException) {
671 loge("nvReadItem: CommandException: " +
672 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800674 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 }
676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 break;
679
Jake Hambye994d462014-02-03 13:10:13 -0800680 case CMD_NV_WRITE_ITEM:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
683 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800684 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700685 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800686 break;
687
688 case EVENT_NV_WRITE_ITEM_DONE:
689 handleNullReturnEvent(msg, "nvWriteItem");
690 break;
691
692 case CMD_NV_WRITE_CDMA_PRL:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800696 break;
697
698 case EVENT_NV_WRITE_CDMA_PRL_DONE:
699 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
700 break;
701
chen xu6dac5ab2018-10-26 17:39:23 -0700702 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800703 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700704 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800705 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800706 break;
707
chen xu6dac5ab2018-10-26 17:39:23 -0700708 case EVENT_RESET_MODEM_CONFIG_DONE:
709 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800710 break;
711
Jake Hamby7c27be32014-03-03 13:25:59 -0800712 case CMD_GET_PREFERRED_NETWORK_TYPE:
713 request = (MainThreadRequest) msg.obj;
714 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700715 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 break;
717
718 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
719 ar = (AsyncResult) msg.obj;
720 request = (MainThreadRequest) ar.userObj;
721 if (ar.exception == null && ar.result != null) {
722 request.result = ar.result; // Integer
723 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800724 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 if (ar.result == null) {
726 loge("getPreferredNetworkType: Empty response");
727 } else if (ar.exception instanceof CommandException) {
728 loge("getPreferredNetworkType: CommandException: " +
729 ar.exception);
730 } else {
731 loge("getPreferredNetworkType: Unknown exception");
732 }
733 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800735 break;
736
737 case CMD_SET_PREFERRED_NETWORK_TYPE:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
740 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700741 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800742 break;
743
744 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
745 handleNullReturnEvent(msg, "setPreferredNetworkType");
746 break;
747
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000748 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
749 request = (MainThreadRequest)msg.obj;
750 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800751 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000752 break;
753
754 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
755 ar = (AsyncResult)msg.obj;
756 request = (MainThreadRequest)ar.userObj;
757 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700758 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 break;
760
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800761 case CMD_SET_VOICEMAIL_NUMBER:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
764 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800765 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
766 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800767 break;
768
769 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
770 handleNullReturnEvent(msg, "setVoicemailNumber");
771 break;
772
Stuart Scott54788802015-03-30 13:18:01 -0700773 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
776 request);
777 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
778 break;
779
780 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
781 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
782 break;
783
Shishir Agrawal302c8692015-06-19 13:49:39 -0700784 case CMD_PERFORM_NETWORK_SCAN:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
787 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
788 break;
789
790 case EVENT_PERFORM_NETWORK_SCAN_DONE:
791 ar = (AsyncResult) msg.obj;
792 request = (MainThreadRequest) ar.userObj;
793 CellNetworkScanResult cellScanResult;
794 if (ar.exception == null && ar.result != null) {
795 cellScanResult = new CellNetworkScanResult(
796 CellNetworkScanResult.STATUS_SUCCESS,
797 (List<OperatorInfo>) ar.result);
798 } else {
799 if (ar.result == null) {
800 loge("getCellNetworkScanResults: Empty response");
801 }
802 if (ar.exception != null) {
803 loge("getCellNetworkScanResults: Exception: " + ar.exception);
804 }
805 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
806 if (ar.exception instanceof CommandException) {
807 CommandException.Error error =
808 ((CommandException) (ar.exception)).getCommandError();
809 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
810 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
811 } else if (error == CommandException.Error.GENERIC_FAILURE) {
812 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
813 }
814 }
815 cellScanResult = new CellNetworkScanResult(errorCode, null);
816 }
817 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700818 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700819 break;
820
821 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
822 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700823 ManualNetworkSelectionArgument selArg =
824 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700825 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
826 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700827 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
828 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700829 break;
830
831 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700832 ar = (AsyncResult) msg.obj;
833 request = (MainThreadRequest) ar.userObj;
834 if (ar.exception == null) {
835 request.result = true;
836 } else {
837 request.result = false;
838 loge("setNetworkSelectionModeManual " + ar.exception);
839 }
840 notifyRequester(request);
841 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700842 break;
843
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700844 case CMD_GET_MODEM_ACTIVITY_INFO:
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700847 if (defaultPhone != null) {
848 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
849 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700850 break;
851
852 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 if (ar.result == null) {
859 loge("queryModemActivityInfo: Empty response");
860 } else if (ar.exception instanceof CommandException) {
861 loge("queryModemActivityInfo: CommandException: " +
862 ar.exception);
863 } else {
864 loge("queryModemActivityInfo: Unknown exception");
865 }
866 }
Amit Mahajand4766222016-01-28 15:28:28 -0800867 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
868 if (request.result == null) {
869 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
870 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700871 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700872 break;
873
Meng Wang1a7c35a2016-05-05 20:56:15 -0700874 case CMD_SET_ALLOWED_CARRIERS:
875 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800876 CarrierRestrictionRules argument =
877 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800879 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 break;
881
882 case EVENT_SET_ALLOWED_CARRIERS_DONE:
883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result;
887 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800888 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
889 if (ar.exception instanceof CommandException) {
890 loge("setAllowedCarriers: CommandException: " + ar.exception);
891 CommandException.Error error =
892 ((CommandException) (ar.exception)).getCommandError();
893 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
894 request.result =
895 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
896 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 } else {
898 loge("setAllowedCarriers: Unknown exception");
899 }
900 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700901 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700902 break;
903
904 case CMD_GET_ALLOWED_CARRIERS:
905 request = (MainThreadRequest) msg.obj;
906 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800907 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 break;
909
910 case EVENT_GET_ALLOWED_CARRIERS_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result;
915 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800916 request.result = new IllegalStateException(
917 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700918 if (ar.result == null) {
919 loge("getAllowedCarriers: Empty response");
920 } else if (ar.exception instanceof CommandException) {
921 loge("getAllowedCarriers: CommandException: " +
922 ar.exception);
923 } else {
924 loge("getAllowedCarriers: Unknown exception");
925 }
926 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700927 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700928 break;
929
Nathan Haroldb3014052017-01-25 15:57:32 -0800930 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
931 ar = (AsyncResult) msg.obj;
932 request = (MainThreadRequest) ar.userObj;
933 if (ar.exception == null && ar.result != null) {
934 request.result = ar.result;
935 } else {
936 request.result = new IllegalArgumentException(
937 "Failed to retrieve Forbidden Plmns");
938 if (ar.result == null) {
939 loge("getForbiddenPlmns: Empty response");
940 } else {
941 loge("getForbiddenPlmns: Unknown exception");
942 }
943 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700944 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800945 break;
946
947 case CMD_GET_FORBIDDEN_PLMNS:
948 request = (MainThreadRequest) msg.obj;
949 uiccCard = getUiccCardFromRequest(request);
950 if (uiccCard == null) {
951 loge("getForbiddenPlmns() UiccCard is null");
952 request.result = new IllegalArgumentException(
953 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700954 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800955 break;
956 }
957 Integer appType = (Integer) request.argument;
958 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
959 if (uiccApp == null) {
960 loge("getForbiddenPlmns() no app with specified type -- "
961 + appType);
962 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700963 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800964 break;
965 } else {
966 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
967 + " specified type -- " + appType);
968 }
969 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
970 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
971 onCompleted);
972 break;
973
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000974 case CMD_SWITCH_SLOTS:
975 request = (MainThreadRequest) msg.obj;
976 int[] physicalSlots = (int[]) request.argument;
977 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
978 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
979 break;
980
981 case EVENT_SWITCH_SLOTS_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700985 notifyRequester(request);
986 break;
987 case CMD_GET_NETWORK_SELECTION_MODE:
988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
990 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
991 break;
992
993 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 if (ar.exception != null) {
997 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
998 } else {
999 int mode = ((int[]) ar.result)[0];
1000 if (mode == 0) {
1001 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1002 } else {
1003 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1004 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001005 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001006 notifyRequester(request);
1007 break;
1008 case CMD_GET_CDMA_ROAMING_MODE:
1009 request = (MainThreadRequest) msg.obj;
1010 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1011 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1012 break;
1013 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception != null) {
1017 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1018 } else {
1019 request.result = ((int[]) ar.result)[0];
1020 }
1021 notifyRequester(request);
1022 break;
1023 case CMD_SET_CDMA_ROAMING_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1026 int mode = (int) request.argument;
1027 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1028 break;
1029 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 request.result = ar.exception == null;
1033 notifyRequester(request);
1034 break;
1035 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1036 request = (MainThreadRequest) msg.obj;
1037 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1038 int subscriptionMode = (int) request.argument;
1039 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1040 break;
1041 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
1044 request.result = ar.exception == null;
1045 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001046 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 case CMD_GET_ALL_CELL_INFO:
1048 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001050 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001052 case EVENT_GET_ALL_CELL_INFO_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001055 // If a timeout occurs, the response will be null
1056 request.result = (ar.exception == null && ar.result != null)
1057 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 synchronized (request) {
1059 request.notifyAll();
1060 }
1061 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 case CMD_REQUEST_CELL_INFO_UPDATE:
1063 request = (MainThreadRequest) msg.obj;
1064 request.phone.requestCellInfoUpdate(request.workSource,
1065 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1066 break;
1067 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
1070 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1071 try {
1072 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001074 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1075 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001078 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 } else {
1080 // use the result as returned
1081 cb.onCellInfo((List<CellInfo>) ar.result);
1082 }
1083 } catch (RemoteException re) {
1084 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1085 }
1086 break;
1087 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001088 request = (MainThreadRequest) msg.obj;
1089 WorkSource ws = (WorkSource) request.argument;
1090 Phone phone = getPhoneFromRequest(request);
1091 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1092 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001094 ar = (AsyncResult) msg.obj;
1095 request = (MainThreadRequest) ar.userObj;
1096 if (ar.exception == null) {
1097 request.result = ar.result;
1098 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001099 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001100 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1101 ? new CdmaCellLocation() : new GsmCellLocation();
1102 }
1103
1104 synchronized (request) {
1105 request.notifyAll();
1106 }
1107 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001108 case CMD_MODEM_REBOOT:
1109 request = (MainThreadRequest) msg.obj;
1110 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001111 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001112 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001113 case EVENT_CMD_MODEM_REBOOT_DONE:
1114 handleNullReturnEvent(msg, "rebootModem");
1115 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001116 case CMD_REQUEST_ENABLE_MODEM:
1117 request = (MainThreadRequest) msg.obj;
1118 boolean enable = (boolean) request.argument;
1119 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001120 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001121 PhoneConfigurationManager.getInstance()
1122 .enablePhone(request.phone, enable, onCompleted);
1123 break;
1124 case EVENT_ENABLE_MODEM_DONE:
1125 ar = (AsyncResult) msg.obj;
1126 request = (MainThreadRequest) ar.userObj;
1127 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001128 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001129 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001130 if ((boolean) request.result) {
1131 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1132 updateModemStateMetrics();
1133 } else {
1134 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1135 + ar.exception);
1136 }
1137 notifyRequester(request);
1138 break;
1139 case CMD_GET_MODEM_STATUS:
1140 request = (MainThreadRequest) msg.obj;
1141 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1142 PhoneConfigurationManager.getInstance()
1143 .getPhoneStatusFromModem(request.phone, onCompleted);
1144 break;
1145 case EVENT_GET_MODEM_STATUS_DONE:
1146 ar = (AsyncResult) msg.obj;
1147 request = (MainThreadRequest) ar.userObj;
1148 int id = request.phone.getPhoneId();
1149 if (ar.exception == null && ar.result != null) {
1150 request.result = ar.result;
1151 //update the cache as modem status has changed
1152 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1153 (boolean) request.result);
1154 } else {
1155 // Return true if modem status cannot be retrieved. For most cases,
1156 // modem status is on. And for older version modems, GET_MODEM_STATUS
1157 // and disable modem are not supported. Modem is always on.
1158 // TODO: this should be fixed in R to support a third
1159 // status UNKNOWN b/131631629
1160 request.result = true;
1161 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1162 + ar.exception);
1163 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001164 notifyRequester(request);
1165 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001166 default:
1167 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1168 break;
1169 }
1170 }
Jake Hambye994d462014-02-03 13:10:13 -08001171
Pengquan Menga1bb6272018-09-06 09:59:22 -07001172 private void notifyRequester(MainThreadRequest request) {
1173 synchronized (request) {
1174 request.notifyAll();
1175 }
1176 }
1177
Jake Hambye994d462014-02-03 13:10:13 -08001178 private void handleNullReturnEvent(Message msg, String command) {
1179 AsyncResult ar = (AsyncResult) msg.obj;
1180 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1181 if (ar.exception == null) {
1182 request.result = true;
1183 } else {
1184 request.result = false;
1185 if (ar.exception instanceof CommandException) {
1186 loge(command + ": CommandException: " + ar.exception);
1187 } else {
1188 loge(command + ": Unknown exception");
1189 }
1190 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001191 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001193 }
1194
1195 /**
1196 * Posts the specified command to be executed on the main thread,
1197 * waits for the request to complete, and returns the result.
1198 * @see #sendRequestAsync
1199 */
1200 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001201 return sendRequest(
1202 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001203 }
1204
1205 /**
1206 * Posts the specified command to be executed on the main thread,
1207 * waits for the request to complete, and returns the result.
1208 * @see #sendRequestAsync
1209 */
1210 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1211 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001212 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001213 }
1214
1215 /**
1216 * Posts the specified command to be executed on the main thread,
1217 * waits for the request to complete, and returns the result.
1218 * @see #sendRequestAsync
1219 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001220 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001221 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001222 }
1223
1224 /**
1225 * Posts the specified command to be executed on the main thread,
1226 * waits for the request to complete, and returns the result.
1227 * @see #sendRequestAsync
1228 */
Nathan Harold92bed182018-10-12 18:16:49 -07001229 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1230 return sendRequest(command, argument, subId, null, workSource);
1231 }
1232
1233 /**
1234 * Posts the specified command to be executed on the main thread,
1235 * waits for the request to complete, and returns the result.
1236 * @see #sendRequestAsync
1237 */
1238 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1239 return sendRequest(
1240 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1241 }
1242
1243 /**
1244 * Posts the specified command to be executed on the main thread,
1245 * waits for the request to complete, and returns the result.
1246 * @see #sendRequestAsync
1247 */
1248 private Object sendRequest(
1249 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1251 throw new RuntimeException("This method will deadlock if called from the main thread.");
1252 }
1253
Nathan Harold92bed182018-10-12 18:16:49 -07001254 MainThreadRequest request = null;
1255 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1256 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1257 } else if (phone != null) {
1258 request = new MainThreadRequest(argument, phone, workSource);
1259 } else {
1260 request = new MainThreadRequest(argument, subId, workSource);
1261 }
1262
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 Message msg = mMainThreadHandler.obtainMessage(command, request);
1264 msg.sendToTarget();
1265
1266 // Wait for the request to complete
1267 synchronized (request) {
1268 while (request.result == null) {
1269 try {
1270 request.wait();
1271 } catch (InterruptedException e) {
1272 // Do nothing, go back and wait until the request is complete
1273 }
1274 }
1275 }
1276 return request.result;
1277 }
1278
1279 /**
1280 * Asynchronous ("fire and forget") version of sendRequest():
1281 * Posts the specified command to be executed on the main thread, and
1282 * returns immediately.
1283 * @see #sendRequest
1284 */
1285 private void sendRequestAsync(int command) {
1286 mMainThreadHandler.sendEmptyMessage(command);
1287 }
1288
1289 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001290 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001291 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001292 */
1293 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001294 sendRequestAsync(command, argument, null, null);
1295 }
1296
1297 /**
1298 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1299 * @see {@link #sendRequest(int,Object)}
1300 */
1301 private void sendRequestAsync(
1302 int command, Object argument, Phone phone, WorkSource workSource) {
1303 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001304 Message msg = mMainThreadHandler.obtainMessage(command, request);
1305 msg.sendToTarget();
1306 }
1307
1308 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 * Initialize the singleton PhoneInterfaceManager instance.
1310 * This is only done once, at startup, from PhoneApp.onCreate().
1311 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001312 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 synchronized (PhoneInterfaceManager.class) {
1314 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001315 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 } else {
1317 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1318 }
1319 return sInstance;
1320 }
1321 }
1322
1323 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001324 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001327 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1329 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001330 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001331 mTelephonySharedPreferences =
1332 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001333 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001334 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001335
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 publish();
1337 }
1338
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001339 private Phone getDefaultPhone() {
1340 Phone thePhone = getPhone(getDefaultSubscription());
1341 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1342 }
1343
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 private void publish() {
1345 if (DBG) log("publish: " + this);
1346
1347 ServiceManager.addService("phone", this);
1348 }
1349
Stuart Scott584921c2015-01-15 17:10:34 -08001350 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001351 if (request.phone != null) {
1352 return request.phone;
1353 } else {
1354 return getPhoneFromSubId(request.subId);
1355 }
1356 }
1357
1358 private Phone getPhoneFromSubId(int subId) {
1359 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1360 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001361 }
1362
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001363 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1364 Phone phone = getPhoneFromRequest(request);
1365 return phone == null ? null :
1366 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1367 }
1368
Wink Saville36469e72014-06-11 15:17:00 -07001369 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001370 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001371 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373
1374 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 if (DBG) log("dial: " + number);
1380 // No permission check needed here: This is just a wrapper around the
1381 // ACTION_DIAL intent, which is available to any app since it puts up
1382 // the UI before it does anything.
1383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001384 final long identity = Binder.clearCallingIdentity();
1385 try {
1386 String url = createTelUrl(number);
1387 if (url == null) {
1388 return;
1389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001391 // PENDING: should we just silently fail if phone is offhook or ringing?
1392 PhoneConstants.State state = mCM.getState(subId);
1393 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1394 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1395 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1396 mApp.startActivity(intent);
1397 }
1398 } finally {
1399 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 }
1401 }
1402
1403 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001404 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001405 }
1406
Wink Savilleb564aae2014-10-23 10:18:09 -07001407 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 if (DBG) log("call: " + number);
1409
1410 // This is just a wrapper around the ACTION_CALL intent, but we still
1411 // need to do a permission check since we're calling startActivity()
1412 // from the context of the phone app.
1413 enforceCallPermission();
1414
Jordan Liu1617b712019-07-10 15:06:26 -07001415 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 != AppOpsManager.MODE_ALLOWED) {
1417 return;
1418 }
1419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001420 final long identity = Binder.clearCallingIdentity();
1421 try {
1422 String url = createTelUrl(number);
1423 if (url == null) {
1424 return;
1425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001427 boolean isValid = false;
1428 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1429 if (slist != null) {
1430 for (SubscriptionInfo subInfoRecord : slist) {
1431 if (subInfoRecord.getSubscriptionId() == subId) {
1432 isValid = true;
1433 break;
1434 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001435 }
Wink Saville08874612014-08-31 19:19:58 -07001436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001437 if (!isValid) {
1438 return;
1439 }
Wink Saville08874612014-08-31 19:19:58 -07001440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001441 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1442 intent.putExtra(SUBSCRIPTION_KEY, subId);
1443 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1444 mApp.startActivity(intent);
1445 } finally {
1446 Binder.restoreCallingIdentity(identity);
1447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 }
1449
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001451 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001452 }
1453
Wink Savilleb564aae2014-10-23 10:18:09 -07001454 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001456 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1457 }
1458
1459 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001460 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001461 }
1462
Wink Savilleb564aae2014-10-23 10:18:09 -07001463 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001464 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001465 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1466 }
1467
1468 /** {@hide} */
1469 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001470 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001471 }
1472
Wink Savilleb564aae2014-10-23 10:18:09 -07001473 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001475
1476 final long identity = Binder.clearCallingIdentity();
1477 try {
1478 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1479 checkSimPin.start();
1480 return checkSimPin.unlockSim(null, pin);
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
1483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 }
1485
Wink Saville9de0f752013-10-22 19:04:03 -07001486 /** {@hide} */
1487 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001488 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001489 }
1490
Wink Savilleb564aae2014-10-23 10:18:09 -07001491 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001493
1494 final long identity = Binder.clearCallingIdentity();
1495 try {
1496 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1497 checkSimPuk.start();
1498 return checkSimPuk.unlockSim(puk, pin);
1499 } finally {
1500 Binder.restoreCallingIdentity(identity);
1501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 }
1503
1504 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001505 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 * a synchronous one.
1507 */
1508 private static class UnlockSim extends Thread {
1509
1510 private final IccCard mSimCard;
1511
1512 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001513 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1514 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515
1516 // For replies from SimCard interface
1517 private Handler mHandler;
1518
1519 // For async handler to identify request type
1520 private static final int SUPPLY_PIN_COMPLETE = 100;
1521
1522 public UnlockSim(IccCard simCard) {
1523 mSimCard = simCard;
1524 }
1525
1526 @Override
1527 public void run() {
1528 Looper.prepare();
1529 synchronized (UnlockSim.this) {
1530 mHandler = new Handler() {
1531 @Override
1532 public void handleMessage(Message msg) {
1533 AsyncResult ar = (AsyncResult) msg.obj;
1534 switch (msg.what) {
1535 case SUPPLY_PIN_COMPLETE:
1536 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1537 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001538 mRetryCount = msg.arg1;
1539 if (ar.exception != null) {
1540 if (ar.exception instanceof CommandException &&
1541 ((CommandException)(ar.exception)).getCommandError()
1542 == CommandException.Error.PASSWORD_INCORRECT) {
1543 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1544 } else {
1545 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1546 }
1547 } else {
1548 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 mDone = true;
1551 UnlockSim.this.notifyAll();
1552 }
1553 break;
1554 }
1555 }
1556 };
1557 UnlockSim.this.notifyAll();
1558 }
1559 Looper.loop();
1560 }
1561
1562 /*
1563 * Use PIN or PUK to unlock SIM card
1564 *
1565 * If PUK is null, unlock SIM card with PIN
1566 *
1567 * If PUK is not null, unlock SIM card with PUK and set PIN code
1568 */
Wink Saville9de0f752013-10-22 19:04:03 -07001569 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570
1571 while (mHandler == null) {
1572 try {
1573 wait();
1574 } catch (InterruptedException e) {
1575 Thread.currentThread().interrupt();
1576 }
1577 }
1578 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1579
1580 if (puk == null) {
1581 mSimCard.supplyPin(pin, callback);
1582 } else {
1583 mSimCard.supplyPuk(puk, pin, callback);
1584 }
1585
1586 while (!mDone) {
1587 try {
1588 Log.d(LOG_TAG, "wait for done");
1589 wait();
1590 } catch (InterruptedException e) {
1591 // Restore the interrupted status
1592 Thread.currentThread().interrupt();
1593 }
1594 }
1595 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001596 int[] resultArray = new int[2];
1597 resultArray[0] = mResult;
1598 resultArray[1] = mRetryCount;
1599 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
1601 }
1602
1603 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001604 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001605
1606 }
1607
Wink Savilleb564aae2014-10-23 10:18:09 -07001608 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 // No permission check needed here: this call is harmless, and it's
1610 // needed for the ServiceState.requestStateUpdate() call (which is
1611 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001612 final long identity = Binder.clearCallingIdentity();
1613 try {
1614 final Phone phone = getPhone(subId);
1615 if (phone != null) {
1616 phone.updateServiceLocation();
1617 }
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001623 @Override
1624 public boolean isRadioOn(String callingPackage) {
1625 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001626 }
1627
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001628 @Override
1629 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001631 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001632 return false;
1633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001634
1635 final long identity = Binder.clearCallingIdentity();
1636 try {
1637 return isRadioOnForSubscriber(subId);
1638 } finally {
1639 Binder.restoreCallingIdentity(identity);
1640 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001641 }
1642
1643 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001644 final long identity = Binder.clearCallingIdentity();
1645 try {
1646 final Phone phone = getPhone(subId);
1647 if (phone != null) {
1648 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1649 } else {
1650 return false;
1651 }
1652 } finally {
1653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 }
1656
1657 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001658 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
Wink Saville36469e72014-06-11 15:17:00 -07001660
Wink Savilleb564aae2014-10-23 10:18:09 -07001661 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001663
1664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 final Phone phone = getPhone(subId);
1667 if (phone != null) {
1668 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1669 }
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 }
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
1674
1675 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001676 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001677 }
1678
Wink Savilleb564aae2014-10-23 10:18:09 -07001679 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001681
1682 final long identity = Binder.clearCallingIdentity();
1683 try {
1684 final Phone phone = getPhone(subId);
1685 if (phone == null) {
1686 return false;
1687 }
1688 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1689 toggleRadioOnOffForSubscriber(subId);
1690 }
1691 return true;
1692 } finally {
1693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 }
Wink Saville36469e72014-06-11 15:17:00 -07001696
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001697 public boolean needMobileRadioShutdown() {
1698 /*
1699 * If any of the Radios are available, it will need to be
1700 * shutdown. So return true if any Radio is available.
1701 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001702 final long identity = Binder.clearCallingIdentity();
1703 try {
1704 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1705 Phone phone = PhoneFactory.getPhone(i);
1706 if (phone != null && phone.isRadioAvailable()) return true;
1707 }
1708 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1709 return false;
1710 } finally {
1711 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001712 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001713 }
1714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001716 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717 enforceModifyPermission();
1718
1719 final long identity = Binder.clearCallingIdentity();
1720 try {
1721 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1722 logv("Shutting down Phone " + i);
1723 shutdownRadioUsingPhoneId(i);
1724 }
1725 } finally {
1726 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001727 }
1728 }
1729
1730 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001731 Phone phone = PhoneFactory.getPhone(phoneId);
1732 if (phone != null && phone.isRadioAvailable()) {
1733 phone.shutdownRadio();
1734 }
1735 }
1736
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001738 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001739
1740 final long identity = Binder.clearCallingIdentity();
1741 try {
1742 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1743 if (defaultPhone != null) {
1744 defaultPhone.setRadioPower(turnOn);
1745 return true;
1746 } else {
1747 loge("There's no default phone.");
1748 return false;
1749 }
1750 } finally {
1751 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001752 }
Wink Saville36469e72014-06-11 15:17:00 -07001753 }
1754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
1762 phone.setRadioPower(turnOn);
1763 return true;
1764 } else {
1765 return false;
1766 }
1767 } finally {
1768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
Wink Saville36469e72014-06-11 15:17:00 -07001772 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public boolean enableDataConnectivity() {
1775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776
1777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 int subId = mSubscriptionController.getDefaultDataSubId();
1780 final Phone phone = getPhone(subId);
1781 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001782 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001783 return true;
1784 } else {
1785 return false;
1786 }
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Wink Saville36469e72014-06-11 15:17:00 -07001792 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 public boolean disableDataConnectivity() {
1795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796
1797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 int subId = mSubscriptionController.getDefaultDataSubId();
1800 final Phone phone = getPhone(subId);
1801 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001802 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001803 return true;
1804 } else {
1805 return false;
1806 }
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 }
1811
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001813 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 final Phone phone = getPhone(subId);
1817 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001818 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819 } else {
1820 return false;
1821 }
1822 } finally {
1823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 }
1826
1827 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001828 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001829 }
1830
pkanwarae03a6b2016-11-06 20:37:09 -08001831 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001832 enforceCallPermission();
1833
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1837 return;
1838 }
1839 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1840 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
1843 }
pkanwar32d516d2016-10-14 19:37:38 -07001844 };
1845
Wink Savilleb564aae2014-10-23 10:18:09 -07001846 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001848
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1852 return false;
1853 }
1854 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001861 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001862 }
1863
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001864 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001865 final long identity = Binder.clearCallingIdentity();
1866 try {
1867 Phone phone = PhoneFactory.getPhone(slotIndex);
1868 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1869 PhoneConstantConversions.convertCallState(phone.getState());
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
1872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001876 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001877 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1878 }
1879
1880 @Override
1881 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882 final long identity = Binder.clearCallingIdentity();
1883 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001884 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 if (phone != null) {
1886 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1887 } else {
1888 return PhoneConstantConversions.convertDataState(
1889 PhoneConstants.DataState.DISCONNECTED);
1890 }
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 }
1895
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001897 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001898 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1899 }
1900
1901 @Override
1902 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001903 final long identity = Binder.clearCallingIdentity();
1904 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001905 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001906 if (phone != null) {
1907 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1908 } else {
1909 return TelephonyManager.DATA_ACTIVITY_NONE;
1910 }
1911 } finally {
1912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 }
1915
1916 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001917 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001918 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001919 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001920
1921 LocationAccessPolicy.LocationPermissionResult locationResult =
1922 LocationAccessPolicy.checkLocationPermission(mApp,
1923 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1924 .setCallingPackage(callingPackage)
1925 .setCallingPid(Binder.getCallingPid())
1926 .setCallingUid(Binder.getCallingUid())
1927 .setMethod("getCellLocation")
1928 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1929 .build());
1930 switch (locationResult) {
1931 case DENIED_HARD:
1932 throw new SecurityException("Not allowed to access cell location");
1933 case DENIED_SOFT:
1934 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 }
1936
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001937 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001938 final long identity = Binder.clearCallingIdentity();
1939 try {
1940 if (DBG_LOC) log("getCellLocation: is active user");
1941 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001942 int subId = mSubscriptionController.getDefaultDataSubId();
1943 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1944 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 return data;
1946 } finally {
1947 Binder.restoreCallingIdentity(identity);
1948 }
Svetoslav64fad262015-04-14 14:35:21 -07001949 }
1950
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001952 public String getNetworkCountryIsoForPhone(int phoneId) {
1953 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1954 // registered cell info, so return a NULL country instead.
1955 final long identity = Binder.clearCallingIdentity();
1956 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001957 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1958 // Get default phone in this case.
1959 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1960 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001961 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001962 // Todo: fix this when we can get the actual cellular network info when the device
1963 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001964 if (TelephonyManager.NETWORK_TYPE_IWLAN
1965 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1966 return "";
1967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968 Phone phone = PhoneFactory.getPhone(phoneId);
1969 if (phone != null) {
1970 ServiceStateTracker sst = phone.getServiceStateTracker();
sqian1c069d02019-07-31 20:23:45 -07001971 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001972 if (sst != null) {
1973 LocaleTracker lt = sst.getLocaleTracker();
1974 if (lt != null) {
sqian1c069d02019-07-31 20:23:45 -07001975 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
1976 return lt.getCurrentCountry();
1977 } else if (emergencyNumberTracker != null) {
1978 return emergencyNumberTracker.getEmergencyCountryIso();
1979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 }
1981 }
1982 }
1983 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001984 } finally {
1985 Binder.restoreCallingIdentity(identity);
1986 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001987 }
1988
1989 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001991 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001992 }
1993
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001995 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 mApp.enforceCallingOrSelfPermission(
1997 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998
1999 final long identity = Binder.clearCallingIdentity();
2000 try {
2001 final Phone phone = getPhone(subId);
2002 if (phone != null) {
2003 phone.enableLocationUpdates();
2004 }
2005 } finally {
2006 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 }
2009
2010 @Override
2011 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002012 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002013 }
2014
Sanket Padawe356d7632015-06-22 14:03:32 -07002015 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002016 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 mApp.enforceCallingOrSelfPermission(
2018 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002019
2020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 final Phone phone = getPhone(subId);
2023 if (phone != null) {
2024 phone.disableLocationUpdates();
2025 }
2026 } finally {
2027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 }
2030
Nathan Harold31d7ff32018-10-15 20:20:30 -07002031 /**
2032 * Returns the target SDK version number for a given package name.
2033 *
Nathan Haroldec184742019-07-10 17:04:16 -07002034 * This call MUST be invoked before clearing the calling UID.
2035 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002036 * @return target SDK if the package is found or INT_MAX.
2037 */
2038 private int getTargetSdk(String packageName) {
2039 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002040 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002041 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002042 if (ai != null) return ai.targetSdkVersion;
2043 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002044 loge("Failed to get package info for pkg="
2045 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002046 }
2047 return Integer.MAX_VALUE;
2048 }
2049
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050 @Override
2051 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002052 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2053 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002054 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2055 throw new SecurityException(
2056 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2057 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002058
Jordan Liu1617b712019-07-10 15:06:26 -07002059 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2061 return null;
2062 }
Svetoslav64fad262015-04-14 14:35:21 -07002063
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002064 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065
Nathan Haroldf180aac2018-06-01 18:43:55 -07002066 List<CellInfo> info = getAllCellInfo(callingPackage);
2067 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068
Nathan Haroldf180aac2018-06-01 18:43:55 -07002069 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2070 for (CellInfo ci : info) {
2071 if (ci instanceof CellInfoGsm) {
2072 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2073 } else if (ci instanceof CellInfoWcdma) {
2074 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2075 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002076 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002077 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 }
2079
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002080 private List<CellInfo> getCachedCellInfo() {
2081 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2082 for (Phone phone : PhoneFactory.getPhones()) {
2083 List<CellInfo> info = phone.getAllCellInfo();
2084 if (info != null) cellInfos.addAll(info);
2085 }
2086 return cellInfos;
2087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088
2089 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002090 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002091 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002092 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002093
2094 LocationAccessPolicy.LocationPermissionResult locationResult =
2095 LocationAccessPolicy.checkLocationPermission(mApp,
2096 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2097 .setCallingPackage(callingPackage)
2098 .setCallingPid(Binder.getCallingPid())
2099 .setCallingUid(Binder.getCallingUid())
2100 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002101 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002102 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2103 .build());
2104 switch (locationResult) {
2105 case DENIED_HARD:
2106 throw new SecurityException("Not allowed to access cell info");
2107 case DENIED_SOFT:
2108 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002111 final int targetSdk = getTargetSdk(callingPackage);
2112 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2113 return getCachedCellInfo();
2114 }
2115
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002116 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002117 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002118 final long identity = Binder.clearCallingIdentity();
2119 try {
2120 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2121 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002122 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002123 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002124 if (info != null) cellInfos.addAll(info);
2125 }
2126 return cellInfos;
2127 } finally {
2128 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
2130 }
2131
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002132 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002133 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2134 requestCellInfoUpdateInternal(
2135 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2136 }
2137
2138 @Override
2139 public void requestCellInfoUpdateWithWorkSource(
2140 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2141 enforceModifyPermission();
2142 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2143 }
2144
2145 private void requestCellInfoUpdateInternal(
2146 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002147 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002148 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002149
2150 LocationAccessPolicy.LocationPermissionResult locationResult =
2151 LocationAccessPolicy.checkLocationPermission(mApp,
2152 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2153 .setCallingPackage(callingPackage)
2154 .setCallingPid(Binder.getCallingPid())
2155 .setCallingUid(Binder.getCallingUid())
2156 .setMethod("requestCellInfoUpdate")
2157 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2158 .build());
2159 switch (locationResult) {
2160 case DENIED_HARD:
2161 throw new SecurityException("Not allowed to access cell info");
2162 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002163 try {
2164 cb.onCellInfo(new ArrayList<CellInfo>());
2165 } catch (RemoteException re) {
2166 // Drop without consequences
2167 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002168 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002169 }
2170
Nathan Harolda939a962019-05-09 10:13:47 -07002171
2172 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002173 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2174
2175 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2176 }
2177
2178 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002180 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002181 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002182
2183 final long identity = Binder.clearCallingIdentity();
2184 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002185 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002186 } finally {
2187 Binder.restoreCallingIdentity(identity);
2188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 }
2190
Shishir Agrawala9f32182016-04-12 12:00:16 -07002191 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002192 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002193 Phone phone = PhoneFactory.getPhone(slotIndex);
2194 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002195 return null;
2196 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002197 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002198 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2199 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002200 return null;
2201 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002202
2203 final long identity = Binder.clearCallingIdentity();
2204 try {
2205 return phone.getImei();
2206 } finally {
2207 Binder.restoreCallingIdentity(identity);
2208 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002209 }
2210
2211 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002212 public String getTypeAllocationCodeForSlot(int slotIndex) {
2213 Phone phone = PhoneFactory.getPhone(slotIndex);
2214 String tac = null;
2215 if (phone != null) {
2216 String imei = phone.getImei();
2217 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2218 }
2219 return tac;
2220 }
2221
2222 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002223 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002224 Phone phone = PhoneFactory.getPhone(slotIndex);
2225 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002226 return null;
2227 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002228
Jeff Davidson913390f2018-02-23 17:11:49 -08002229 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002230 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2231 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002232 return null;
2233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002234
2235 final long identity = Binder.clearCallingIdentity();
2236 try {
2237 return phone.getMeid();
2238 } finally {
2239 Binder.restoreCallingIdentity(identity);
2240 }
Jack Yu2af8d712017-03-15 17:14:14 -07002241 }
2242
2243 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002244 public String getManufacturerCodeForSlot(int slotIndex) {
2245 Phone phone = PhoneFactory.getPhone(slotIndex);
2246 String manufacturerCode = null;
2247 if (phone != null) {
2248 String meid = phone.getMeid();
2249 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2250 }
2251 return manufacturerCode;
2252 }
2253
2254 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002255 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002256 Phone phone = PhoneFactory.getPhone(slotIndex);
2257 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002258 return null;
2259 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002260 int subId = phone.getSubId();
2261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2262 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2263 return null;
2264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002265
2266 final long identity = Binder.clearCallingIdentity();
2267 try {
2268 return phone.getDeviceSvn();
2269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002272 }
2273
fionaxu43304da2017-11-27 22:51:16 -08002274 @Override
2275 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276 final long identity = Binder.clearCallingIdentity();
2277 try {
2278 final Phone phone = getPhone(subId);
2279 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2280 } finally {
2281 Binder.restoreCallingIdentity(identity);
2282 }
fionaxu43304da2017-11-27 22:51:16 -08002283 }
2284
2285 @Override
2286 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 final Phone phone = getPhone(subId);
2290 return phone == null ? null : phone.getCarrierName();
2291 } finally {
2292 Binder.restoreCallingIdentity(identity);
2293 }
fionaxu43304da2017-11-27 22:51:16 -08002294 }
2295
calvinpanffe225e2018-11-01 19:43:06 +08002296 @Override
chen xu0026ca62019-03-06 15:28:50 -08002297 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 final Phone phone = getPhone(subId);
2301 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002302 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002303 } finally {
2304 Binder.restoreCallingIdentity(identity);
2305 }
2306 }
2307
2308 @Override
chen xu0026ca62019-03-06 15:28:50 -08002309 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002313 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002314 } finally {
2315 Binder.restoreCallingIdentity(identity);
2316 }
2317 }
2318
chen xu651eec72018-11-11 19:03:44 -08002319 @Override
chen xu864e11c2018-12-06 22:10:03 -08002320 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2321 if (!isSubscriptionMccMnc) {
2322 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2323 }
chen xu651eec72018-11-11 19:03:44 -08002324 final Phone phone = PhoneFactory.getPhone(slotIndex);
2325 if (phone == null) {
2326 return TelephonyManager.UNKNOWN_CARRIER_ID;
2327 }
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
2333 }
2334 }
2335
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 //
2337 // Internal helper methods.
2338 //
2339
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002340 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2342 *
2343 * @throws SecurityException if the caller does not have the required permission
2344 */
2345 private void enforceModifyPermission() {
2346 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2347 }
2348
2349 /**
2350 * Make sure the caller has the CALL_PHONE permission.
2351 *
2352 * @throws SecurityException if the caller does not have the required permission
2353 */
2354 private void enforceCallPermission() {
2355 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2356 }
2357
Stuart Scott8eef64f2015-04-08 15:13:54 -07002358 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002359 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002360 "ConnectivityService");
2361 }
2362
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 private String createTelUrl(String number) {
2364 if (TextUtils.isEmpty(number)) {
2365 return null;
2366 }
2367
Jake Hambye994d462014-02-03 13:10:13 -08002368 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 }
2370
Ihab Awadf9e92732013-12-05 18:02:52 -08002371 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2373 }
2374
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002375 private static void logv(String msg) {
2376 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2377 }
2378
Ihab Awadf9e92732013-12-05 18:02:52 -08002379 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2381 }
2382
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002383 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002385 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002386 }
2387
Sanket Padawe356d7632015-06-22 14:03:32 -07002388 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002389 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002390 final long identity = Binder.clearCallingIdentity();
2391 try {
2392 final Phone phone = PhoneFactory.getPhone(slotIndex);
2393 if (phone == null) {
2394 return PhoneConstants.PHONE_TYPE_NONE;
2395 } else {
2396 return phone.getPhoneType();
2397 }
2398 } finally {
2399 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
2402
2403 /**
2404 * Returns the CDMA ERI icon index to display
2405 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002406 @Override
2407 public int getCdmaEriIconIndex(String callingPackage) {
2408 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002409 }
2410
Sanket Padawe356d7632015-06-22 14:03:32 -07002411 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002412 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002414 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002415 return -1;
2416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 final Phone phone = getPhone(subId);
2421 if (phone != null) {
2422 return phone.getCdmaEriIconIndex();
2423 } else {
2424 return -1;
2425 }
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
2431 /**
2432 * Returns the CDMA ERI icon mode,
2433 * 0 - ON
2434 * 1 - FLASHING
2435 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002436 @Override
2437 public int getCdmaEriIconMode(String callingPackage) {
2438 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002439 }
2440
Sanket Padawe356d7632015-06-22 14:03:32 -07002441 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002442 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002444 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002445 return -1;
2446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447
2448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 final Phone phone = getPhone(subId);
2451 if (phone != null) {
2452 return phone.getCdmaEriIconMode();
2453 } else {
2454 return -1;
2455 }
2456 } finally {
2457 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 }
2460
2461 /**
2462 * Returns the CDMA ERI text,
2463 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002464 @Override
2465 public String getCdmaEriText(String callingPackage) {
2466 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
Sanket Padawe356d7632015-06-22 14:03:32 -07002469 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002470 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002472 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002473 return null;
2474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475
2476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 final Phone phone = getPhone(subId);
2479 if (phone != null) {
2480 return phone.getCdmaEriText();
2481 } else {
2482 return null;
2483 }
2484 } finally {
2485 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
2488
2489 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002490 * Returns the CDMA MDN.
2491 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002492 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002493 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2495 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496
2497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002500 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501 return phone.getLine1Number();
2502 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002503 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 return null;
2505 }
2506 } finally {
2507 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002508 }
2509 }
2510
2511 /**
2512 * Returns the CDMA MIN.
2513 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002514 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002515 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2517 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518
2519 final long identity = Binder.clearCallingIdentity();
2520 try {
2521 final Phone phone = getPhone(subId);
2522 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2523 return phone.getCdmaMin();
2524 } else {
2525 return null;
2526 }
2527 } finally {
2528 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002529 }
2530 }
2531
Hall Liud892bec2018-11-30 14:51:45 -08002532 @Override
2533 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2534 INumberVerificationCallback callback, String callingPackage) {
2535 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2536 != PERMISSION_GRANTED) {
2537 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2538 }
2539 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2540
2541 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2542 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2543 throw new SecurityException("Calling package must be configured in the device config");
2544 }
2545
2546 if (range == null) {
2547 throw new NullPointerException("Range must be non-null");
2548 }
2549
2550 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002551 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002552
2553 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2554 }
2555
Junda Liuca05d5d2014-08-14 22:36:34 -07002556 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 * Returns true if CDMA provisioning needs to run.
2558 */
2559 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560 final long identity = Binder.clearCallingIdentity();
2561 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002562 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 } finally {
2564 Binder.restoreCallingIdentity(identity);
2565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 }
2567
2568 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002569 * Sets the voice mail number of a given subId.
2570 */
2571 @Override
2572 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002573 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2578 new Pair<String, String>(alphaTag, number), new Integer(subId));
2579 return success;
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
2582 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002583 }
2584
Ta-wei Yen87c49842016-05-13 21:19:52 -07002585 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002586 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002588 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002589 if (!TextUtils.equals(callingPackage, systemDialer)) {
2590 throw new SecurityException("caller must be system dialer");
2591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592
2593 final long identity = Binder.clearCallingIdentity();
2594 try {
2595 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2596 if (phoneAccountHandle == null) {
2597 return null;
2598 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002599 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002602 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002603 }
2604
2605 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002606 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002608 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002609 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002610 return null;
2611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002613 final long identity = Binder.clearCallingIdentity();
2614 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002615 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002616 } finally {
2617 Binder.restoreCallingIdentity(identity);
2618 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002619 }
2620
2621 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002622 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2623 VisualVoicemailSmsFilterSettings settings) {
2624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625
2626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002629 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002633 }
2634
2635 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002636 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2637 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002642 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 } finally {
2644 Binder.restoreCallingIdentity(identity);
2645 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002646 }
2647
2648 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002649 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2650 String callingPackage, int subId) {
2651 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652
2653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002656 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 } finally {
2658 Binder.restoreCallingIdentity(identity);
2659 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002660 }
2661
2662 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002663 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002664 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665
2666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002669 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002673 }
2674
2675 @Override
2676 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2677 String number, int port, String text, PendingIntent sentIntent) {
2678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002679 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002680 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002681 SmsController smsController = PhoneFactory.getSmsController();
2682 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2683 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002684 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002685
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002686 /**
fionaxu0152e512016-11-14 13:36:14 -08002687 * Sets the voice activation state of a given subId.
2688 */
2689 @Override
2690 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2692 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
2696 final Phone phone = getPhone(subId);
2697 if (phone != null) {
2698 phone.setVoiceActivationState(activationState);
2699 } else {
2700 loge("setVoiceActivationState fails with invalid subId: " + subId);
2701 }
2702 } finally {
2703 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002704 }
2705 }
2706
2707 /**
2708 * Sets the data activation state of a given subId.
2709 */
2710 @Override
2711 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2713 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714
2715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 final Phone phone = getPhone(subId);
2718 if (phone != null) {
2719 phone.setDataActivationState(activationState);
2720 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002721 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 }
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002725 }
2726 }
2727
2728 /**
2729 * Returns the voice activation state of a given subId.
2730 */
2731 @Override
2732 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002733 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734
fionaxu0152e512016-11-14 13:36:14 -08002735 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 final long identity = Binder.clearCallingIdentity();
2737 try {
2738 if (phone != null) {
2739 return phone.getVoiceActivationState();
2740 } else {
2741 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2742 }
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002745 }
2746 }
2747
2748 /**
2749 * Returns the data activation state of a given subId.
2750 */
2751 @Override
2752 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002753 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754
fionaxu0152e512016-11-14 13:36:14 -08002755 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 if (phone != null) {
2759 return phone.getDataActivationState();
2760 } else {
2761 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2762 }
2763 } finally {
2764 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002765 }
2766 }
2767
2768 /**
Wink Saville36469e72014-06-11 15:17:00 -07002769 * Returns the unread count of voicemails for a subId
2770 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002771 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002772 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2774 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2775 return 0;
2776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 final Phone phone = getPhone(subId);
2780 if (phone != null) {
2781 return phone.getVoiceMessageCount();
2782 } else {
2783 return 0;
2784 }
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002788 }
2789
2790 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002791 * returns true, if the device is in a state where both voice and data
2792 * are supported simultaneously. This can change based on location or network condition.
2793 */
2794 @Override
2795 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796 final long identity = Binder.clearCallingIdentity();
2797 try {
2798 final Phone phone = getPhone(subId);
2799 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2800 } finally {
2801 Binder.restoreCallingIdentity(identity);
2802 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002803 }
2804
2805 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002806 * Send the dialer code if called from the current default dialer or the caller has
2807 * carrier privilege.
2808 * @param inputCode The dialer code to send
2809 */
2810 @Override
2811 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002812 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002813 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002814 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2815 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002816 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002817 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2818 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002819 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002823 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 } finally {
2825 Binder.restoreCallingIdentity(identity);
2826 }
fionaxu235cc5e2017-03-06 22:25:57 -08002827 }
2828
Pengquan Menga1bb6272018-09-06 09:59:22 -07002829 @Override
2830 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002831 if (!isActiveSubscription(subId)) {
2832 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2833 }
2834
Pengquan Menga1bb6272018-09-06 09:59:22 -07002835 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2836 }
2837
Brad Ebinger35c841c2018-10-01 10:40:55 -07002838 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002839 public boolean isInEmergencySmsMode() {
2840 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 for (Phone phone : PhoneFactory.getPhones()) {
2844 if (phone.isInEmergencySmsMode()) {
2845 return true;
2846 }
2847 }
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
2850 }
2851 return false;
2852 }
2853
2854 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002855 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2856 throws RemoteException {
2857 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002858 final long token = Binder.clearCallingIdentity();
2859 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002860 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002861 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002862 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002863 } catch (ImsException e) {
2864 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002865 } finally {
2866 Binder.restoreCallingIdentity(token);
2867 }
2868 }
2869
2870 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002871 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2872 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2875 }
2876 Binder.withCleanCallingIdentity(() -> {
2877 try {
2878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002879 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002880 .removeRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002881 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002882 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2883 + "is inactive, ignoring unregister.");
2884 // If the subscription is no longer active, just return, since the callback
2885 // will already have been removed internally.
2886 }
2887 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002888 }
2889
2890 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002891 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2892 throws RemoteException {
2893 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2895 final long token = Binder.clearCallingIdentity();
2896 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002897 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002898 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002899 } catch (ImsException e) {
2900 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002901 } finally {
2902 Binder.restoreCallingIdentity(token);
2903 }
2904 }
2905
2906 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002907 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2908 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002909
2910 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2911 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2912 }
2913 Binder.withCleanCallingIdentity(() -> {
2914 try {
2915 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002916 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002917 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002918 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002919 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2920 + "is inactive, ignoring unregister.");
2921 // If the subscription is no longer active, just return, since the callback
2922 // will already have been removed internally.
2923 }
2924 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002925 }
2926
2927 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002928 public boolean isCapable(int subId, int capability, int regTech) {
2929 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002930 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2931 final long token = Binder.clearCallingIdentity();
2932 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002933 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002934 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002935 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002936 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2937 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002938 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002939 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2940 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002941 } finally {
2942 Binder.restoreCallingIdentity(token);
2943 }
2944 }
2945
2946 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002947 public boolean isAvailable(int subId, int capability, int regTech) {
2948 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002949 final long token = Binder.clearCallingIdentity();
2950 try {
2951 Phone phone = getPhone(subId);
2952 if (phone == null) return false;
2953 return phone.isImsCapabilityAvailable(capability, regTech);
2954 } finally {
2955 Binder.restoreCallingIdentity(token);
2956 }
2957 }
2958
2959 @Override
2960 public boolean isAdvancedCallingSettingEnabled(int subId) {
2961 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2963 final long token = Binder.clearCallingIdentity();
2964 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002965 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002966 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002967 } catch (ImsException e) {
2968 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 } finally {
2970 Binder.restoreCallingIdentity(token);
2971 }
2972 }
2973
2974 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002975 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002977 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002981 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002982 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002983 } catch (ImsException e) {
2984 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
2988 }
2989
2990 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002991 public boolean isVtSettingEnabled(int subId) {
2992 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002996 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
2997 } catch (ImsException e) {
2998 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
3002 }
3003
3004 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003005 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003007 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003012 } catch (ImsException e) {
3013 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003014 } finally {
3015 Binder.restoreCallingIdentity(identity);
3016 }
3017 }
3018
3019 @Override
3020 public boolean isVoWiFiSettingEnabled(int subId) {
3021 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003025 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003026 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003027 } catch (ImsException e) {
3028 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003029 } finally {
3030 Binder.restoreCallingIdentity(identity);
3031 }
3032 }
3033
3034 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003035 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003037 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003041 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003042 } catch (ImsException e) {
3043 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
3047 }
3048
3049 @Override
3050 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3051 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
3054 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003055 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003056 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003057 } catch (ImsException e) {
3058 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
3062 }
3063
3064 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003065 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003067 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003071 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003072 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003073 } catch (ImsException e) {
3074 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
3081 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3083 "setVoWiFiNonPersistent");
3084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003087 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003088 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003089 } catch (ImsException e) {
3090 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
3094 }
3095
3096 @Override
3097 public int getVoWiFiModeSetting(int subId) {
3098 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003102 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003104 } catch (ImsException e) {
3105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
3109 }
3110
3111 @Override
3112 public void setVoWiFiModeSetting(int subId, int mode) {
3113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3114 "setVoWiFiModeSetting");
3115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003118 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003119 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003120 } catch (ImsException e) {
3121 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
3125 }
3126
3127 @Override
3128 public int getVoWiFiRoamingModeSetting(int subId) {
3129 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003133 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003134 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003135 } catch (ImsException e) {
3136 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
3140 }
3141
3142 @Override
3143 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3145 "setVoWiFiRoamingModeSetting");
3146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003149 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003150 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003151 } catch (ImsException e) {
3152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
3156 }
3157
3158 @Override
3159 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3161 "setRttCapabilityEnabled");
3162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003165 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3166 } catch (ImsException e) {
3167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
3171 }
3172
3173 @Override
3174 public boolean isTtyOverVolteEnabled(int subId) {
3175 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3176 final long identity = Binder.clearCallingIdentity();
3177 try {
3178 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003179 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003180 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003181 } catch (ImsException e) {
3182 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
3186 }
3187
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003188 @Override
3189 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3190 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3191 final long identity = Binder.clearCallingIdentity();
3192 try {
3193 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003194 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003195 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003196 } catch (ImsException e) {
3197 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
3201 }
3202
3203 @Override
3204 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3205 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3206 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003207 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3208 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3209 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003210 try {
3211 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003212 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003213 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003214 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003215 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3216 + "is inactive, ignoring unregister.");
3217 // If the subscription is no longer active, just return, since the callback will already
3218 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
3222 }
3223
3224 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003225 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3226 boolean isProvisioned) {
3227 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3228 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3229 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3230 }
3231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3232 "setProvisioningStatusForCapability");
3233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3236 Phone phone = getPhone(subId);
3237 if (phone == null) {
3238 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3239 + subId);
3240 return;
3241 }
3242 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3243 return;
3244 }
3245
3246 // this capability requires provisioning, route to the correct API.
3247 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3248 switch (capability) {
3249 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3250 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3251 ims.setVolteProvisioned(isProvisioned);
3252 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3253 ims.setWfcProvisioned(isProvisioned);
3254 }
3255 break;
3256 }
3257 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3258 // There is currently no difference in VT provisioning type.
3259 ims.setVtProvisioned(isProvisioned);
3260 break;
3261 }
3262 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3263 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3264 // change the capability of the feature instead if needed.
3265 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3266 == isProvisioned) {
3267 // No change in provisioning.
3268 return;
3269 }
3270 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3271 try {
3272 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003273 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003274 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3275 + ", Exception" + e.getMessage());
3276 }
3277 break;
3278 }
3279 default: {
3280 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3281 + capability + "', which does not require provisioning.");
3282 }
3283 }
3284
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
3288 }
3289
3290 @Override
3291 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3292 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3293 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3294 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3295 }
3296 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3300 Phone phone = getPhone(subId);
3301 if (phone == null) {
3302 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3303 + subId);
3304 // We will fail with "true" as the provisioning status because this is the default
3305 // if we do not require provisioning.
3306 return true;
3307 }
3308
3309 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3310 return true;
3311 }
3312
3313 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3314 switch (capability) {
3315 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3316 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3317 return ims.isVolteProvisionedOnDevice();
3318 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3319 return ims.isWfcProvisionedOnDevice();
3320 }
3321 // This should never happen, since we are checking tech above to make sure it
3322 // is either LTE or IWLAN.
3323 throw new IllegalArgumentException("Invalid radio technology for voice "
3324 + "capability.");
3325 }
3326 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3327 // There is currently no difference in VT provisioning type.
3328 return ims.isVtProvisionedOnDevice();
3329 }
3330 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3331 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3332 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3333 }
3334 default: {
3335 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3336 + capability + "', which does not require provisioning.");
3337 }
3338 }
3339
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
3343 }
3344
3345 @Override
3346 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3347 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3348 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3349 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3350 }
3351 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3352 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3353 return (provisionedBits & capability) > 0;
3354 }
3355
3356 @Override
3357 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3358 boolean isProvisioned) {
3359 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3360 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3361 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3362 }
3363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3364 "setProvisioningStatusForCapability");
3365 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3366 // If the current provisioning status for capability already matches isProvisioned,
3367 // do nothing.
3368 if (((provisionedBits & capability) > 0) == isProvisioned) {
3369 return;
3370 }
3371 if (isProvisioned) {
3372 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3373 } else {
3374 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3375 }
3376 }
3377
3378 /**
3379 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3380 * technology. The bitfield should mirror the bitfield defined by
3381 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3382 */
3383 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3384 String key = getMmTelProvisioningKey(subId, tech);
3385 // Default is no capabilities are provisioned.
3386 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3387 }
3388
3389 /**
3390 * Sets the MmTel capability provisioning bitfield (defined by
3391 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3392 * technology specified.
3393 *
3394 * Note: This is a synchronous command and should not be called on UI thread.
3395 */
3396 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3397 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3398 String key = getMmTelProvisioningKey(subId, tech);
3399 editor.putInt(key, newField);
3400 editor.commit();
3401 }
3402
3403 private static String getMmTelProvisioningKey(int subId, int tech) {
3404 // resulting key is provision_ims_mmtel_{subId}_{tech}
3405 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3406 }
3407
3408 /**
3409 * Query CarrierConfig to see if the specified capability requires provisioning for the
3410 * carrier associated with the subscription id.
3411 */
3412 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3413 int capability) {
3414 CarrierConfigManager configManager = new CarrierConfigManager(context);
3415 PersistableBundle c = configManager.getConfigForSubId(subId);
3416 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003417 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003418 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3419 false);
3420 boolean requireVoiceVtProvisioning = c.getBoolean(
3421 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3422
3423 // First check to make sure that the capability requires provisioning.
3424 switch (capability) {
3425 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3426 // intentional fallthrough
3427 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3428 if (requireVoiceVtProvisioning) {
3429 // Voice and Video requires provisioning
3430 return true;
3431 }
3432 break;
3433 }
3434 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3435 if (requireUtProvisioning) {
3436 // UT requires provisioning
3437 return true;
3438 }
3439 break;
3440 }
3441 }
3442 return false;
3443 }
3444
3445 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003446 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003447 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3448 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3449 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003450 enforceReadPrivilegedPermission("getImsProvisioningInt");
3451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003454 int slotId = getSlotIndex(subId);
3455 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3456 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3457 + subId + "' for key:" + key);
3458 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3459 }
3460 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003461 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003462 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3463 + subId + "' for key:" + key);
3464 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
3468 }
3469
3470 @Override
3471 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003472 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3473 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3474 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003475 enforceReadPrivilegedPermission("getImsProvisioningString");
3476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003479 int slotId = getSlotIndex(subId);
3480 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3481 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3482 + subId + "' for key:" + key);
3483 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3484 }
3485 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003486 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003487 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3488 + subId + "' for key:" + key);
3489 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
3493 }
3494
3495 @Override
3496 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003497 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3498 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3499 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3501 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003505 int slotId = getSlotIndex(subId);
3506 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3507 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3508 + subId + "' for key:" + key);
3509 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3510 }
3511 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003512 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003513 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3514 + "' for key:" + key);
3515 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003516 } finally {
3517 Binder.restoreCallingIdentity(identity);
3518 }
3519 }
3520
3521 @Override
3522 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003523 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3524 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3525 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3527 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003531 int slotId = getSlotIndex(subId);
3532 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3533 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3534 + subId + "' for key:" + key);
3535 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3536 }
3537 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003538 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003539 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3540 + "' for key:" + key);
3541 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
3545 }
3546
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003547 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 int slotId = SubscriptionManager.getSlotIndex(subId);
3549 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003550 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3551 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 }
3553 return slotId;
3554 }
3555
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003556 private int getSlotIndex(int subId) {
3557 int slotId = SubscriptionManager.getSlotIndex(subId);
3558 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3559 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3560 }
3561 return slotId;
3562 }
3563
Wink Saville36469e72014-06-11 15:17:00 -07003564 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003565 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003566 */
3567 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003568 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003569 final int targetSdk = getTargetSdk(callingPackage);
3570 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3571 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3572 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003573 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3574 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003575 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3576 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 final Phone phone = getPhone(subId);
3581 if (phone != null) {
3582 return phone.getServiceState().getDataNetworkType();
3583 } else {
3584 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003589 }
3590
3591 /**
3592 * Returns the data network type
3593 */
3594 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003595 public int getDataNetworkType(String callingPackage) {
3596 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003597 }
3598
3599 /**
3600 * Returns the data network type for a subId
3601 */
3602 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003603 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003605 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003606 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3607 }
3608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 final Phone phone = getPhone(subId);
3612 if (phone != null) {
3613 return phone.getServiceState().getDataNetworkType();
3614 } else {
3615 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3616 }
3617 } finally {
3618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003620 }
3621
3622 /**
Wink Saville36469e72014-06-11 15:17:00 -07003623 * Returns the Voice network type for a subId
3624 */
3625 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003626 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003628 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003629 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3630 }
3631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632 final long identity = Binder.clearCallingIdentity();
3633 try {
3634 final Phone phone = getPhone(subId);
3635 if (phone != null) {
3636 return phone.getServiceState().getVoiceNetworkType();
3637 } else {
3638 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3639 }
3640 } finally {
3641 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003643 }
3644
3645 /**
3646 * @return true if a ICC card is present
3647 */
3648 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003649 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003650 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3651 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003652 }
3653
3654 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003655 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003656 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003657 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003658 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 final Phone phone = PhoneFactory.getPhone(slotIndex);
3662 if (phone != null) {
3663 return phone.getIccCard().hasIccCard();
3664 } else {
3665 return false;
3666 }
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003670 }
3671
3672 /**
3673 * Return if the current radio is LTE on CDMA. This
3674 * is a tri-state return value as for a period of time
3675 * the mode may be unknown.
3676 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003677 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003678 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003679 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003680 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003681 @Override
3682 public int getLteOnCdmaMode(String callingPackage) {
3683 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003684 }
3685
Sanket Padawe356d7632015-06-22 14:03:32 -07003686 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003687 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003689 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003690 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3691 }
3692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003693 final long identity = Binder.clearCallingIdentity();
3694 try {
3695 final Phone phone = getPhone(subId);
3696 if (phone == null) {
3697 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3698 } else {
3699 return phone.getLteOnCdmaMode();
3700 }
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003703 }
Wink Saville36469e72014-06-11 15:17:00 -07003704 }
3705
Wink Saville36469e72014-06-11 15:17:00 -07003706 /**
3707 * {@hide}
3708 * Returns Default subId, 0 in the case of single standby.
3709 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003710 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003711 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003712 }
3713
Shishir Agrawala9f32182016-04-12 12:00:16 -07003714 private int getSlotForDefaultSubscription() {
3715 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3716 }
3717
Wink Savilleb564aae2014-10-23 10:18:09 -07003718 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003719 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003720 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003721
Pengquan Menge92a50d2018-09-21 15:54:48 -07003722 private boolean isActiveSubscription(int subId) {
3723 return mSubscriptionController.isActiveSubId(subId);
3724 }
3725
Ihab Awadf2177b72013-11-25 13:33:23 -08003726 /**
3727 * @see android.telephony.TelephonyManager.WifiCallingChoices
3728 */
3729 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730 final long identity = Binder.clearCallingIdentity();
3731 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003732 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3734 getWhenToMakeWifiCallsDefaultPreference());
3735 } finally {
3736 Binder.restoreCallingIdentity(identity);
3737 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003738 }
3739
3740 /**
3741 * @see android.telephony.TelephonyManager.WifiCallingChoices
3742 */
3743 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003747 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3749 } finally {
3750 Binder.restoreCallingIdentity(identity);
3751 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003752 }
3753
Sailesh Nepald1e68152013-12-12 19:08:02 -08003754 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003755 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003756 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003757 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003758
Jordan Liu4c733742019-02-28 12:03:40 -08003759 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3760 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3761 if (phoneId == -1) {
3762 throw new IllegalArgumentException("Given slot index: " + slotIndex
3763 + " does not correspond to an active phone");
3764 }
3765 return PhoneFactory.getPhone(phoneId);
3766 }
3767
Shishir Agrawal566b7612013-10-28 14:41:00 -07003768 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003769 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3770 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3772 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003774 if (DBG) {
3775 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3776 }
3777 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3778 p2);
3779 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003780
Jordan Liu4c733742019-02-28 12:03:40 -08003781
3782 @Override
3783 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3784 int slotIndex, String callingPackage, String aid, int p2) {
3785 enforceModifyPermission();
3786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3787 if (DBG) {
3788 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3789 }
3790 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3791 callingPackage, aid, p2);
3792 }
3793
3794 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3795 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 if (TextUtils.equals(ISDR_AID, aid)) {
3799 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003800 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3801 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802 if (bestComponent == null
3803 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3804 loge("The calling package is not allowed to access ISD-R.");
3805 throw new SecurityException(
3806 "The calling package is not allowed to access ISD-R.");
3807 }
Derek Tan740e1672017-06-27 14:56:27 -07003808 }
Derek Tan740e1672017-06-27 14:56:27 -07003809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003811 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3812 null /* workSource */);
3813 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 return response;
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
3817 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003818 }
3819
3820 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003821 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3823 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003824 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3825 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3826 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003827
Jordan Liu4c733742019-02-28 12:03:40 -08003828 @Override
3829 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3830 enforceModifyPermission();
3831 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3832 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3833 channel);
3834 }
3835
3836 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837 final long identity = Binder.clearCallingIdentity();
3838 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 if (channel < 0) {
3840 return false;
3841 }
Jordan Liu4c733742019-02-28 12:03:40 -08003842 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3843 null /* workSource */);
3844 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003845 return success;
3846 } finally {
3847 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003848 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003849 }
3850
3851 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003852 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003853 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3855 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003856 if (DBG) {
3857 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3858 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3859 + p3 + " data=" + data);
3860 }
3861 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3862 command, p1, p2, p3, data);
3863 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003864
Jordan Liu4c733742019-02-28 12:03:40 -08003865 @Override
3866 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3867 int command, int p1, int p2, int p3, String data) {
3868 enforceModifyPermission();
3869 if (DBG) {
3870 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3871 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3872 + p3 + " data=" + data);
3873 }
3874 return iccTransmitApduLogicalChannelWithPermission(
3875 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3876 data);
3877 }
3878
3879 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3880 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003881 final long identity = Binder.clearCallingIdentity();
3882 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003883 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884 return "";
3885 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003888 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3889 null /* workSource */);
3890 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892 // Append the returned status code to the end of the response payload.
3893 String s = Integer.toHexString(
3894 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3895 if (response.payload != null) {
3896 s = IccUtils.bytesToHexString(response.payload) + s;
3897 }
3898 return s;
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003901 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003902 }
Jake Hambye994d462014-02-03 13:10:13 -08003903
Evan Charltonc66da362014-05-16 14:06:40 -07003904 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003905 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3906 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3908 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003910 if (DBG) {
3911 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3912 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3913 }
3914 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3915 cla, command, p1, p2, p3, data);
3916 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003917
Jordan Liu4c733742019-02-28 12:03:40 -08003918 @Override
3919 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3920 int command, int p1, int p2, int p3, String data) {
3921 enforceModifyPermission();
3922 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3923 if (DBG) {
3924 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3925 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3926 + " data=" + data);
3927 }
3928
3929 return iccTransmitApduBasicChannelWithPermission(
3930 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3931 p2, p3, data);
3932 }
3933
3934 // open APDU basic channel assuming the caller has sufficient permissions
3935 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3936 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3940 && TextUtils.equals(ISDR_AID, data)) {
3941 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003942 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3943 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 if (bestComponent == null
3945 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3946 loge("The calling package is not allowed to select ISD-R.");
3947 throw new SecurityException(
3948 "The calling package is not allowed to select ISD-R.");
3949 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003950 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003953 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3954 null /* workSource */);
3955 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957 // Append the returned status code to the end of the response payload.
3958 String s = Integer.toHexString(
3959 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3960 if (response.payload != null) {
3961 s = IccUtils.bytesToHexString(response.payload) + s;
3962 }
3963 return s;
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003966 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003967 }
3968
3969 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003970 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003971 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3973 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 if (DBG) {
3978 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3979 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3980 }
3981
3982 IccIoResult response =
3983 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3984 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3985 subId);
3986
3987 if (DBG) {
3988 log("Exchange SIM_IO [R]" + response);
3989 }
3990
3991 byte[] result = null;
3992 int length = 2;
3993 if (response.payload != null) {
3994 length = 2 + response.payload.length;
3995 result = new byte[length];
3996 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3997 } else {
3998 result = new byte[length];
3999 }
4000
4001 result[length - 1] = (byte) response.sw2;
4002 result[length - 2] = (byte) response.sw1;
4003 return result;
4004 } finally {
4005 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004006 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004007 }
4008
Nathan Haroldb3014052017-01-25 15:57:32 -08004009 /**
4010 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4011 * on a particular subscription
4012 */
sqianb6e41952018-03-12 14:54:01 -07004013 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4015 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4016 return null;
4017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018
4019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 if (appType != TelephonyManager.APPTYPE_USIM
4022 && appType != TelephonyManager.APPTYPE_SIM) {
4023 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4024 return null;
4025 }
4026 Object response = sendRequest(
4027 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4028 if (response instanceof String[]) {
4029 return (String[]) response;
4030 }
4031 // Response is an Exception of some kind,
4032 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004033 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004034 } finally {
4035 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004036 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004037 }
4038
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004039 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004040 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4042 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044 final long identity = Binder.clearCallingIdentity();
4045 try {
4046 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4047 if (response.payload == null) {
4048 return "";
4049 }
Evan Charltonc66da362014-05-16 14:06:40 -07004050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051 // Append the returned status code to the end of the response payload.
4052 String s = Integer.toHexString(
4053 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4054 s = IccUtils.bytesToHexString(response.payload) + s;
4055 return s;
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
Evan Charltonc66da362014-05-16 14:06:40 -07004059 }
4060
Jake Hambye994d462014-02-03 13:10:13 -08004061 /**
4062 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4063 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4064 *
4065 * @param itemID the ID of the item to read
4066 * @return the NV item as a String, or null on error.
4067 */
4068 @Override
4069 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004070 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4072 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073
4074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004077 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004078 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4079 return value;
4080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
Jake Hambye994d462014-02-03 13:10:13 -08004083 }
4084
4085 /**
4086 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4087 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4088 *
4089 * @param itemID the ID of the item to read
4090 * @param itemValue the value to write, as a String
4091 * @return true on success; false on any failure
4092 */
4093 @Override
4094 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004095 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4097 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098
4099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4102 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004103 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4105 return success;
4106 } finally {
4107 Binder.restoreCallingIdentity(identity);
4108 }
Jake Hambye994d462014-02-03 13:10:13 -08004109 }
4110
4111 /**
4112 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4113 * Used for device configuration by some CDMA operators.
4114 *
4115 * @param preferredRoamingList byte array containing the new PRL
4116 * @return true on success; false on any failure
4117 */
4118 @Override
4119 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4121 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004122
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4126 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4127 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4128 return success;
4129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
Jake Hambye994d462014-02-03 13:10:13 -08004132 }
4133
4134 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004135 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004136 * Used for device configuration by some CDMA operators.
4137 *
chen xu6dac5ab2018-10-26 17:39:23 -07004138 * @param slotIndex - device slot.
4139 *
Jake Hambye994d462014-02-03 13:10:13 -08004140 * @return true on success; false on any failure
4141 */
4142 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004143 public boolean resetModemConfig(int slotIndex) {
4144 Phone phone = PhoneFactory.getPhone(slotIndex);
4145 if (phone != null) {
4146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4147 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148
chen xu6dac5ab2018-10-26 17:39:23 -07004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4152 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4153 return success;
4154 } finally {
4155 Binder.restoreCallingIdentity(identity);
4156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157 }
chen xu6dac5ab2018-10-26 17:39:23 -07004158 return false;
4159 }
4160
4161 /**
4162 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4163 *
4164 * @param slotIndex - device slot.
4165 *
4166 * @return true on success; false on any failure
4167 */
4168 @Override
4169 public boolean rebootModem(int slotIndex) {
4170 Phone phone = PhoneFactory.getPhone(slotIndex);
4171 if (phone != null) {
4172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4173 mApp, phone.getSubId(), "rebootModem");
4174
4175 final long identity = Binder.clearCallingIdentity();
4176 try {
4177 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4178 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4179 return success;
4180 } finally {
4181 Binder.restoreCallingIdentity(identity);
4182 }
4183 }
4184 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004185 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004186
Svet Ganovb320e182015-04-16 12:30:10 -07004187 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004188 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004190 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004191 return new String[0];
4192 }
4193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194 final long identity = Binder.clearCallingIdentity();
4195 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004196 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 } finally {
4198 Binder.restoreCallingIdentity(identity);
4199 }
Wink Saville36469e72014-06-11 15:17:00 -07004200 }
4201
Brad Ebinger51f743a2017-01-23 13:50:20 -08004202 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004203 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4204 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004205 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004206 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004207 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208
4209 final long identity = Binder.clearCallingIdentity();
4210 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004211 ImsResolver resolver = PhoneFactory.getImsResolver();
4212 if (resolver == null) {
4213 // may happen if the device does not support IMS.
4214 return;
4215 }
4216 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217 } finally {
4218 Binder.restoreCallingIdentity(identity);
4219 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004220 }
4221
4222 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004223 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4224 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004225 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004226 public void disableIms(int slotId) {
4227 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228
4229 final long identity = Binder.clearCallingIdentity();
4230 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004231 ImsResolver resolver = PhoneFactory.getImsResolver();
4232 if (resolver == null) {
4233 // may happen if the device does not support IMS.
4234 return;
4235 }
4236 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237 } finally {
4238 Binder.restoreCallingIdentity(identity);
4239 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004240 }
4241
4242 /**
4243 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4244 * feature or {@link null} if the service is not available. If the feature is available, the
4245 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4246 */
4247 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004248 IImsServiceFeatureCallback callback) {
4249 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250
4251 final long identity = Binder.clearCallingIdentity();
4252 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004253 ImsResolver resolver = PhoneFactory.getImsResolver();
4254 if (resolver == null) {
4255 // may happen if the device does not support IMS.
4256 return null;
4257 }
4258 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004262 }
4263
4264 /**
4265 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4266 * feature during emergency calling or {@link null} if the service is not available. If the
4267 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4268 * listener for feature updates.
4269 */
4270 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4271 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272
4273 final long identity = Binder.clearCallingIdentity();
4274 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004275 ImsResolver resolver = PhoneFactory.getImsResolver();
4276 if (resolver == null) {
4277 // may happen if the device does not support IMS.
4278 return null;
4279 }
4280 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004284 }
4285
Brad Ebinger5f64b052017-12-14 14:26:15 -08004286 /**
4287 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004288 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004289 */
4290 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4291 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292
4293 final long identity = Binder.clearCallingIdentity();
4294 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004295 ImsResolver resolver = PhoneFactory.getImsResolver();
4296 if (resolver == null) {
4297 // may happen if the device does not support IMS.
4298 return null;
4299 }
4300 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004304 }
4305
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004306 /**
4307 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004308 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004309 */
4310 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4311 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004315 ImsResolver resolver = PhoneFactory.getImsResolver();
4316 if (resolver == null) {
4317 // may happen if the device does not support IMS.
4318 return null;
4319 }
4320 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004324 }
4325
Brad Ebinger884c07b2018-02-15 16:17:40 -08004326 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004327 * Sets the ImsService Package Name that Telephony will bind to.
4328 *
4329 * @param slotId the slot ID that the ImsService should bind for.
4330 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4331 * ImsService is the device default ImsService.
4332 * @param packageName The package name of the application that contains the ImsService to bind
4333 * to.
4334 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4335 * @hide
4336 */
4337 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004338 int[] subIds = SubscriptionManager.getSubId(slotId);
4339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4340 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4341 "setImsService");
4342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 final long identity = Binder.clearCallingIdentity();
4344 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004345 ImsResolver resolver = PhoneFactory.getImsResolver();
4346 if (resolver == null) {
4347 // may happen if the device does not support IMS.
4348 return false;
4349 }
4350 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4351 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352 } finally {
4353 Binder.restoreCallingIdentity(identity);
4354 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004355 }
4356
4357 /**
4358 * Return the ImsService configuration.
4359 *
4360 * @param slotId The slot that the ImsService is associated with.
4361 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4362 * the device default.
4363 * @return the package name of the ImsService configuration.
4364 */
4365 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004366 int[] subIds = SubscriptionManager.getSubId(slotId);
4367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4368 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4369 "getImsService");
4370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371 final long identity = Binder.clearCallingIdentity();
4372 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004373 ImsResolver resolver = PhoneFactory.getImsResolver();
4374 if (resolver == null) {
4375 // may happen if the device does not support IMS.
4376 return "";
4377 }
4378 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004382 }
4383
Wink Saville36469e72014-06-11 15:17:00 -07004384 public void setImsRegistrationState(boolean registered) {
4385 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386
4387 final long identity = Binder.clearCallingIdentity();
4388 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004389 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004390 } finally {
4391 Binder.restoreCallingIdentity(identity);
4392 }
Wink Saville36469e72014-06-11 15:17:00 -07004393 }
4394
4395 /**
Stuart Scott54788802015-03-30 13:18:01 -07004396 * Set the network selection mode to automatic.
4397 *
4398 */
4399 @Override
4400 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4402 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403
Pengquan Menge92a50d2018-09-21 15:54:48 -07004404 if (!isActiveSubscription(subId)) {
4405 return;
4406 }
4407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408 final long identity = Binder.clearCallingIdentity();
4409 try {
4410 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4411 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
Stuart Scott54788802015-03-30 13:18:01 -07004415 }
4416
Pengquan Mengea84e042018-09-20 14:57:26 -07004417 /**
4418 * Ask the radio to connect to the input network and change selection mode to manual.
4419 *
4420 * @param subId the id of the subscription.
4421 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4422 * the operator to attach to.
4423 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4424 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4425 * normal network selection next time.
4426 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004427 */
4428 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004429 public boolean setNetworkSelectionModeManual(
4430 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4432 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004433
4434 if (!isActiveSubscription(subId)) {
4435 return false;
4436 }
4437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004438 final long identity = Binder.clearCallingIdentity();
4439 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004440 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004442 if (DBG) {
4443 log("setNetworkSelectionModeManual: subId: " + subId
4444 + " operator: " + operatorInfo);
4445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004450 }
4451
4452 /**
4453 * Scans for available networks.
4454 */
4455 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004456 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4458 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004459 LocationAccessPolicy.LocationPermissionResult locationResult =
4460 LocationAccessPolicy.checkLocationPermission(mApp,
4461 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4462 .setCallingPackage(callingPackage)
4463 .setCallingPid(Binder.getCallingPid())
4464 .setCallingUid(Binder.getCallingUid())
4465 .setMethod("getCellNetworkScanResults")
4466 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4467 .build());
4468 switch (locationResult) {
4469 case DENIED_HARD:
4470 throw new SecurityException("Not allowed to access scan results -- location");
4471 case DENIED_SOFT:
4472 return null;
4473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474
Pengquan Menga1bb6272018-09-06 09:59:22 -07004475 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476 try {
4477 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004478 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004483 }
4484
4485 /**
yinxub1bed742017-04-17 11:45:04 -07004486 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004487 *
yinxub1bed742017-04-17 11:45:04 -07004488 * @param subId id of the subscription
4489 * @param request contains the radio access networks with bands/channels to scan
4490 * @param messenger callback messenger for scan results or errors
4491 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004492 * @return the id of the requested scan which can be used to stop the scan.
4493 */
4494 @Override
4495 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004496 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4498 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004499 LocationAccessPolicy.LocationPermissionResult locationResult =
4500 LocationAccessPolicy.checkLocationPermission(mApp,
4501 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4502 .setCallingPackage(callingPackage)
4503 .setCallingPid(Binder.getCallingPid())
4504 .setCallingUid(Binder.getCallingUid())
4505 .setMethod("requestNetworkScan")
4506 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4507 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004508 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004509 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004510 if (e != null) {
4511 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4512 throw e;
4513 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004514 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004515 return TelephonyScanManager.INVALID_SCAN_ID;
4516 }
4517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 }
Hall Liu912dfd32019-04-25 14:02:26 -07004519 int callingUid = Binder.getCallingUid();
4520 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004521 final long identity = Binder.clearCallingIdentity();
4522 try {
4523 return mNetworkScanRequestTracker.startNetworkScan(
4524 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004525 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
yinxu504e1392017-04-12 16:03:22 -07004529 }
4530
Hall Liub2ac8ef2019-02-28 15:56:23 -08004531 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004532 NetworkScanRequest request, int subId) {
4533 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4534 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4535 boolean hasNetworkScanPermission =
4536 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4537 == PERMISSION_GRANTED;
4538
4539 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4540 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4541 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004542 }
4543
4544 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4545 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004546 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4547 return new SecurityException("Specific channels must not be"
4548 + " scanned without location access.");
4549 }
4550 }
4551 }
4552
Hall Liub2ac8ef2019-02-28 15:56:23 -08004553 return null;
4554 }
4555
yinxu504e1392017-04-12 16:03:22 -07004556 /**
4557 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004558 *
4559 * @param subId id of the subscription
4560 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004561 */
4562 @Override
4563 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4565 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566
Hall Liu912dfd32019-04-25 14:02:26 -07004567 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 final long identity = Binder.clearCallingIdentity();
4569 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004570 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 } finally {
4572 Binder.restoreCallingIdentity(identity);
4573 }
yinxu504e1392017-04-12 16:03:22 -07004574 }
4575
4576 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004577 * Get the calculated preferred network type.
4578 * Used for debugging incorrect network type.
4579 *
4580 * @return the preferred network type, defined in RILConstants.java.
4581 */
4582 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004583 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004584 final Phone defaultPhone = getDefaultPhone();
4585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4586 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004587 return RILConstants.PREFERRED_NETWORK_MODE;
4588 }
4589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004593 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 } finally {
4595 Binder.restoreCallingIdentity(identity);
4596 }
Junda Liu84d15a22014-07-02 11:21:04 -07004597 }
4598
4599 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004600 * Get the preferred network type.
4601 * Used for device configuration by some CDMA operators.
4602 *
4603 * @return the preferred network type, defined in RILConstants.java.
4604 */
4605 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004606 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004607 TelephonyPermissions
4608 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4609 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610
4611 final long identity = Binder.clearCallingIdentity();
4612 try {
4613 if (DBG) log("getPreferredNetworkType");
4614 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4615 int networkType = (result != null ? result[0] : -1);
4616 if (DBG) log("getPreferredNetworkType: " + networkType);
4617 return networkType;
4618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004621 }
4622
4623 /**
4624 * Set the preferred network type.
4625 * Used for device configuration by some CDMA operators.
4626 *
4627 * @param networkType the preferred network type, defined in RILConstants.java.
4628 * @return true on success; false on any failure.
4629 */
4630 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004631 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4633 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004634
4635 final long identity = Binder.clearCallingIdentity();
4636 try {
4637 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4638 Boolean success = (Boolean) sendRequest(
4639 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4640 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4641 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004642 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4644 }
4645 return success;
4646 } finally {
4647 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004648 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004649 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004650
4651 /**
Miaoa84611c2019-03-15 09:21:10 +08004652 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004653 *
Miaoa84611c2019-03-15 09:21:10 +08004654 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004655 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004656 * @hide
4657 */
4658 @Override
Miaoa84611c2019-03-15 09:21:10 +08004659 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004660 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004662 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 try {
Miaoa84611c2019-03-15 09:21:10 +08004664 if (phone != null) {
4665 return phone.hasMatchedTetherApnSetting();
4666 } else {
4667 return false;
4668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004669 } finally {
4670 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004671 }
Junda Liu475951f2014-11-07 16:45:03 -08004672 }
4673
4674 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004675 * Set mobile data enabled
4676 * Used by the user through settings etc to turn on/off mobile data
4677 *
4678 * @param enable {@code true} turn turn data on, else {@code false}
4679 */
4680 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004681 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4683 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
4687 int phoneId = mSubscriptionController.getPhoneId(subId);
4688 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4689 Phone phone = PhoneFactory.getPhone(phoneId);
4690 if (phone != null) {
4691 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004692 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004694 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 }
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004698 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004699 }
4700
4701 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004702 * Get the user enabled state of Mobile Data.
4703 *
4704 * TODO: remove and use isUserDataEnabled.
4705 * This can't be removed now because some vendor codes
4706 * calls through ITelephony directly while they should
4707 * use TelephonyManager.
4708 *
4709 * @return true on enabled
4710 */
4711 @Override
4712 public boolean getDataEnabled(int subId) {
4713 return isUserDataEnabled(subId);
4714 }
4715
4716 /**
4717 * Get whether mobile data is enabled per user setting.
4718 *
4719 * There are other factors deciding whether mobile data is actually enabled, but they are
4720 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004721 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004722 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004723 *
4724 * @return {@code true} if data is enabled else {@code false}
4725 */
4726 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004727 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004728 try {
4729 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4730 null);
4731 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4733 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004734 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735
4736 final long identity = Binder.clearCallingIdentity();
4737 try {
4738 int phoneId = mSubscriptionController.getPhoneId(subId);
4739 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4740 Phone phone = PhoneFactory.getPhone(phoneId);
4741 if (phone != null) {
4742 boolean retVal = phone.isUserDataEnabled();
4743 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4744 return retVal;
4745 } else {
4746 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4747 return false;
4748 }
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004751 }
4752 }
4753
4754 /**
4755 * Get whether mobile data is enabled.
4756 *
4757 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4758 * whether mobile data is actually enabled.
4759 *
4760 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4761 *
4762 * @return {@code true} if data is enabled else {@code false}
4763 */
4764 @Override
4765 public boolean isDataEnabled(int subId) {
4766 try {
4767 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4768 null);
4769 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4771 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773
4774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 int phoneId = mSubscriptionController.getPhoneId(subId);
4777 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4778 Phone phone = PhoneFactory.getPhone(phoneId);
4779 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004780 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4782 return retVal;
4783 } else {
4784 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4785 return false;
4786 }
4787 } finally {
4788 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004789 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004790 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004791
4792 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004793 public int getCarrierPrivilegeStatus(int subId) {
4794 final Phone phone = getPhone(subId);
4795 if (phone == null) {
4796 loge("getCarrierPrivilegeStatus: Invalid subId");
4797 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4798 }
4799 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004800 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004801 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004802 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4803 }
4804 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004805 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004806 }
Junda Liu29340342014-07-10 15:23:27 -07004807
4808 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004809 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4810 final Phone phone = getPhone(subId);
4811 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004812 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004813 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4814 }
4815 UiccProfile profile =
4816 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4817 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004818 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004819 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4820 }
4821 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4822 }
4823
4824 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004825 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4826 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004827 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004828 }
4829
4830 int phoneId = SubscriptionManager.getPhoneId(subId);
4831 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004832 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004833 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004834 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4835 }
chen xuf7e9fe82019-05-09 19:31:02 -07004836
4837 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004838 }
4839
4840 @Override
4841 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004842 if (TextUtils.isEmpty(pkgName))
4843 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004844 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4845 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4846 UiccCard card = UiccController.getInstance().getUiccCard(i);
4847 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004848 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004849 continue;
4850 }
4851
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004852 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004853 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4854 break;
4855 }
4856 }
4857
4858 return result;
Junda Liu29340342014-07-10 15:23:27 -07004859 }
Derek Tan89e89d42014-07-08 17:00:10 -07004860
4861 @Override
Junda Liue64de782015-04-16 17:19:16 -07004862 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4863 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4864 loge("phoneId " + phoneId + " is not valid.");
4865 return null;
4866 }
4867 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004868 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004869 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004870 return null ;
4871 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004872 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004873 }
4874
Amith Yamasani6e118872016-02-19 12:53:51 -08004875 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004876 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004877 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004878 List<String> privilegedPackages = new ArrayList<>();
4879 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004880 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4881 // has UICC in that slot.
4882 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004883 if (card.hasCarrierPrivilegeRules()) {
4884 if (packages == null) {
4885 // Only check packages in user 0 for now
4886 packages = pm.getInstalledPackagesAsUser(
4887 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004888 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4889 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004890 }
4891 for (int p = packages.size() - 1; p >= 0; p--) {
4892 PackageInfo pkgInfo = packages.get(p);
4893 if (pkgInfo != null && pkgInfo.packageName != null
4894 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004895 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004896 privilegedPackages.add(pkgInfo.packageName);
4897 }
4898 }
4899 }
4900 }
4901 return privilegedPackages;
4902 }
4903
chen xuf7e9fe82019-05-09 19:31:02 -07004904 @Override
4905 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4906 List<String> privilegedPackages = new ArrayList<>();
4907 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4908 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4909 }
4910 return privilegedPackages;
4911 }
4912
Wink Savilleb564aae2014-10-23 10:18:09 -07004913 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004914 final Phone phone = getPhone(subId);
4915 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004916 if (card == null) {
4917 loge("getIccId: No UICC");
4918 return null;
4919 }
4920 String iccId = card.getIccId();
4921 if (TextUtils.isEmpty(iccId)) {
4922 loge("getIccId: ICC ID is null or empty.");
4923 return null;
4924 }
4925 return iccId;
4926 }
4927
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004928 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004929 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4930 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004931 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4932 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 final long identity = Binder.clearCallingIdentity();
4935 try {
4936 final String iccId = getIccId(subId);
4937 final Phone phone = getPhone(subId);
4938 if (phone == null) {
4939 return false;
4940 }
4941 final String subscriberId = phone.getSubscriberId();
4942
4943 if (DBG_MERGE) {
4944 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4945 + subscriberId + " to " + number);
4946 }
4947
4948 if (TextUtils.isEmpty(iccId)) {
4949 return false;
4950 }
4951
4952 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4953
4954 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4955 if (alphaTag == null) {
4956 editor.remove(alphaTagPrefKey);
4957 } else {
4958 editor.putString(alphaTagPrefKey, alphaTag);
4959 }
4960
4961 // Record both the line number and IMSI for this ICCID, since we need to
4962 // track all merged IMSIs based on line number
4963 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4964 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4965 if (number == null) {
4966 editor.remove(numberPrefKey);
4967 editor.remove(subscriberPrefKey);
4968 } else {
4969 editor.putString(numberPrefKey, number);
4970 editor.putString(subscriberPrefKey, subscriberId);
4971 }
4972
4973 editor.commit();
4974 return true;
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004977 }
Derek Tan7226c842014-07-02 17:42:23 -07004978 }
4979
4980 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004981 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004982 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004984 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004985 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004986 return null;
4987 }
Derek Tan97ebb422014-09-05 16:55:38 -07004988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 final long identity = Binder.clearCallingIdentity();
4990 try {
4991 String iccId = getIccId(subId);
4992 if (iccId != null) {
4993 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4994 if (DBG_MERGE) {
4995 log("getLine1NumberForDisplay returning "
4996 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4997 }
4998 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5001 return null;
5002 } finally {
5003 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005004 }
Derek Tan7226c842014-07-02 17:42:23 -07005005 }
5006
5007 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005008 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005010 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005011 return null;
5012 }
Derek Tan97ebb422014-09-05 16:55:38 -07005013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 String iccId = getIccId(subId);
5017 if (iccId != null) {
5018 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5019 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5020 }
5021 return null;
5022 } finally {
5023 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005024 }
Derek Tan7226c842014-07-02 17:42:23 -07005025 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005026
5027 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005028 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005029 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5030 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005032 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5033 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005034 return null;
5035 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005036
Jordan Liub49b04b2019-05-06 14:45:15 -07005037 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5038 // the process, where TelephonyManager was instantiated.
5039 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005040 final long identity = Binder.clearCallingIdentity();
5041 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005042 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 final TelephonyManager tele = TelephonyManager.from(context);
5044 final SubscriptionManager sub = SubscriptionManager.from(context);
5045
5046 // Figure out what subscribers are currently active
5047 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048
Jordan Liub49b04b2019-05-06 14:45:15 -07005049 // Only consider subs which match the current subId
5050 // This logic can be simplified. See b/131189269 for progress.
5051 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005052 activeSubscriberIds.add(tele.getSubscriberId(subId));
5053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054
5055 // First pass, find a number override for an active subscriber
5056 String mergeNumber = null;
5057 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5058 for (String key : prefs.keySet()) {
5059 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5060 final String subscriberId = (String) prefs.get(key);
5061 if (activeSubscriberIds.contains(subscriberId)) {
5062 final String iccId = key.substring(
5063 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5064 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5065 mergeNumber = (String) prefs.get(numberKey);
5066 if (DBG_MERGE) {
5067 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5068 + " for active subscriber " + subscriberId);
5069 }
5070 if (!TextUtils.isEmpty(mergeNumber)) {
5071 break;
5072 }
5073 }
5074 }
5075 }
5076
5077 // Shortcut when no active merged subscribers
5078 if (TextUtils.isEmpty(mergeNumber)) {
5079 return null;
5080 }
5081
5082 // Second pass, find all subscribers under that line override
5083 final ArraySet<String> result = new ArraySet<>();
5084 for (String key : prefs.keySet()) {
5085 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5086 final String number = (String) prefs.get(key);
5087 if (mergeNumber.equals(number)) {
5088 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5089 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5090 final String subscriberId = (String) prefs.get(subscriberKey);
5091 if (!TextUtils.isEmpty(subscriberId)) {
5092 result.add(subscriberId);
5093 }
5094 }
5095 }
5096 }
5097
5098 final String[] resultArray = result.toArray(new String[result.size()]);
5099 Arrays.sort(resultArray);
5100 if (DBG_MERGE) {
5101 Slog.d(LOG_TAG,
5102 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5103 }
5104 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005105 } finally {
5106 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005107 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005108 }
5109
5110 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005111 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005112 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5113 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114
5115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 final Phone phone = getPhone(subId);
5118 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5119 } finally {
5120 Binder.restoreCallingIdentity(identity);
5121 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005122 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005123
5124 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005125 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005126 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5127 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005128 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129
5130 final long identity = Binder.clearCallingIdentity();
5131 try {
5132 final Phone phone = getPhone(subId);
5133 if (phone == null) {
5134 return false;
5135 }
5136 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5137 cdmaNonRoamingList);
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005140 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005141 }
5142
5143 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005144 @Deprecated
5145 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5146 enforceModifyPermission();
5147
5148 int returnValue = 0;
5149 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005150 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005151 if(result.exception == null) {
5152 if (result.result != null) {
5153 byte[] responseData = (byte[])(result.result);
5154 if(responseData.length > oemResp.length) {
5155 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5156 responseData.length + "bytes. Buffer Size is " +
5157 oemResp.length + "bytes.");
5158 }
5159 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5160 returnValue = responseData.length;
5161 }
5162 } else {
5163 CommandException ex = (CommandException) result.exception;
5164 returnValue = ex.getCommandError().ordinal();
5165 if(returnValue > 0) returnValue *= -1;
5166 }
5167 } catch (RuntimeException e) {
5168 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5169 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5170 if(returnValue > 0) returnValue *= -1;
5171 }
5172
5173 return returnValue;
5174 }
5175
5176 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005177 public void setRadioCapability(RadioAccessFamily[] rafs) {
5178 try {
5179 ProxyController.getInstance().setRadioCapability(rafs);
5180 } catch (RuntimeException e) {
5181 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5182 }
5183 }
5184
5185 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005186 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005187 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005188 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005189 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005190 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 final long identity = Binder.clearCallingIdentity();
5193 try {
chen xub97461a2018-10-26 14:17:57 -07005194 TelephonyPermissions
5195 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5196 mApp, phone.getSubId(), "getRadioAccessFamily");
5197 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
chen xub97461a2018-10-26 14:17:57 -07005201 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005202 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005203
5204 @Override
5205 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005206 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005207 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208
5209 final long identity = Binder.clearCallingIdentity();
5210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005211 ImsManager.getInstance(defaultPhone.getContext(),
5212 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005216 }
5217
5218 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005219 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005220 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005222 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005223 return false;
5224 }
Svet Ganovb320e182015-04-16 12:30:10 -07005225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 final long identity = Binder.clearCallingIdentity();
5227 try {
5228 // Check the user preference and the system-level IMS setting. Even if the user has
5229 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5230 // In the long run, we may instead need to check if there exists a connection service
5231 // which can support video calling.
5232 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005233 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 return imsManager.isVtEnabledByPlatform()
5235 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5236 && imsManager.isVtEnabledByUser();
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005240 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005241
Andrew Leea1239f22015-03-02 17:44:07 -08005242 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5245 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5246 return false;
5247 }
5248
5249 final long identity = Binder.clearCallingIdentity();
5250 try {
5251 CarrierConfigManager configManager =
5252 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005253 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5255 } finally {
5256 Binder.restoreCallingIdentity(identity);
5257 }
Andrew Leea1239f22015-03-02 17:44:07 -08005258 }
5259
5260 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 public boolean isWorldPhone(int subId, String callingPackage) {
5262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5263 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5264 return false;
5265 }
5266
5267 final long identity = Binder.clearCallingIdentity();
5268 try {
5269 CarrierConfigManager configManager =
5270 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005271 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
Andrew Leea1239f22015-03-02 17:44:07 -08005276 }
5277
Andrew Lee9431b832015-03-09 18:46:45 -07005278 @Override
5279 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005280 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005281 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005282 }
5283
5284 @Override
5285 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005288 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
Andrew Lee9431b832015-03-09 18:46:45 -07005292 }
5293
Hall Liuf6668912018-10-31 17:05:23 -07005294 /**
5295 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5296 * support for the feature and device firmware support.
5297 *
5298 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5299 */
5300 @Override
5301 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005303 final Phone phone = getPhone(subscriptionId);
5304 if (phone == null) {
5305 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5306 return false;
5307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005309 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5311 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005312 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 return isCarrierSupported && isDeviceSupported;
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
Hall Liu98187582018-01-22 19:15:32 -08005317 }
5318
Hall Liuf6668912018-10-31 17:05:23 -07005319 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005320 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5321 * RTT setting, will return true if the device and carrier both support RTT.
5322 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005323 */
5324 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 final long identity = Binder.clearCallingIdentity();
5326 try {
Hall Liu6a06be62019-07-23 18:39:00 -07005327 boolean isRttSupported = isRttSupported(subscriptionId);
5328 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005329 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liu6a06be62019-07-23 18:39:00 -07005330 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5331 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5332 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005336 }
5337
Sanket Padawe7310cc72015-01-14 09:53:20 -08005338 /**
5339 * Returns the unique device ID of phone, for example, the IMEI for
5340 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5341 *
5342 * <p>Requires Permission:
5343 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5344 */
5345 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005346 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005347 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005348 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005349 return null;
5350 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005351 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005352 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5353 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005354 return null;
5355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356
5357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 return phone.getDeviceId();
5360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005363 }
5364
Ping Sunc67b7c22016-03-02 19:16:45 +08005365 /**
5366 * {@hide}
5367 * Returns the IMS Registration Status on a particular subid
5368 *
5369 * @param subId
5370 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005371 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005372 Phone phone = getPhone(subId);
5373 if (phone != null) {
5374 return phone.isImsRegistered();
5375 } else {
5376 return false;
5377 }
5378 }
5379
Santos Cordon7a1885b2015-02-03 11:15:19 -08005380 @Override
5381 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 final long identity = Binder.clearCallingIdentity();
5383 try {
5384 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5385 } finally {
5386 Binder.restoreCallingIdentity(identity);
5387 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005388 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005389
Tyler Gunnf70ed162019-04-03 15:28:53 -07005390 @Override
5391 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5392 final long identity = Binder.clearCallingIdentity();
5393 try {
5394 Phone phone = getPhone(subscriptionId);
5395 if (phone == null) {
5396 return null;
5397 }
5398 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
5402 }
5403
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005404 /**
5405 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005406 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005407 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 final long identity = Binder.clearCallingIdentity();
5409 try {
5410 Phone phone = getPhone(subId);
5411 if (phone != null) {
5412 return phone.isWifiCallingEnabled();
5413 } else {
5414 return false;
5415 }
5416 } finally {
5417 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005418 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005419 }
5420
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005421 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005422 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005423 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005424 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 Phone phone = getPhone(subId);
5428 if (phone != null) {
5429 return phone.isVideoEnabled();
5430 } else {
5431 return false;
5432 }
5433 } finally {
5434 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005435 }
5436 }
5437
5438 /**
5439 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5440 * defined in {@link ImsRegistrationImplBase}.
5441 */
5442 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 final long identity = Binder.clearCallingIdentity();
5444 try {
5445 Phone phone = getPhone(subId);
5446 if (phone != null) {
5447 return phone.getImsRegistrationTech();
5448 } else {
5449 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5450 }
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005453 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005454 }
5455
Stuart Scott8eef64f2015-04-08 15:13:54 -07005456 @Override
5457 public void factoryReset(int subId) {
5458 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005459 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5460 return;
5461 }
5462
Svet Ganovcc087f82015-05-12 20:35:54 -07005463 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005464
Svet Ganovcc087f82015-05-12 20:35:54 -07005465 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005466 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5467 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005468 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005469 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005470 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005471 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5472 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005473 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005474 // There has been issues when Sms raw table somehow stores orphan
5475 // fragments. They lead to garbled message when new fragments come
5476 // in and combined with those stale ones. In case this happens again,
5477 // user can reset all network settings which will clean up this table.
5478 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005481 }
5482 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005483
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005484 private void cleanUpSmsRawTable(Context context) {
5485 ContentResolver resolver = context.getContentResolver();
5486 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5487 resolver.delete(uri, null, null);
5488 }
5489
Narayan Kamath1c496c22015-04-16 14:40:19 +01005490 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005491 public String getSimLocaleForSubscriber(int subId) {
5492 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5493 final Phone phone = getPhone(subId);
5494 if (phone == null) {
5495 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005496 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498 final long identity = Binder.clearCallingIdentity();
5499 try {
chen xu5d3637b2019-01-21 23:31:38 -08005500 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5501 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005502 if (info == null) {
5503 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5504 return null;
5505 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 // Try and fetch the locale from the carrier properties or from the SIM language
5507 // preferences (EF-PL and EF-LI)...
5508 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005510 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5511 if (localeFromDefaultSim != null) {
5512 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5513 if (DBG) log("Using locale from subId: " + subId + " locale: "
5514 + localeFromDefaultSim);
5515 return localeFromDefaultSim.toLanguageTag();
5516 } else {
5517 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 }
5519 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 // The SIM language preferences only store a language (e.g. fr = French), not an
5522 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5523 // the SIM and carrier preferences does not include a country we add the country
5524 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005525 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005527 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 return mccLocale.toLanguageTag();
5529 }
5530
5531 if (DBG) log("No locale found - returning null");
5532 return null;
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
5535 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005536 }
5537
5538 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005539 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005540 }
5541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 /**
5543 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5544 */
5545 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005546 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005547 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005548
Chenjie Yu1ba97252018-01-11 18:16:20 -08005549 private final ModemActivityInfo mLastModemActivityInfo =
5550 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5551
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005552 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005553 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5554 * representing the state of the modem.
5555 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005556 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5557 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005558 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005559 */
5560 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005561 public void requestModemActivityInfo(ResultReceiver result) {
5562 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005563 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 ModemActivityInfo ret = null;
5568 synchronized (mLastModemActivityInfo) {
5569 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5570 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005571 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005572 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5574 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005575 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5576 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 }
5578 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005579 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5580 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 mLastModemActivityInfo.setIdleTimeMillis(
5582 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5583 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5584 mLastModemActivityInfo.setRxTimeMillis(
5585 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5586 mLastModemActivityInfo.setEnergyUsed(
5587 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5590 mLastModemActivityInfo.getSleepTimeMillis(),
5591 mLastModemActivityInfo.getIdleTimeMillis(),
5592 mLastModemActivityInfo.getTxTimeMillis(),
5593 mLastModemActivityInfo.getRxTimeMillis(),
5594 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 Bundle bundle = new Bundle();
5597 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5598 result.send(0, bundle);
5599 } finally {
5600 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005601 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005602 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005603
Siddharth Rayb8114062018-06-17 15:02:38 -07005604 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5605 // less than total activity duration.
5606 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5607 if (info == null) {
5608 return false;
5609 }
5610 int activityDurationMs =
5611 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5612 int totalTxTimeMs = 0;
5613 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5614 totalTxTimeMs += info.getTxTimeMillis()[i];
5615 }
5616 return (info.isValid()
5617 && (info.getSleepTimeMillis() <= activityDurationMs)
5618 && (info.getIdleTimeMillis() <= activityDurationMs)
5619 && (info.getRxTimeMillis() <= activityDurationMs)
5620 && (totalTxTimeMs <= activityDurationMs));
5621 }
5622
Jack Yu85bd38a2015-11-09 11:34:32 -08005623 /**
5624 * {@hide}
5625 * Returns the service state information on specified subscription.
5626 */
5627 @Override
5628 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005630 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005631 return null;
5632 }
5633
Hall Liuf19c44f2018-11-27 14:38:17 -08005634 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5635 LocationAccessPolicy.checkLocationPermission(mApp,
5636 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5637 .setCallingPackage(callingPackage)
5638 .setCallingPid(Binder.getCallingPid())
5639 .setCallingUid(Binder.getCallingUid())
5640 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005641 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005642 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5643 .build());
5644
5645 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5646 LocationAccessPolicy.checkLocationPermission(mApp,
5647 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5648 .setCallingPackage(callingPackage)
5649 .setCallingPid(Binder.getCallingPid())
5650 .setCallingUid(Binder.getCallingUid())
5651 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005652 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005653 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5654 .build());
5655 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5656 boolean hasFinePermission =
5657 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5658 boolean hasCoarsePermission =
5659 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 final Phone phone = getPhone(subId);
5664 if (phone == null) {
5665 return null;
5666 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005667
Hall Liuf19c44f2018-11-27 14:38:17 -08005668 ServiceState ss = phone.getServiceState();
5669
5670 // Scrub out the location info in ServiceState depending on what level of access
5671 // the caller has.
5672 if (hasFinePermission) return ss;
5673 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5674 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005678 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005679
5680 /**
5681 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5682 *
5683 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5684 * voicemail ringtone.
5685 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5686 * PhoneAccount.
5687 */
5688 @Override
5689 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 final long identity = Binder.clearCallingIdentity();
5691 try {
5692 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5693 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005694 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005701 }
5702
5703 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005704 * Sets the per-account voicemail ringtone.
5705 *
5706 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5707 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5708 *
5709 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5710 * voicemail ringtone.
5711 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5712 * PhoneAccount.
5713 */
5714 @Override
5715 public void setVoicemailRingtoneUri(String callingPackage,
5716 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005717 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5719 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005720 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5722 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5723 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725
5726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5729 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005730 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 }
5732 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005735 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005736 }
5737
5738 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005739 * Returns whether vibration is set for voicemail notification in Phone settings.
5740 *
5741 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5742 * voicemail vibration setting.
5743 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5744 */
5745 @Override
5746 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5750 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005751 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005758 }
5759
Youhan Wange64578a2016-05-02 15:32:42 -07005760 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005761 * Sets the per-account voicemail vibration.
5762 *
5763 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5764 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5765 *
5766 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5767 * voicemail vibration setting.
5768 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5769 * specific PhoneAccount.
5770 */
5771 @Override
5772 public void setVoicemailVibrationEnabled(String callingPackage,
5773 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005774 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5776 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005777 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5779 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5780 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005781 }
5782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783 final long identity = Binder.clearCallingIdentity();
5784 try {
5785 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5786 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005787 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 }
5789 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005792 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005793 }
5794
5795 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005796 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5797 *
5798 * @throws SecurityException if the caller does not have the required permission
5799 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005800 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005801 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005802 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005803 }
5804
5805 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005806 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5807 * permission.
5808 *
5809 * @throws SecurityException if the caller does not have the required permission
5810 */
5811 private void enforceSendSmsPermission() {
5812 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5813 }
5814
5815 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005816 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005817 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005818 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005819 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005820 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 final long identity = Binder.clearCallingIdentity();
5822 try {
5823 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005824 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 if (componentName == null) {
5826 throw new SecurityException(
5827 "Caller not current active visual voicemail package[null]");
5828 }
5829 String vvmPackage = componentName.getPackageName();
5830 if (!callingPackage.equals(vvmPackage)) {
5831 throw new SecurityException("Caller not current active visual voicemail package["
5832 + vvmPackage + "]");
5833 }
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005836 }
5837 }
5838
5839 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005840 * Return the application ID for the app type.
5841 *
5842 * @param subId the subscription ID that this request applies to.
5843 * @param appType the uicc app type.
5844 * @return Application ID for specificied app type, or null if no uicc.
5845 */
5846 @Override
5847 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005848 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005849 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850
5851 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005852 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853 if (phone == null) {
5854 return null;
5855 }
5856 String aid = null;
5857 try {
5858 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5859 .getApplicationByType(appType).getAid();
5860 } catch (Exception e) {
5861 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5862 }
5863 return aid;
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005866 }
Youhan Wange64578a2016-05-02 15:32:42 -07005867 }
5868
Youhan Wang4001d252016-05-11 10:29:41 -07005869 /**
5870 * Return the Electronic Serial Number.
5871 *
5872 * @param subId the subscription ID that this request applies to.
5873 * @return ESN or null if error.
5874 */
5875 @Override
5876 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005877 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005878 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879
5880 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005881 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 if (phone == null) {
5883 return null;
5884 }
5885 String esn = null;
5886 try {
5887 esn = phone.getEsn();
5888 } catch (Exception e) {
5889 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5890 }
5891 return esn;
5892 } finally {
5893 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005894 }
Youhan Wang4001d252016-05-11 10:29:41 -07005895 }
5896
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005897 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005898 * Return the Preferred Roaming List Version.
5899 *
5900 * @param subId the subscription ID that this request applies to.
5901 * @return PRLVersion or null if error.
5902 */
5903 @Override
5904 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005905 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005906 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907
5908 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005909 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 if (phone == null) {
5911 return null;
5912 }
5913 String cdmaPrlVersion = null;
5914 try {
5915 cdmaPrlVersion = phone.getCdmaPrlVersion();
5916 } catch (Exception e) {
5917 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5918 }
5919 return cdmaPrlVersion;
5920 } finally {
5921 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005922 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005923 }
5924
5925 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005926 * Get snapshot of Telephony histograms
5927 * @return List of Telephony histograms
5928 * @hide
5929 */
5930 @Override
5931 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5933 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
5937 return RIL.getTelephonyRILTimingHistograms();
5938 } finally {
5939 Binder.restoreCallingIdentity(identity);
5940 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005941 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005942
5943 /**
5944 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005945 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5946 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005947 * Require system privileges. In the future we may add this to carrier APIs.
5948 *
Michele Berionne482f8202018-11-27 18:57:59 -08005949 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005950 */
5951 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005952 @TelephonyManager.SetCarrierRestrictionResult
5953 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005954 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005955 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005956
Michele Berionne482f8202018-11-27 18:57:59 -08005957 if (carrierRestrictionRules == null) {
5958 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005959 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 final long identity = Binder.clearCallingIdentity();
5962 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005963 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005964 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
5967 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005968 }
5969
5970 /**
5971 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005972 * Get the allowed carrier list and the excluded carrier list, including the priority between
5973 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005974 * Require system privileges. In the future we may add this to carrier APIs.
5975 *
Michele Berionne482f8202018-11-27 18:57:59 -08005976 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005977 */
5978 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005979 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005980 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005981 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982
5983 final long identity = Binder.clearCallingIdentity();
5984 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005985 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5986 if (response instanceof CarrierRestrictionRules) {
5987 return (CarrierRestrictionRules) response;
5988 }
5989 // Response is an Exception of some kind,
5990 // which is signalled to the user as a NULL retval
5991 return null;
5992 } catch (Exception e) {
5993 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5994 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 } finally {
5996 Binder.restoreCallingIdentity(identity);
5997 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005998 }
5999
fionaxu59545b42016-05-25 15:53:37 -07006000 /**
6001 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6002 * @param subId the subscription ID that this action applies to.
6003 * @param enabled control enable or disable metered apns.
6004 * {@hide}
6005 */
6006 @Override
6007 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6008 enforceModifyPermission();
6009 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
6011 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006012 if (phone == null) {
6013 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6014 return;
6015 }
6016 try {
6017 phone.carrierActionSetMeteredApnsEnabled(enabled);
6018 } catch (Exception e) {
6019 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 } finally {
6021 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006022 }
6023 }
6024
6025 /**
6026 * Action set from carrier signalling broadcast receivers to enable/disable radio
6027 * @param subId the subscription ID that this action applies to.
6028 * @param enabled control enable or disable radio.
6029 * {@hide}
6030 */
6031 @Override
6032 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6033 enforceModifyPermission();
6034 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035
6036 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006037 if (phone == null) {
6038 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6039 return;
6040 }
6041 try {
6042 phone.carrierActionSetRadioEnabled(enabled);
6043 } catch (Exception e) {
6044 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 } finally {
6046 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006047 }
6048 }
6049
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006050 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006051 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6052 * network status based on which carrier apps could apply actions accordingly,
6053 * enable/disable default url handler for example.
6054 *
6055 * @param subId the subscription ID that this action applies to.
6056 * @param report control start/stop reporting the default network status.
6057 * {@hide}
6058 */
6059 @Override
6060 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6061 enforceModifyPermission();
6062 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063
6064 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006065 if (phone == null) {
6066 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6067 return;
6068 }
6069 try {
6070 phone.carrierActionReportDefaultNetworkStatus(report);
6071 } catch (Exception e) {
6072 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 } finally {
6074 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006075 }
6076 }
6077
6078 /**
fionaxud9622282017-07-17 17:51:30 -07006079 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6080 * @param subId the subscription ID that this action applies to.
6081 * {@hide}
6082 */
6083 @Override
6084 public void carrierActionResetAll(int subId) {
6085 enforceModifyPermission();
6086 final Phone phone = getPhone(subId);
6087 if (phone == null) {
6088 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6089 return;
6090 }
6091 try {
6092 phone.carrierActionResetAll();
6093 } catch (Exception e) {
6094 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6095 }
6096 }
6097
6098 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006099 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6100 * bug report is being generated.
6101 */
6102 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006103 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006104 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6105 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006106 writer.println("Permission Denial: can't dump Phone from pid="
6107 + Binder.getCallingPid()
6108 + ", uid=" + Binder.getCallingUid()
6109 + "without permission "
6110 + android.Manifest.permission.DUMP);
6111 return;
6112 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006113 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006114 }
Jack Yueb89b242016-06-22 13:27:47 -07006115
Brad Ebingerdac2f002018-04-03 15:17:52 -07006116 @Override
6117 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6118 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6119 throws RemoteException {
6120 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6121 }
6122
Jack Yueb89b242016-06-22 13:27:47 -07006123 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006124 * Get aggregated video call data usage since boot.
6125 *
6126 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6127 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006128 * {@hide}
6129 */
6130 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006131 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006132 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6133 null);
6134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 final long identity = Binder.clearCallingIdentity();
6136 try {
6137 // NetworkStatsService keeps tracking the active network interface and identity. It
6138 // records the delta with the corresponding network identity.
6139 // We just return the total video call data usage snapshot since boot.
6140 Phone phone = getPhone(subId);
6141 if (phone != null) {
6142 return phone.getVtDataUsage(perUidStats);
6143 }
6144 return null;
6145 } finally {
6146 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006147 }
Jack Yueb89b242016-06-22 13:27:47 -07006148 }
Jack Yu75ab2952016-07-08 14:29:33 -07006149
6150 /**
6151 * Policy control of data connection. Usually used when data limit is passed.
6152 * @param enabled True if enabling the data, otherwise disabling.
6153 * @param subId Subscription index
6154 * {@hide}
6155 */
6156 @Override
6157 public void setPolicyDataEnabled(boolean enabled, int subId) {
6158 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159
6160 final long identity = Binder.clearCallingIdentity();
6161 try {
6162 Phone phone = getPhone(subId);
6163 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006164 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 }
6166 } finally {
6167 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006168 }
6169 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006170
6171 /**
6172 * Get Client request stats
6173 * @return List of Client Request Stats
6174 * @hide
6175 */
6176 @Override
6177 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006178 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006179 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006180 return null;
6181 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006182 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184 final long identity = Binder.clearCallingIdentity();
6185 try {
6186 if (phone != null) {
6187 return phone.getClientRequestStats();
6188 }
6189
6190 return null;
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
6193 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006194 }
6195
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006196 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006197 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006198 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006199 }
Jack Yueb4124c2017-02-16 15:32:43 -08006200
6201 /**
Grace Chen70990072017-03-24 17:21:30 -07006202 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006203 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006204 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006205 * @param state State of SIM (power down, power up, pass through)
6206 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6207 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6208 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006209 *
6210 **/
6211 @Override
Grace Chen70990072017-03-24 17:21:30 -07006212 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006213 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006214 Phone phone = PhoneFactory.getPhone(slotIndex);
6215
vagdeviaf9a5b92018-08-15 16:01:53 -07006216 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006218 final long identity = Binder.clearCallingIdentity();
6219 try {
6220 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006221 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222 }
6223 } finally {
6224 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006225 }
6226 }
Shuo Qiandd210312017-04-12 22:11:33 +00006227
Tyler Gunn65d45c22017-06-05 11:22:26 -07006228 private boolean isUssdApiAllowed(int subId) {
6229 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006230 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006231 if (configManager == null) {
6232 return false;
6233 }
6234 PersistableBundle pb = configManager.getConfigForSubId(subId);
6235 if (pb == null) {
6236 return false;
6237 }
6238 return pb.getBoolean(
6239 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6240 }
6241
Shuo Qiandd210312017-04-12 22:11:33 +00006242 /**
6243 * Check if phone is in emergency callback mode
6244 * @return true if phone is in emergency callback mode
6245 * @param subId sub id
6246 */
goneil9c5f4872017-12-05 14:07:56 -08006247 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006248 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006249 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006250 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251
6252 final long identity = Binder.clearCallingIdentity();
6253 try {
6254 if (phone != null) {
6255 return phone.isInEcm();
6256 } else {
6257 return false;
6258 }
6259 } finally {
6260 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006261 }
6262 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006263
6264 /**
6265 * Get the current signal strength information for the given subscription.
6266 * Because this information is not updated when the device is in a low power state
6267 * it should not be relied-upon to be current.
6268 * @param subId Subscription index
6269 * @return the most recent cached signal strength info from the modem
6270 */
6271 @Override
6272 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273 final long identity = Binder.clearCallingIdentity();
6274 try {
6275 Phone p = getPhone(subId);
6276 if (p == null) {
6277 return null;
6278 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 return p.getSignalStrength();
6281 } finally {
6282 Binder.restoreCallingIdentity(identity);
6283 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006284 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006285
Pengquan Meng77b7f132018-08-22 14:49:57 -07006286 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006287 * Get the current modem radio state for the given slot.
6288 * @param slotIndex slot index.
6289 * @param callingPackage the name of the package making the call.
6290 * @return the current radio power state from the modem
6291 */
6292 @Override
6293 public int getRadioPowerState(int slotIndex, String callingPackage) {
6294 Phone phone = PhoneFactory.getPhone(slotIndex);
6295 if (phone != null) {
6296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6297 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6298 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6299 }
6300
6301 final long identity = Binder.clearCallingIdentity();
6302 try {
6303 return phone.getRadioPowerState();
6304 } finally {
6305 Binder.restoreCallingIdentity(identity);
6306 }
6307 }
6308 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6309 }
6310
6311 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006312 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6313 *
6314 * <p>Requires one of the following permissions:
6315 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6316 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6317 * privileges.
6318 *
6319 * @param subId subscription id
6320 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6321 * {@code false}.
6322 */
6323 @Override
6324 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006325 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6326 null /* message */);
6327
Pengquan Menga1bb6272018-09-06 09:59:22 -07006328 boolean isEnabled = false;
6329 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006330 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006331 Phone phone = getPhone(subId);
6332 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006333 } catch (Exception e) {
6334 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6335 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006336 } finally {
6337 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006338 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006339 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006340 }
6341
6342
6343 /**
6344 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6345 *
6346 * <p> Requires permission:
6347 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6348 * privileges.
6349 *
6350 * @param subId subscription id
6351 * @param isEnabled {@code true} means enable, {@code false} means disable.
6352 */
6353 @Override
6354 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6356 mApp, subId, "setDataRoamingEnabled");
6357
Pengquan Menga1bb6272018-09-06 09:59:22 -07006358 final long identity = Binder.clearCallingIdentity();
6359 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006360 Phone phone = getPhone(subId);
6361 if (phone != null) {
6362 phone.setDataRoamingEnabled(isEnabled);
6363 }
6364 } finally {
6365 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006366 }
6367 }
6368
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006369 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006370 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006371 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6372 mApp, subId, "isManualNetworkSelectionAllowed");
6373
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006374 boolean isAllowed = true;
6375 final long identity = Binder.clearCallingIdentity();
6376 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006377 Phone phone = getPhone(subId);
6378 if (phone != null) {
6379 isAllowed = phone.isCspPlmnEnabled();
6380 }
6381 } finally {
6382 Binder.restoreCallingIdentity(identity);
6383 }
6384 return isAllowed;
6385 }
6386
6387 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006388 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006389 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006390 try {
6391 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006392 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006393 } catch (SecurityException e) {
6394 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6395 // has carrier privileges on an active UICC
6396 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6397 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006398 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006399 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006400 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006401
6402 final long identity = Binder.clearCallingIdentity();
6403 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006404 UiccController uiccController = UiccController.getInstance();
6405 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006406 if (hasReadPermission) {
6407 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006408 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006409
6410 // Remove private info if the caller doesn't have access
6411 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6412 for (UiccCardInfo cardInfo : cardInfos) {
6413 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6414 // is available
6415 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6416 if (card == null || card.getUiccProfile() == null) {
6417 // assume no access if the card or profile is unavailable
6418 filteredInfos.add(cardInfo.getUnprivileged());
6419 continue;
6420 }
6421 UiccProfile profile = card.getUiccProfile();
6422 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6423 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6424 filteredInfos.add(cardInfo);
6425 } else {
6426 filteredInfos.add(cardInfo.getUnprivileged());
6427 }
6428 }
6429 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006430 } finally {
6431 Binder.restoreCallingIdentity(identity);
6432 }
6433 }
6434
6435 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006436 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006437 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6442 if (slots == null) {
6443 Rlog.i(LOG_TAG, "slots is null.");
6444 return null;
6445 }
6446
6447 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6448 for (int i = 0; i < slots.length; i++) {
6449 UiccSlot slot = slots[i];
6450 if (slot == null) {
6451 continue;
6452 }
6453
Jordan Liu7be7e652019-05-06 18:55:02 +00006454 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 UiccCard card = slot.getUiccCard();
6456 if (card != null) {
6457 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006458 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459 cardId = slot.getIccId();
6460 }
6461
Jordan Liu857451f2019-05-09 16:35:35 -07006462 if (cardId != null) {
6463 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6464 // if cardId is an EID, it's all digits so this is fine
6465 cardId = IccUtils.stripTrailingFs(cardId);
6466 }
6467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468 int cardState = 0;
6469 switch (slot.getCardState()) {
6470 case CARDSTATE_ABSENT:
6471 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6472 break;
6473 case CARDSTATE_PRESENT:
6474 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6475 break;
6476 case CARDSTATE_ERROR:
6477 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6478 break;
6479 case CARDSTATE_RESTRICTED:
6480 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6481 break;
6482 default:
6483 break;
6484
6485 }
6486
6487 infos[i] = new UiccSlotInfo(
6488 slot.isActive(),
6489 slot.isEuicc(),
6490 cardId,
6491 cardState,
6492 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006493 slot.isExtendedApduSupported(),
6494 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 }
6496 return infos;
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006499 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006500 }
6501
6502 @Override
6503 public boolean switchSlots(int[] physicalSlots) {
6504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505
6506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006512 }
Jack Yu4c988042018-02-27 15:30:01 -08006513
6514 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006515 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006516 final long identity = Binder.clearCallingIdentity();
6517 try {
6518 return UiccController.getInstance().getCardIdForDefaultEuicc();
6519 } finally {
6520 Binder.restoreCallingIdentity(identity);
6521 }
6522 }
6523
6524 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006525 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6526 enforceModifyPermission();
6527 final Phone phone = getPhone(subId);
6528 if (phone == null) {
6529 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6530 return;
6531 }
6532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533 final long identity = Binder.clearCallingIdentity();
6534 try {
6535 phone.setRadioIndicationUpdateMode(filters, mode);
6536 } finally {
6537 Binder.restoreCallingIdentity(identity);
6538 }
Jack Yu4c988042018-02-27 15:30:01 -08006539 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006540
6541 /**
goneil47ffb6e2018-04-06 15:40:58 -07006542 * A test API to reload the UICC profile.
6543 *
6544 * <p>Requires that the calling app has permission
6545 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6546 * @hide
6547 */
6548 @Override
6549 public void refreshUiccProfile(int subId) {
6550 enforceModifyPermission();
6551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
6554 Phone phone = getPhone(subId);
6555 if (phone == null) {
6556 return;
6557 }
6558 UiccCard uiccCard = phone.getUiccCard();
6559 if (uiccCard == null) {
6560 return;
6561 }
6562 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6563 if (uiccProfile == null) {
6564 return;
6565 }
6566 uiccProfile.refresh();
6567 } finally {
6568 Binder.restoreCallingIdentity(identity);
6569 }
6570 }
6571
6572 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006573 * Returns false if the mobile data is disabled by default, otherwise return true.
6574 */
6575 private boolean getDefaultDataEnabled() {
6576 return "true".equalsIgnoreCase(
6577 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6578 }
6579
6580 /**
6581 * Returns true if the data roaming is enabled by default, i.e the system property
6582 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6583 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6584 */
6585 private boolean getDefaultDataRoamingEnabled(int subId) {
6586 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006587 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006588 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6589 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6590 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6591 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6592 return isDataRoamingEnabled;
6593 }
6594
6595 /**
6596 * Returns the default network type for the given {@code subId}, if the default network type is
6597 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6598 */
6599 private int getDefaultNetworkType(int subId) {
6600 return Integer.parseInt(
6601 TelephonyManager.getTelephonyProperty(
6602 mSubscriptionController.getPhoneId(subId),
6603 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6604 String.valueOf(Phone.PREFERRED_NT_MODE)));
6605 }
fionaxua13278b2018-03-21 00:08:13 -07006606
6607 @Override
6608 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006609 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006610 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611
6612 final long identity = Binder.clearCallingIdentity();
6613 try {
6614 final Phone phone = getPhone(subId);
6615 if (phone == null) {
6616 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6617 return;
6618 }
chen xueaba88a2019-03-15 13:15:10 -07006619 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6620 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 } finally {
6622 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006623 }
fionaxua13278b2018-03-21 00:08:13 -07006624 }
6625
6626 @Override
6627 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006628 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629
6630 final long identity = Binder.clearCallingIdentity();
6631 try {
6632 final Phone phone = getPhone(subId);
6633 if (phone == null) {
6634 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6635 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6636 }
6637 return phone.getCarrierIdListVersion();
6638 } finally {
6639 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006640 }
fionaxua13278b2018-03-21 00:08:13 -07006641 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006642
6643 @Override
6644 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6646 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6647 return -1;
6648 }
6649
6650 final long identity = Binder.clearCallingIdentity();
6651 try {
6652 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
6655 }
6656 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006657
6658 @Override
6659 public int getCdmaRoamingMode(int subId) {
6660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6661 mApp, subId, "getCdmaRoamingMode");
6662
6663 final long identity = Binder.clearCallingIdentity();
6664 try {
6665 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
6669 }
6670
6671 @Override
6672 public boolean setCdmaRoamingMode(int subId, int mode) {
6673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6674 mApp, subId, "setCdmaRoamingMode");
6675
6676 final long identity = Binder.clearCallingIdentity();
6677 try {
6678 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
6682 }
6683
6684 @Override
6685 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6687 mApp, subId, "setCdmaSubscriptionMode");
6688
6689 final long identity = Binder.clearCallingIdentity();
6690 try {
6691 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6692 } finally {
6693 Binder.restoreCallingIdentity(identity);
6694 }
6695 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006696
6697 private void ensureUserRunning(int userId) {
6698 if (!mUserManager.isUserRunning(userId)) {
6699 throw new IllegalStateException("User " + userId + " does not exist or not running");
6700 }
6701 }
6702
6703 /**
6704 * Returns a list of SMS apps on a given user.
6705 *
6706 * Only the shell user (UID 2000 or 0) can call it.
6707 * Target user must be running.
6708 */
6709 @Override
6710 public String[] getSmsApps(int userId) {
6711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6712 ensureUserRunning(userId);
6713
6714 final Collection<SmsApplicationData> apps =
6715 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6716
6717 String[] ret = new String[apps.size()];
6718 int i = 0;
6719 for (SmsApplicationData app : apps) {
6720 ret[i++] = app.mPackageName;
6721 }
6722 return ret;
6723 }
6724
6725 /**
6726 * Returns the default SMS app package name on a given user.
6727 *
6728 * Only the shell user (UID 2000 or 0) can call it.
6729 * Target user must be running.
6730 */
6731 @Override
6732 public String getDefaultSmsApp(int userId) {
6733 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6734 ensureUserRunning(userId);
6735
6736 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6737 /* updateIfNeeded= */ true, userId);
6738 return cn == null ? null : cn.getPackageName();
6739 }
6740
6741 /**
6742 * Set a package as the default SMS app on a given user.
6743 *
6744 * Only the shell user (UID 2000 or 0) can call it.
6745 * Target user must be running.
6746 */
6747 @Override
6748 public void setDefaultSmsApp(int userId, String packageName) {
6749 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6750 ensureUserRunning(userId);
6751
6752 boolean found = false;
6753 for (String pkg : getSmsApps(userId)) {
6754 if (TextUtils.equals(packageName, pkg)) {
6755 found = true;
6756 break;
6757 }
6758 }
6759 if (!found) {
6760 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6761 }
6762
6763 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6764 }
sqianc5eccab2018-10-19 18:46:41 -07006765
6766 @Override
sqian8c685422019-02-22 15:55:18 -08006767 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006768 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006770 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006771 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6772 }
6773 final long identity = Binder.clearCallingIdentity();
6774 try {
sqian854d44b2018-12-12 16:48:18 -08006775 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6776 for (Phone phone: PhoneFactory.getPhones()) {
6777 if (phone.getEmergencyNumberTracker() != null
6778 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6779 emergencyNumberListInternal.put(
6780 phone.getSubId(),
6781 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6782 }
sqian11b7a0e2018-12-05 18:48:28 -08006783 }
sqian854d44b2018-12-12 16:48:18 -08006784 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006785 } finally {
6786 Binder.restoreCallingIdentity(identity);
6787 }
sqianc5eccab2018-10-19 18:46:41 -07006788 }
6789
6790 @Override
sqian8c685422019-02-22 15:55:18 -08006791 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006792 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006793 if (!exactMatch) {
6794 TelephonyPermissions
6795 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006796 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006797 }
6798 final long identity = Binder.clearCallingIdentity();
6799 try {
sqian854d44b2018-12-12 16:48:18 -08006800 for (Phone phone: PhoneFactory.getPhones()) {
6801 if (phone.getEmergencyNumberTracker() != null
6802 && phone.getEmergencyNumberTracker() != null) {
6803 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6804 number, exactMatch)) {
6805 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006806 }
6807 }
sqian11b7a0e2018-12-05 18:48:28 -08006808 }
6809 return false;
6810 } finally {
6811 Binder.restoreCallingIdentity(identity);
6812 }
6813 }
6814
sqianf4ca7ed2019-01-15 18:32:07 -08006815 /**
6816 * Update emergency number list for test mode.
6817 */
6818 @Override
6819 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6820 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6821 "updateEmergencyNumberListTestMode");
6822
6823 final long identity = Binder.clearCallingIdentity();
6824 try {
6825 for (Phone phone: PhoneFactory.getPhones()) {
6826 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6827 if (tracker != null) {
6828 tracker.executeEmergencyNumberTestModeCommand(action, num);
6829 }
6830 }
6831 } finally {
6832 Binder.restoreCallingIdentity(identity);
6833 }
6834 }
6835
6836 /**
6837 * Get the full emergency number list for test mode.
6838 */
6839 @Override
6840 public List<String> getEmergencyNumberListTestMode() {
6841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6842 "getEmergencyNumberListTestMode");
6843
6844 final long identity = Binder.clearCallingIdentity();
6845 try {
6846 Set<String> emergencyNumbers = new HashSet<>();
6847 for (Phone phone: PhoneFactory.getPhones()) {
6848 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6849 if (tracker != null) {
6850 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6851 emergencyNumbers.add(num.getNumber());
6852 }
6853 }
6854 }
6855 return new ArrayList<>(emergencyNumbers);
6856 } finally {
6857 Binder.restoreCallingIdentity(identity);
6858 }
6859 }
6860
chen xud6b45bd2018-10-30 22:27:10 -07006861 @Override
6862 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6863 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6864 Phone phone = getPhone(subId);
6865 if (phone == null) {
6866 return null;
6867 }
6868 final long identity = Binder.clearCallingIdentity();
6869 try {
6870 UiccProfile profile = UiccController.getInstance()
6871 .getUiccProfileForPhone(phone.getPhoneId());
6872 if (profile != null) {
6873 return profile.getCertsFromCarrierPrivilegeAccessRules();
6874 }
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
6877 }
6878 return null;
6879 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006880
6881 /**
6882 * Enable or disable a modem stack.
6883 */
6884 @Override
6885 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6886 enforceModifyPermission();
6887
6888 final long identity = Binder.clearCallingIdentity();
6889 try {
6890 Phone phone = PhoneFactory.getPhone(slotIndex);
6891 if (phone == null) {
6892 return false;
6893 } else {
6894 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6895 }
6896 } finally {
6897 Binder.restoreCallingIdentity(identity);
6898 }
6899 }
Michelecea4cf22018-12-21 15:00:11 -08006900
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006901 /**
6902 * Whether a modem stack is enabled or not.
6903 */
6904 @Override
6905 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6906 Phone phone = PhoneFactory.getPhone(slotIndex);
6907 if (phone == null) return false;
6908
6909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6910 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6911 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6912 }
6913
6914 final long identity = Binder.clearCallingIdentity();
6915 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006916 try {
6917 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6918 } catch (NoSuchElementException ex) {
6919 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6920 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006921 } finally {
6922 Binder.restoreCallingIdentity(identity);
6923 }
6924 }
6925
Michelecea4cf22018-12-21 15:00:11 -08006926 @Override
Michele0ea7d782019-03-19 14:58:42 -07006927 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006928 enforceModifyPermission();
6929
6930 final long identity = Binder.clearCallingIdentity();
6931 try {
6932 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006933 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006934 .commit();
6935 } finally {
6936 Binder.restoreCallingIdentity(identity);
6937 }
6938 }
6939
6940 @Override
Michele0ea7d782019-03-19 14:58:42 -07006941 @TelephonyManager.IsMultiSimSupportedResult
6942 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006944 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6945 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006946 }
Michelecea4cf22018-12-21 15:00:11 -08006947
6948 final long identity = Binder.clearCallingIdentity();
6949 try {
Michele0ea7d782019-03-19 14:58:42 -07006950 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006951 } finally {
6952 Binder.restoreCallingIdentity(identity);
6953 }
6954 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006955
Michele0ea7d782019-03-19 14:58:42 -07006956 @TelephonyManager.IsMultiSimSupportedResult
6957 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006958 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6959 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6960 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006961 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6962 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006963 }
6964 // Check if the hardware supports multisim functionality. If usage of multisim is not
6965 // supported by the modem, indicate that it is restricted.
6966 PhoneCapability staticCapability =
6967 mPhoneConfigurationManager.getStaticPhoneCapability();
6968 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006969 loge("isMultiSimSupportedInternal: no static configuration available");
6970 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006971 }
6972 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006973 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6974 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006975 }
6976 // Check if support of multiple SIMs is restricted by carrier
6977 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006978 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006979 }
6980
Michele0ea7d782019-03-19 14:58:42 -07006981 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006982 }
6983
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006984 /**
6985 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006986 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6987 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6988 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006989 * @param numOfSims number of active sims we want to switch to
6990 */
6991 @Override
6992 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006993 if (numOfSims == 1) {
6994 enforceModifyPermission();
6995 } else {
6996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6997 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6998 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006999 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007000
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007001 try {
Michele30b57b22019-03-01 12:01:14 -08007002 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007003 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007004 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7005 return;
7006 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007007 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
7011 }
7012
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007013 @Override
7014 public boolean isApplicationOnUicc(int subId, int appType) {
7015 enforceReadPrivilegedPermission("isApplicationOnUicc");
7016 Phone phone = getPhone(subId);
7017 if (phone == null) {
7018 return false;
7019 }
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 UiccCard uiccCard = phone.getUiccCard();
7023 if (uiccCard == null) {
7024 return false;
7025 }
7026 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7027 if (uiccProfile == null) {
7028 return false;
7029 }
7030 if (TelephonyManager.APPTYPE_SIM <= appType
7031 && appType <= TelephonyManager.APPTYPE_ISIM) {
7032 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7033 }
7034 return false;
7035 } finally {
7036 Binder.restoreCallingIdentity(identity);
7037 }
7038 }
7039
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007040 /**
chen xub4baa772019-04-03 10:23:41 -07007041 * Get whether making changes to modem configurations will trigger reboot.
7042 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007043 */
7044 @Override
chen xub4baa772019-04-03 10:23:41 -07007045 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7047 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7048 return false;
7049 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007050 final long identity = Binder.clearCallingIdentity();
7051 try {
7052 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7053 } finally {
7054 Binder.restoreCallingIdentity(identity);
7055 }
7056 }
7057
Nathan Harold29f5f052019-02-15 13:41:57 -08007058 private void updateModemStateMetrics() {
7059 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7060 // TODO: check the state for each modem if the api is ready.
7061 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7062 }
7063
Pengquan Meng3889a572019-01-23 11:16:29 -08007064 @Override
7065 public int[] getSlotsMapping() {
7066 enforceReadPrivilegedPermission("getSlotsMapping");
7067
7068 final long identity = Binder.clearCallingIdentity();
7069 try {
7070 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7071 // All logical slots should have a mapping to a physical slot.
7072 int[] logicalSlotsMapping = new int[phoneCount];
7073 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7074 for (int i = 0; i < slotInfos.length; i++) {
7075 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7076 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7077 }
7078 }
7079 return logicalSlotsMapping;
7080 } finally {
7081 Binder.restoreCallingIdentity(identity);
7082 }
7083 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007084
7085 /**
7086 * Get the IRadio HAL Version
7087 */
7088 @Override
7089 public int getRadioHalVersion() {
7090 Phone phone = getDefaultPhone();
7091 if (phone == null) return -1;
7092 HalVersion hv = phone.getHalVersion();
7093 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7094 return hv.major * 100 + hv.minor;
7095 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007096
7097 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007098 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7099 * corresponding network requests on a subId.
7100 *
7101 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007102 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007103 * 2) APN is un-metered for this subscription, or
7104 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7105 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7106 *
7107 * @return whether data is allowed for a apn type.
7108 *
7109 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007110 */
7111 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007112 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007113 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007114 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7115 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007116 }
7117
7118 // Now that all security checks passes, perform the operation as ourselves.
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
7121 Phone phone = getPhone(subId);
7122 if (phone == null) return false;
7123
Jack Yu41407ee2019-05-13 16:54:09 -07007124 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007125 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7126 } finally {
7127 Binder.restoreCallingIdentity(identity);
7128 }
7129 }
7130
7131 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007132 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007133 enforceReadPrivilegedPermission("isApnMetered");
7134
7135 // Now that all security checks passes, perform the operation as ourselves.
7136 final long identity = Binder.clearCallingIdentity();
7137 try {
7138 Phone phone = getPhone(subId);
7139 if (phone == null) return true; // By default return true.
7140
Jack Yu41407ee2019-05-13 16:54:09 -07007141 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007142 } finally {
7143 Binder.restoreCallingIdentity(identity);
7144 }
7145 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007146
7147 @Override
7148 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7149 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7150 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7151 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7152 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7153 }
7154 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7155 Intent intent = new Intent();
7156 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7157 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7158 // Bring up choose default SMS subscription dialog right now
7159 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7160 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7161 mApp.startActivity(intent);
7162 }
chen xud5ca2d52019-05-28 15:20:57 -07007163
7164 @Override
7165 public String getMmsUAProfUrl(int subId) {
7166 //TODO investigate if this API should require proper permission check in R b/133791609
7167 final long identity = Binder.clearCallingIdentity();
7168 try {
7169 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7170 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7171 } finally {
7172 Binder.restoreCallingIdentity(identity);
7173 }
7174 }
7175
7176 @Override
7177 public String getMmsUserAgent(int subId) {
7178 //TODO investigate if this API should require proper permission check in R b/133791609
7179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7182 .getString(com.android.internal.R.string.config_mms_user_agent);
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
7185 }
7186 }
Jack Yub07d4972019-05-28 16:12:25 -07007187
7188 @Override
7189 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7190 enforceModifyPermission();
7191
7192 // Now that all security checks passes, perform the operation as ourselves.
7193 final long identity = Binder.clearCallingIdentity();
7194 try {
7195 Phone phone = getPhone(subId);
7196 if (phone == null) return false;
7197
7198 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7199 } finally {
7200 Binder.restoreCallingIdentity(identity);
7201 }
7202 }
7203
7204 @Override
7205 public boolean isDataAllowedInVoiceCall(int subId) {
7206 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7207
7208 // Now that all security checks passes, perform the operation as ourselves.
7209 final long identity = Binder.clearCallingIdentity();
7210 try {
7211 Phone phone = getPhone(subId);
7212 if (phone == null) return false;
7213
7214 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7215 } finally {
7216 Binder.restoreCallingIdentity(identity);
7217 }
7218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007219}