blob: f329150965ee0f5617cff5d485d6ea4f624676e8 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunn327a9722019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070047import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080048import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070049import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070051import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070052import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070054import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070055import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070056import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080057import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070058import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080059import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080060import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070061import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070062import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080063import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070065import android.telephony.CellInfoGsm;
66import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070067import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070069import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070070import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080071import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070072import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080073import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070074import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080075import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080076import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070077import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080078import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080081import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080082import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070084import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070085import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080087import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000088import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070089import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070091import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080092import android.telephony.data.ApnSetting;
Jack Yu40306fc2019-05-13 16:54:09 -070093import android.telephony.data.ApnSetting.ApnType;
calvinpaneed9ae82018-11-01 19:43:06 +080094import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080096import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070097import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080098import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070099import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsMmTelFeature;
101import android.telephony.ims.aidl.IImsRcsFeature;
102import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800104import android.telephony.ims.feature.MmTelFeature;
105import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800106import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800110import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800112
Brad Ebinger4c460712018-10-01 10:40:55 -0700113import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700114import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800115import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700117import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700118import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800119import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700120import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800123import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800124import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800126import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700127import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100128import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700129import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700132import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800133import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700134import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700135import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700136import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700137import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700138import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800140import com.android.internal.telephony.SmsApplication;
141import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajan716e76c2019-05-13 13:48:32 -0700142import com.android.internal.telephony.SmsController;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800143import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800144import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chen460810d2019-04-10 18:25:07 -0700145import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqian9d4df8b2019-01-15 18:32:07 -0800146import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700147import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800148import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800149import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.uicc.IccIoResult;
151import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800152import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700153import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800154import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800156import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000157import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700158import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800159import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700160import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800161import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700162import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700163import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800164
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700165import java.io.FileDescriptor;
166import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800168import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800169import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800170import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800171import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800172import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100173import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import java.util.Map;
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -0700175import java.util.NoSuchElementException;
sqian9d4df8b2019-01-15 18:32:07 -0800176import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177
178/**
179 * Implementation of the ITelephony interface.
180 */
Santos Cordon117fee72014-05-16 17:56:12 -0700181public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182 private static final String LOG_TAG = "PhoneInterfaceManager";
183 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
184 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187 // Message codes used with mMainThreadHandler
188 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700189 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
190 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191 private static final int CMD_OPEN_CHANNEL = 9;
192 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
193 private static final int CMD_CLOSE_CHANNEL = 11;
194 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800195 private static final int CMD_NV_READ_ITEM = 13;
196 private static final int EVENT_NV_READ_ITEM_DONE = 14;
197 private static final int CMD_NV_WRITE_ITEM = 15;
198 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
199 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
200 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700201 private static final int CMD_RESET_MODEM_CONFIG = 19;
202 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800203 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
204 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
205 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
206 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800207 private static final int CMD_SEND_ENVELOPE = 25;
208 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000209 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
210 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700211 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
212 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
213 private static final int CMD_EXCHANGE_SIM_IO = 31;
214 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800215 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
216 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700217 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
218 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700219 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
220 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700221 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
222 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
223 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
224 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700225 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
226 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
227 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
228 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700229 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800230 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
231 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000232 private static final int CMD_SWITCH_SLOTS = 50;
233 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700234 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
235 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
236 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
237 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
238 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
239 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
240 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
241 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700242 private static final int CMD_GET_ALL_CELL_INFO = 60;
243 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
244 private static final int CMD_GET_CELL_LOCATION = 62;
245 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700246 private static final int CMD_MODEM_REBOOT = 64;
247 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700248 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
249 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800250 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
251 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -0700252 private static final int CMD_GET_MODEM_STATUS = 70;
253 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800255 // Parameters of select command.
256 private static final int SELECT_COMMAND = 0xA4;
257 private static final int SELECT_P1 = 0x04;
258 private static final int SELECT_P2 = 0;
259 private static final int SELECT_P3 = 0x10;
260
Pengquan Meng85728fb2018-03-12 16:31:21 -0700261 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
262 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
263 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
264
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265 /** The singleton instance. */
266 private static PhoneInterfaceManager sInstance;
267
Wink Saville3ab207e2014-11-20 13:07:20 -0800268 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800269 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700270 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800271 private AppOpsManager mAppOps;
272 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800273 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800274 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700275 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276
Derek Tan97ebb422014-09-05 16:55:38 -0700277 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
278 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800279 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800280 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700281
Micheled3107c52018-12-21 15:00:11 -0800282 // String to store multi SIM allowed
283 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
284
Derek Tan740e1672017-06-27 14:56:27 -0700285 // The AID of ISD-R.
286 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
287
yinxub1bed742017-04-17 11:45:04 -0700288 private NetworkScanRequestTracker mNetworkScanRequestTracker;
289
David Kelly5e06a7f2018-03-12 14:10:59 +0000290 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
291 private static final int MANUFACTURER_CODE_LENGTH = 8;
292
Derek Tan89e89d42014-07-08 17:00:10 -0700293 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700294 * A request object to use for transmitting data to an ICC.
295 */
296 private static final class IccAPDUArgument {
297 public int channel, cla, command, p1, p2, p3;
298 public String data;
299
300 public IccAPDUArgument(int channel, int cla, int command,
301 int p1, int p2, int p3, String data) {
302 this.channel = channel;
303 this.cla = cla;
304 this.command = command;
305 this.p1 = p1;
306 this.p2 = p2;
307 this.p3 = p3;
308 this.data = data;
309 }
310 }
311
312 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700313 * A request object to use for transmitting data to an ICC.
314 */
315 private static final class ManualNetworkSelectionArgument {
316 public OperatorInfo operatorInfo;
317 public boolean persistSelection;
318
319 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
320 this.operatorInfo = operatorInfo;
321 this.persistSelection = persistSelection;
322 }
323 }
324
325 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
327 * request after sending. The main thread will notify the request when it is complete.
328 */
329 private static final class MainThreadRequest {
330 /** The argument to use for the request */
331 public Object argument;
332 /** The result of the request that is run on the main thread */
333 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800334 // The subscriber id that this request applies to. Defaults to
335 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
336 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337
Nathan Harold92bed182018-10-12 18:16:49 -0700338 // In cases where subId is unavailable, the caller needs to specify the phone.
339 public Phone phone;
340
vagdevie435a3e2018-08-15 16:01:53 -0700341 public WorkSource workSource;
342
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 public MainThreadRequest(Object argument) {
344 this.argument = argument;
345 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800346
Nathan Harold92bed182018-10-12 18:16:49 -0700347 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
348 this.argument = argument;
349 if (phone != null) {
350 this.phone = phone;
351 }
352 this.workSource = workSource;
353 }
354
vagdevie435a3e2018-08-15 16:01:53 -0700355 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800356 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800357 if (subId != null) {
358 this.subId = subId;
359 }
vagdevie435a3e2018-08-15 16:01:53 -0700360 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 }
363
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800364 private static final class IncomingThirdPartyCallArgs {
365 public final ComponentName component;
366 public final String callId;
367 public final String callerDisplayName;
368
369 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
370 String callerDisplayName) {
371 this.component = component;
372 this.callId = callId;
373 this.callerDisplayName = callerDisplayName;
374 }
375 }
376
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 /**
378 * A handler that processes messages on the main thread in the phone process. Since many
379 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
380 * inbound binder threads to the main thread in the phone process. The Binder thread
381 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
382 * on, which will be notified when the operation completes and will contain the result of the
383 * request.
384 *
385 * <p>If a MainThreadRequest object is provided in the msg.obj field,
386 * note that request.result must be set to something non-null for the calling thread to
387 * unblock.
388 */
389 private final class MainThreadHandler extends Handler {
390 @Override
391 public void handleMessage(Message msg) {
392 MainThreadRequest request;
393 Message onCompleted;
394 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800395 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700396 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800397 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398
399 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700400 case CMD_HANDLE_USSD_REQUEST: {
401 request = (MainThreadRequest) msg.obj;
402 final Phone phone = getPhoneFromRequest(request);
403 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
404 String ussdRequest = ussdObject.first;
405 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700406
Pengquan Meng0c05b502018-09-06 09:59:22 -0700407 if (!isUssdApiAllowed(request.subId)) {
408 // Carrier does not support use of this API, return failure.
409 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
410 UssdResponse response = new UssdResponse(ussdRequest, null);
411 Bundle returnData = new Bundle();
412 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
413 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700414
Pengquan Meng0c05b502018-09-06 09:59:22 -0700415 request.result = true;
416 notifyRequester(request);
417 return;
418 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700419
Pengquan Meng0c05b502018-09-06 09:59:22 -0700420 try {
421 request.result = phone != null
422 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
423 } catch (CallStateException cse) {
424 request.result = false;
425 }
426 // Wake up the requesting thread
427 notifyRequester(request);
428 break;
pkanwar32d516d2016-10-14 19:37:38 -0700429 }
430
Yorke Lee716f67e2015-06-17 15:39:16 -0700431 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700433 final Phone phone = getPhoneFromRequest(request);
434 request.result = phone != null ?
435 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
436 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700438 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800445 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700446 if (uiccCard == null) {
447 loge("iccTransmitApduLogicalChannel: No UICC");
448 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700449 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
452 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 iccArgument.channel, iccArgument.cla, iccArgument.command,
455 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 break;
459
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 ar = (AsyncResult) msg.obj;
462 request = (MainThreadRequest) ar.userObj;
463 if (ar.exception == null && ar.result != null) {
464 request.result = ar.result;
465 } else {
466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
467 if (ar.result == null) {
468 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800469 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700470 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800471 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 } else {
473 loge("iccTransmitApduLogicalChannel: Unknown exception");
474 }
475 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700476 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 break;
478
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
480 request = (MainThreadRequest) msg.obj;
481 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800482 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 if (uiccCard == null) {
484 loge("iccTransmitApduBasicChannel: No UICC");
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700486 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 } else {
488 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
489 request);
490 uiccCard.iccTransmitApduBasicChannel(
491 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
492 iccArgument.p3, iccArgument.data, onCompleted);
493 }
494 break;
495
496 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
497 ar = (AsyncResult) msg.obj;
498 request = (MainThreadRequest) ar.userObj;
499 if (ar.exception == null && ar.result != null) {
500 request.result = ar.result;
501 } else {
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
503 if (ar.result == null) {
504 loge("iccTransmitApduBasicChannel: Empty response");
505 } else if (ar.exception instanceof CommandException) {
506 loge("iccTransmitApduBasicChannel: CommandException: " +
507 ar.exception);
508 } else {
509 loge("iccTransmitApduBasicChannel: Unknown exception");
510 }
511 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 break;
514
515 case CMD_EXCHANGE_SIM_IO:
516 request = (MainThreadRequest) msg.obj;
517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 if (uiccCard == null) {
520 loge("iccExchangeSimIO: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 } else {
524 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
525 request);
526 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
527 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
528 iccArgument.data, onCompleted);
529 }
530 break;
531
532 case EVENT_EXCHANGE_SIM_IO_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
537 } else {
538 request.result = new IccIoResult(0x6f, 0, (byte[])null);
539 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 break;
542
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 case CMD_SEND_ENVELOPE:
544 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800545 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 if (uiccCard == null) {
547 loge("sendEnvelopeWithStatus: No UICC");
548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700549 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 } else {
551 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
552 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
553 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 break;
555
556 case EVENT_SEND_ENVELOPE_DONE:
557 ar = (AsyncResult) msg.obj;
558 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700559 if (ar.exception == null && ar.result != null) {
560 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700562 request.result = new IccIoResult(0x6F, 0, (byte[])null);
563 if (ar.result == null) {
564 loge("sendEnvelopeWithStatus: Empty response");
565 } else if (ar.exception instanceof CommandException) {
566 loge("sendEnvelopeWithStatus: CommandException: " +
567 ar.exception);
568 } else {
569 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
570 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700572 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800573 break;
574
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 case CMD_OPEN_CHANNEL:
576 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800577 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800578 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800581 request.result = new IccOpenLogicalChannelResponse(-1,
582 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 } else {
585 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800586 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
587 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
591 case EVENT_OPEN_CHANNEL_DONE:
592 ar = (AsyncResult) msg.obj;
593 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 int[] result = (int[]) ar.result;
597 int channelId = result[0];
598 byte[] selectResponse = null;
599 if (result.length > 1) {
600 selectResponse = new byte[result.length - 1];
601 for (int i = 1; i < result.length; ++i) {
602 selectResponse[i - 1] = (byte) result[i];
603 }
604 }
605 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 if (ar.result == null) {
609 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 if (ar.exception != null) {
612 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
613 }
614
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700616 if (ar.exception instanceof CommandException) {
617 CommandException.Error error =
618 ((CommandException) (ar.exception)).getCommandError();
619 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700620 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700621 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(
626 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700628 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 break;
631
632 case CMD_CLOSE_CHANNEL:
633 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800634 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 if (uiccCard == null) {
636 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900637 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 } else {
640 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
641 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
642 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 break;
644
645 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800646 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
647 break;
648
649 case CMD_NV_READ_ITEM:
650 request = (MainThreadRequest) msg.obj;
651 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800652 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
653 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800654 break;
655
656 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 ar = (AsyncResult) msg.obj;
658 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800659 if (ar.exception == null && ar.result != null) {
660 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800662 request.result = "";
663 if (ar.result == null) {
664 loge("nvReadItem: Empty response");
665 } else if (ar.exception instanceof CommandException) {
666 loge("nvReadItem: CommandException: " +
667 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800669 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 }
671 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 break;
674
Jake Hambye994d462014-02-03 13:10:13 -0800675 case CMD_NV_WRITE_ITEM:
676 request = (MainThreadRequest) msg.obj;
677 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
678 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800679 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700680 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800681 break;
682
683 case EVENT_NV_WRITE_ITEM_DONE:
684 handleNullReturnEvent(msg, "nvWriteItem");
685 break;
686
687 case CMD_NV_WRITE_CDMA_PRL:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800690 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
693 case EVENT_NV_WRITE_CDMA_PRL_DONE:
694 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
695 break;
696
chen xu1cc0abe2018-10-26 17:39:23 -0700697 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800698 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700699 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800700 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
chen xu1cc0abe2018-10-26 17:39:23 -0700703 case EVENT_RESET_MODEM_CONFIG_DONE:
704 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
Jake Hamby7c27be32014-03-03 13:25:59 -0800707 case CMD_GET_PREFERRED_NETWORK_TYPE:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700710 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 break;
712
713 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
714 ar = (AsyncResult) msg.obj;
715 request = (MainThreadRequest) ar.userObj;
716 if (ar.exception == null && ar.result != null) {
717 request.result = ar.result; // Integer
718 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800719 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 if (ar.result == null) {
721 loge("getPreferredNetworkType: Empty response");
722 } else if (ar.exception instanceof CommandException) {
723 loge("getPreferredNetworkType: CommandException: " +
724 ar.exception);
725 } else {
726 loge("getPreferredNetworkType: Unknown exception");
727 }
728 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700729 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case CMD_SET_PREFERRED_NETWORK_TYPE:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
735 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700736 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 break;
738
739 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
740 handleNullReturnEvent(msg, "setPreferredNetworkType");
741 break;
742
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000743 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
744 request = (MainThreadRequest)msg.obj;
745 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800746 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 break;
748
749 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
750 ar = (AsyncResult)msg.obj;
751 request = (MainThreadRequest)ar.userObj;
752 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700753 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 break;
755
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800756 case CMD_SET_VOICEMAIL_NUMBER:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
759 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800760 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
761 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800762 break;
763
764 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
765 handleNullReturnEvent(msg, "setVoicemailNumber");
766 break;
767
Stuart Scott54788802015-03-30 13:18:01 -0700768 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
771 request);
772 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
773 break;
774
775 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
776 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
777 break;
778
Shishir Agrawal302c8692015-06-19 13:49:39 -0700779 case CMD_PERFORM_NETWORK_SCAN:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
782 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
783 break;
784
785 case EVENT_PERFORM_NETWORK_SCAN_DONE:
786 ar = (AsyncResult) msg.obj;
787 request = (MainThreadRequest) ar.userObj;
788 CellNetworkScanResult cellScanResult;
789 if (ar.exception == null && ar.result != null) {
790 cellScanResult = new CellNetworkScanResult(
791 CellNetworkScanResult.STATUS_SUCCESS,
792 (List<OperatorInfo>) ar.result);
793 } else {
794 if (ar.result == null) {
795 loge("getCellNetworkScanResults: Empty response");
796 }
797 if (ar.exception != null) {
798 loge("getCellNetworkScanResults: Exception: " + ar.exception);
799 }
800 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
801 if (ar.exception instanceof CommandException) {
802 CommandException.Error error =
803 ((CommandException) (ar.exception)).getCommandError();
804 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
805 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
806 } else if (error == CommandException.Error.GENERIC_FAILURE) {
807 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
808 }
809 }
810 cellScanResult = new CellNetworkScanResult(errorCode, null);
811 }
812 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700813 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700814 break;
815
816 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
817 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700818 ManualNetworkSelectionArgument selArg =
819 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700820 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
821 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700822 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
823 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 break;
825
826 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700827 ar = (AsyncResult) msg.obj;
828 request = (MainThreadRequest) ar.userObj;
829 if (ar.exception == null) {
830 request.result = true;
831 } else {
832 request.result = false;
833 loge("setNetworkSelectionModeManual " + ar.exception);
834 }
835 notifyRequester(request);
836 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 break;
838
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 case CMD_GET_MODEM_ACTIVITY_INFO:
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisc56281c2019-04-03 14:18:34 -0700842 if (defaultPhone != null) {
843 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
844 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700845 break;
846
847 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
850 if (ar.exception == null && ar.result != null) {
851 request.result = ar.result;
852 } else {
853 if (ar.result == null) {
854 loge("queryModemActivityInfo: Empty response");
855 } else if (ar.exception instanceof CommandException) {
856 loge("queryModemActivityInfo: CommandException: " +
857 ar.exception);
858 } else {
859 loge("queryModemActivityInfo: Unknown exception");
860 }
861 }
Amit Mahajand4766222016-01-28 15:28:28 -0800862 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
863 if (request.result == null) {
864 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
865 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700866 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700867 break;
868
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 case CMD_SET_ALLOWED_CARRIERS:
870 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800871 CarrierRestrictionRules argument =
872 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800874 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 break;
876
877 case EVENT_SET_ALLOWED_CARRIERS_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result;
882 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800883 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
884 if (ar.exception instanceof CommandException) {
885 loge("setAllowedCarriers: CommandException: " + ar.exception);
886 CommandException.Error error =
887 ((CommandException) (ar.exception)).getCommandError();
888 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
889 request.result =
890 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
891 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 } else {
893 loge("setAllowedCarriers: Unknown exception");
894 }
895 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700896 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 break;
898
899 case CMD_GET_ALLOWED_CARRIERS:
900 request = (MainThreadRequest) msg.obj;
901 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800902 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 break;
904
905 case EVENT_GET_ALLOWED_CARRIERS_DONE:
906 ar = (AsyncResult) msg.obj;
907 request = (MainThreadRequest) ar.userObj;
908 if (ar.exception == null && ar.result != null) {
909 request.result = ar.result;
910 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800911 request.result = new IllegalStateException(
912 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 if (ar.result == null) {
914 loge("getAllowedCarriers: Empty response");
915 } else if (ar.exception instanceof CommandException) {
916 loge("getAllowedCarriers: CommandException: " +
917 ar.exception);
918 } else {
919 loge("getAllowedCarriers: Unknown exception");
920 }
921 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700922 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 break;
924
Nathan Haroldb3014052017-01-25 15:57:32 -0800925 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result;
930 } else {
931 request.result = new IllegalArgumentException(
932 "Failed to retrieve Forbidden Plmns");
933 if (ar.result == null) {
934 loge("getForbiddenPlmns: Empty response");
935 } else {
936 loge("getForbiddenPlmns: Unknown exception");
937 }
938 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700939 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800940 break;
941
942 case CMD_GET_FORBIDDEN_PLMNS:
943 request = (MainThreadRequest) msg.obj;
944 uiccCard = getUiccCardFromRequest(request);
945 if (uiccCard == null) {
946 loge("getForbiddenPlmns() UiccCard is null");
947 request.result = new IllegalArgumentException(
948 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700949 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800950 break;
951 }
952 Integer appType = (Integer) request.argument;
953 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
954 if (uiccApp == null) {
955 loge("getForbiddenPlmns() no app with specified type -- "
956 + appType);
957 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700958 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800959 break;
960 } else {
961 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
962 + " specified type -- " + appType);
963 }
964 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
965 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
966 onCompleted);
967 break;
968
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000969 case CMD_SWITCH_SLOTS:
970 request = (MainThreadRequest) msg.obj;
971 int[] physicalSlots = (int[]) request.argument;
972 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
973 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
974 break;
975
976 case EVENT_SWITCH_SLOTS_DONE:
977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
979 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700980 notifyRequester(request);
981 break;
982 case CMD_GET_NETWORK_SELECTION_MODE:
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
985 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
986 break;
987
988 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
991 if (ar.exception != null) {
992 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
993 } else {
994 int mode = ((int[]) ar.result)[0];
995 if (mode == 0) {
996 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
997 } else {
998 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
999 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001000 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001001 notifyRequester(request);
1002 break;
1003 case CMD_GET_CDMA_ROAMING_MODE:
1004 request = (MainThreadRequest) msg.obj;
1005 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1006 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1007 break;
1008 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 if (ar.exception != null) {
1012 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1013 } else {
1014 request.result = ((int[]) ar.result)[0];
1015 }
1016 notifyRequester(request);
1017 break;
1018 case CMD_SET_CDMA_ROAMING_MODE:
1019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1021 int mode = (int) request.argument;
1022 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1023 break;
1024 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 request.result = ar.exception == null;
1028 notifyRequester(request);
1029 break;
1030 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1031 request = (MainThreadRequest) msg.obj;
1032 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1033 int subscriptionMode = (int) request.argument;
1034 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1035 break;
1036 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 request.result = ar.exception == null;
1040 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001041 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001042 case CMD_GET_ALL_CELL_INFO:
1043 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001044 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001045 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 case EVENT_GET_ALL_CELL_INFO_DONE:
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001050 // If a timeout occurs, the response will be null
1051 request.result = (ar.exception == null && ar.result != null)
1052 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 synchronized (request) {
1054 request.notifyAll();
1055 }
1056 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001057 case CMD_REQUEST_CELL_INFO_UPDATE:
1058 request = (MainThreadRequest) msg.obj;
1059 request.phone.requestCellInfoUpdate(request.workSource,
1060 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1061 break;
1062 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
1065 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1066 try {
1067 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001069 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1070 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001071 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001073 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 } else {
1075 // use the result as returned
1076 cb.onCellInfo((List<CellInfo>) ar.result);
1077 }
1078 } catch (RemoteException re) {
1079 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1080 }
1081 break;
1082 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 request = (MainThreadRequest) msg.obj;
1084 WorkSource ws = (WorkSource) request.argument;
1085 Phone phone = getPhoneFromRequest(request);
1086 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1087 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
1091 if (ar.exception == null) {
1092 request.result = ar.result;
1093 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001095 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1096 ? new CdmaCellLocation() : new GsmCellLocation();
1097 }
1098
1099 synchronized (request) {
1100 request.notifyAll();
1101 }
1102 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001103 case CMD_MODEM_REBOOT:
1104 request = (MainThreadRequest) msg.obj;
1105 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001106 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001107 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001108 case EVENT_CMD_MODEM_REBOOT_DONE:
1109 handleNullReturnEvent(msg, "rebootModem");
1110 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001111 case CMD_REQUEST_ENABLE_MODEM:
1112 request = (MainThreadRequest) msg.obj;
1113 boolean enable = (boolean) request.argument;
1114 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001115 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001116 PhoneConfigurationManager.getInstance()
1117 .enablePhone(request.phone, enable, onCompleted);
1118 break;
1119 case EVENT_ENABLE_MODEM_DONE:
1120 ar = (AsyncResult) msg.obj;
1121 request = (MainThreadRequest) ar.userObj;
1122 request.result = (ar.exception == null);
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07001123 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001124 //update the cache as modem status has changed
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07001125 if ((boolean) request.result) {
1126 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1127 updateModemStateMetrics();
1128 } else {
1129 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1130 + ar.exception);
1131 }
1132 notifyRequester(request);
1133 break;
1134 case CMD_GET_MODEM_STATUS:
1135 request = (MainThreadRequest) msg.obj;
1136 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1137 PhoneConfigurationManager.getInstance()
1138 .getPhoneStatusFromModem(request.phone, onCompleted);
1139 break;
1140 case EVENT_GET_MODEM_STATUS_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 int id = request.phone.getPhoneId();
1144 if (ar.exception == null && ar.result != null) {
1145 request.result = ar.result;
1146 //update the cache as modem status has changed
1147 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1148 (boolean) request.result);
1149 } else {
1150 // Return true if modem status cannot be retrieved. For most cases,
1151 // modem status is on. And for older version modems, GET_MODEM_STATUS
1152 // and disable modem are not supported. Modem is always on.
1153 // TODO: this should be fixed in R to support a third
1154 // status UNKNOWN b/131631629
1155 request.result = true;
1156 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1157 + ar.exception);
1158 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08001159 notifyRequester(request);
1160 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001161 default:
1162 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1163 break;
1164 }
1165 }
Jake Hambye994d462014-02-03 13:10:13 -08001166
Pengquan Meng0c05b502018-09-06 09:59:22 -07001167 private void notifyRequester(MainThreadRequest request) {
1168 synchronized (request) {
1169 request.notifyAll();
1170 }
1171 }
1172
Jake Hambye994d462014-02-03 13:10:13 -08001173 private void handleNullReturnEvent(Message msg, String command) {
1174 AsyncResult ar = (AsyncResult) msg.obj;
1175 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1176 if (ar.exception == null) {
1177 request.result = true;
1178 } else {
1179 request.result = false;
1180 if (ar.exception instanceof CommandException) {
1181 loge(command + ": CommandException: " + ar.exception);
1182 } else {
1183 loge(command + ": Unknown exception");
1184 }
1185 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001186 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 }
1189
1190 /**
1191 * Posts the specified command to be executed on the main thread,
1192 * waits for the request to complete, and returns the result.
1193 * @see #sendRequestAsync
1194 */
1195 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001196 return sendRequest(
1197 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001198 }
1199
1200 /**
1201 * Posts the specified command to be executed on the main thread,
1202 * waits for the request to complete, and returns the result.
1203 * @see #sendRequestAsync
1204 */
1205 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1206 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001207 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001208 }
1209
1210 /**
1211 * Posts the specified command to be executed on the main thread,
1212 * waits for the request to complete, and returns the result.
1213 * @see #sendRequestAsync
1214 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001215 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001216 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001217 }
1218
1219 /**
1220 * Posts the specified command to be executed on the main thread,
1221 * waits for the request to complete, and returns the result.
1222 * @see #sendRequestAsync
1223 */
Nathan Harold92bed182018-10-12 18:16:49 -07001224 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1225 return sendRequest(command, argument, subId, null, workSource);
1226 }
1227
1228 /**
1229 * Posts the specified command to be executed on the main thread,
1230 * waits for the request to complete, and returns the result.
1231 * @see #sendRequestAsync
1232 */
1233 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1234 return sendRequest(
1235 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1236 }
1237
1238 /**
1239 * Posts the specified command to be executed on the main thread,
1240 * waits for the request to complete, and returns the result.
1241 * @see #sendRequestAsync
1242 */
1243 private Object sendRequest(
1244 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1246 throw new RuntimeException("This method will deadlock if called from the main thread.");
1247 }
1248
Nathan Harold92bed182018-10-12 18:16:49 -07001249 MainThreadRequest request = null;
1250 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1251 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1252 } else if (phone != null) {
1253 request = new MainThreadRequest(argument, phone, workSource);
1254 } else {
1255 request = new MainThreadRequest(argument, subId, workSource);
1256 }
1257
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 Message msg = mMainThreadHandler.obtainMessage(command, request);
1259 msg.sendToTarget();
1260
1261 // Wait for the request to complete
1262 synchronized (request) {
1263 while (request.result == null) {
1264 try {
1265 request.wait();
1266 } catch (InterruptedException e) {
1267 // Do nothing, go back and wait until the request is complete
1268 }
1269 }
1270 }
1271 return request.result;
1272 }
1273
1274 /**
1275 * Asynchronous ("fire and forget") version of sendRequest():
1276 * Posts the specified command to be executed on the main thread, and
1277 * returns immediately.
1278 * @see #sendRequest
1279 */
1280 private void sendRequestAsync(int command) {
1281 mMainThreadHandler.sendEmptyMessage(command);
1282 }
1283
1284 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001285 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001286 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001287 */
1288 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 sendRequestAsync(command, argument, null, null);
1290 }
1291
1292 /**
1293 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1294 * @see {@link #sendRequest(int,Object)}
1295 */
1296 private void sendRequestAsync(
1297 int command, Object argument, Phone phone, WorkSource workSource) {
1298 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001299 Message msg = mMainThreadHandler.obtainMessage(command, request);
1300 msg.sendToTarget();
1301 }
1302
1303 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 * Initialize the singleton PhoneInterfaceManager instance.
1305 * This is only done once, at startup, from PhoneApp.onCreate().
1306 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001307 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 synchronized (PhoneInterfaceManager.class) {
1309 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001310 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 } else {
1312 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1313 }
1314 return sInstance;
1315 }
1316 }
1317
1318 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001319 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001322 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1324 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001325 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001326 mTelephonySharedPreferences =
1327 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001328 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001329 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 publish();
1332 }
1333
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001334 private Phone getDefaultPhone() {
1335 Phone thePhone = getPhone(getDefaultSubscription());
1336 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1337 }
1338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 private void publish() {
1340 if (DBG) log("publish: " + this);
1341
1342 ServiceManager.addService("phone", this);
1343 }
1344
Stuart Scott584921c2015-01-15 17:10:34 -08001345 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001346 if (request.phone != null) {
1347 return request.phone;
1348 } else {
1349 return getPhoneFromSubId(request.subId);
1350 }
1351 }
1352
1353 private Phone getPhoneFromSubId(int subId) {
1354 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1355 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001356 }
1357
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001358 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1359 Phone phone = getPhoneFromRequest(request);
1360 return phone == null ? null :
1361 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1362 }
1363
Wink Saville36469e72014-06-11 15:17:00 -07001364 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001365 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001366 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368
1369 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001370 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
1372
Wink Savilleb564aae2014-10-23 10:18:09 -07001373 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 if (DBG) log("dial: " + number);
1375 // No permission check needed here: This is just a wrapper around the
1376 // ACTION_DIAL intent, which is available to any app since it puts up
1377 // the UI before it does anything.
1378
Malcolm Chend965c8b2018-02-28 15:00:40 -08001379 final long identity = Binder.clearCallingIdentity();
1380 try {
1381 String url = createTelUrl(number);
1382 if (url == null) {
1383 return;
1384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385
Malcolm Chend965c8b2018-02-28 15:00:40 -08001386 // PENDING: should we just silently fail if phone is offhook or ringing?
1387 PhoneConstants.State state = mCM.getState(subId);
1388 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1389 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1390 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1391 mApp.startActivity(intent);
1392 }
1393 } finally {
1394 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 }
1396 }
1397
1398 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001400 }
1401
Wink Savilleb564aae2014-10-23 10:18:09 -07001402 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 if (DBG) log("call: " + number);
1404
1405 // This is just a wrapper around the ACTION_CALL intent, but we still
1406 // need to do a permission check since we're calling startActivity()
1407 // from the context of the phone app.
1408 enforceCallPermission();
1409
1410 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1411 != AppOpsManager.MODE_ALLOWED) {
1412 return;
1413 }
1414
Malcolm Chend965c8b2018-02-28 15:00:40 -08001415 final long identity = Binder.clearCallingIdentity();
1416 try {
1417 String url = createTelUrl(number);
1418 if (url == null) {
1419 return;
1420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421
Malcolm Chend965c8b2018-02-28 15:00:40 -08001422 boolean isValid = false;
1423 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1424 if (slist != null) {
1425 for (SubscriptionInfo subInfoRecord : slist) {
1426 if (subInfoRecord.getSubscriptionId() == subId) {
1427 isValid = true;
1428 break;
1429 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001430 }
Wink Saville08874612014-08-31 19:19:58 -07001431 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001432 if (!isValid) {
1433 return;
1434 }
Wink Saville08874612014-08-31 19:19:58 -07001435
Malcolm Chend965c8b2018-02-28 15:00:40 -08001436 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1437 intent.putExtra(SUBSCRIPTION_KEY, subId);
1438 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1439 mApp.startActivity(intent);
1440 } finally {
1441 Binder.restoreCallingIdentity(identity);
1442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 }
1444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001446 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001447 }
1448
Wink Savilleb564aae2014-10-23 10:18:09 -07001449 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001450 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001451 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1452 }
1453
1454 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001459 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001460 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1461 }
1462
1463 /** {@hide} */
1464 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001465 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001466 }
1467
Wink Savilleb564aae2014-10-23 10:18:09 -07001468 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001470
1471 final long identity = Binder.clearCallingIdentity();
1472 try {
1473 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1474 checkSimPin.start();
1475 return checkSimPin.unlockSim(null, pin);
1476 } finally {
1477 Binder.restoreCallingIdentity(identity);
1478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480
Wink Saville9de0f752013-10-22 19:04:03 -07001481 /** {@hide} */
1482 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001483 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
Wink Savilleb564aae2014-10-23 10:18:09 -07001486 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001488
1489 final long identity = Binder.clearCallingIdentity();
1490 try {
1491 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1492 checkSimPuk.start();
1493 return checkSimPuk.unlockSim(puk, pin);
1494 } finally {
1495 Binder.restoreCallingIdentity(identity);
1496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 }
1498
1499 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001500 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 * a synchronous one.
1502 */
1503 private static class UnlockSim extends Thread {
1504
1505 private final IccCard mSimCard;
1506
1507 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001508 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1509 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510
1511 // For replies from SimCard interface
1512 private Handler mHandler;
1513
1514 // For async handler to identify request type
1515 private static final int SUPPLY_PIN_COMPLETE = 100;
1516
1517 public UnlockSim(IccCard simCard) {
1518 mSimCard = simCard;
1519 }
1520
1521 @Override
1522 public void run() {
1523 Looper.prepare();
1524 synchronized (UnlockSim.this) {
1525 mHandler = new Handler() {
1526 @Override
1527 public void handleMessage(Message msg) {
1528 AsyncResult ar = (AsyncResult) msg.obj;
1529 switch (msg.what) {
1530 case SUPPLY_PIN_COMPLETE:
1531 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1532 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001533 mRetryCount = msg.arg1;
1534 if (ar.exception != null) {
1535 if (ar.exception instanceof CommandException &&
1536 ((CommandException)(ar.exception)).getCommandError()
1537 == CommandException.Error.PASSWORD_INCORRECT) {
1538 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1539 } else {
1540 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1541 }
1542 } else {
1543 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 mDone = true;
1546 UnlockSim.this.notifyAll();
1547 }
1548 break;
1549 }
1550 }
1551 };
1552 UnlockSim.this.notifyAll();
1553 }
1554 Looper.loop();
1555 }
1556
1557 /*
1558 * Use PIN or PUK to unlock SIM card
1559 *
1560 * If PUK is null, unlock SIM card with PIN
1561 *
1562 * If PUK is not null, unlock SIM card with PUK and set PIN code
1563 */
Wink Saville9de0f752013-10-22 19:04:03 -07001564 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565
1566 while (mHandler == null) {
1567 try {
1568 wait();
1569 } catch (InterruptedException e) {
1570 Thread.currentThread().interrupt();
1571 }
1572 }
1573 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1574
1575 if (puk == null) {
1576 mSimCard.supplyPin(pin, callback);
1577 } else {
1578 mSimCard.supplyPuk(puk, pin, callback);
1579 }
1580
1581 while (!mDone) {
1582 try {
1583 Log.d(LOG_TAG, "wait for done");
1584 wait();
1585 } catch (InterruptedException e) {
1586 // Restore the interrupted status
1587 Thread.currentThread().interrupt();
1588 }
1589 }
1590 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001591 int[] resultArray = new int[2];
1592 resultArray[0] = mResult;
1593 resultArray[1] = mRetryCount;
1594 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 }
1596 }
1597
1598 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001599 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001600
1601 }
1602
Wink Savilleb564aae2014-10-23 10:18:09 -07001603 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 // No permission check needed here: this call is harmless, and it's
1605 // needed for the ServiceState.requestStateUpdate() call (which is
1606 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001607 final long identity = Binder.clearCallingIdentity();
1608 try {
1609 final Phone phone = getPhone(subId);
1610 if (phone != null) {
1611 phone.updateServiceLocation();
1612 }
1613 } finally {
1614 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 }
1617
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001618 @Override
1619 public boolean isRadioOn(String callingPackage) {
1620 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001621 }
1622
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001623 @Override
1624 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001626 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001627 return false;
1628 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001629
1630 final long identity = Binder.clearCallingIdentity();
1631 try {
1632 return isRadioOnForSubscriber(subId);
1633 } finally {
1634 Binder.restoreCallingIdentity(identity);
1635 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001636 }
1637
1638 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001639 final long identity = Binder.clearCallingIdentity();
1640 try {
1641 final Phone phone = getPhone(subId);
1642 if (phone != null) {
1643 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1644 } else {
1645 return false;
1646 }
1647 } finally {
1648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651
1652 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001653 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 }
Wink Saville36469e72014-06-11 15:17:00 -07001655
Wink Savilleb564aae2014-10-23 10:18:09 -07001656 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001658
1659 final long identity = Binder.clearCallingIdentity();
1660 try {
1661 final Phone phone = getPhone(subId);
1662 if (phone != null) {
1663 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1664 }
1665 } finally {
1666 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001667 }
Wink Saville36469e72014-06-11 15:17:00 -07001668 }
1669
1670 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001671 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
Wink Savilleb564aae2014-10-23 10:18:09 -07001674 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001675 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001676
1677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 final Phone phone = getPhone(subId);
1680 if (phone == null) {
1681 return false;
1682 }
1683 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1684 toggleRadioOnOffForSubscriber(subId);
1685 }
1686 return true;
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
Wink Saville36469e72014-06-11 15:17:00 -07001691
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001692 public boolean needMobileRadioShutdown() {
1693 /*
1694 * If any of the Radios are available, it will need to be
1695 * shutdown. So return true if any Radio is available.
1696 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001697 final long identity = Binder.clearCallingIdentity();
1698 try {
1699 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1700 Phone phone = PhoneFactory.getPhone(i);
1701 if (phone != null && phone.isRadioAvailable()) return true;
1702 }
1703 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1704 return false;
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001707 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001708 }
1709
Malcolm Chend965c8b2018-02-28 15:00:40 -08001710 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001712 enforceModifyPermission();
1713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1717 logv("Shutting down Phone " + i);
1718 shutdownRadioUsingPhoneId(i);
1719 }
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001722 }
1723 }
1724
1725 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001726 Phone phone = PhoneFactory.getPhone(phoneId);
1727 if (phone != null && phone.isRadioAvailable()) {
1728 phone.shutdownRadio();
1729 }
1730 }
1731
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001733 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001734
1735 final long identity = Binder.clearCallingIdentity();
1736 try {
1737 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1738 if (defaultPhone != null) {
1739 defaultPhone.setRadioPower(turnOn);
1740 return true;
1741 } else {
1742 loge("There's no default phone.");
1743 return false;
1744 }
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001747 }
Wink Saville36469e72014-06-11 15:17:00 -07001748 }
1749
Wink Savilleb564aae2014-10-23 10:18:09 -07001750 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 final Phone phone = getPhone(subId);
1756 if (phone != null) {
1757 phone.setRadioPower(turnOn);
1758 return true;
1759 } else {
1760 return false;
1761 }
1762 } finally {
1763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 }
1766
Wink Saville36469e72014-06-11 15:17:00 -07001767 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 public boolean enableDataConnectivity() {
1770 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001771
1772 final long identity = Binder.clearCallingIdentity();
1773 try {
1774 int subId = mSubscriptionController.getDefaultDataSubId();
1775 final Phone phone = getPhone(subId);
1776 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001777 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001778 return true;
1779 } else {
1780 return false;
1781 }
1782 } finally {
1783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Wink Saville36469e72014-06-11 15:17:00 -07001787 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 public boolean disableDataConnectivity() {
1790 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001791
1792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 int subId = mSubscriptionController.getDefaultDataSubId();
1795 final Phone phone = getPhone(subId);
1796 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001797 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001798 return true;
1799 } else {
1800 return false;
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 }
1806
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001808 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 final Phone phone = getPhone(subId);
1812 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001813 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001814 } else {
1815 return false;
1816 }
1817 } finally {
1818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 }
1821
1822 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001823 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001824 }
1825
pkanwarae03a6b2016-11-06 20:37:09 -08001826 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001827 enforceCallPermission();
1828
1829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1832 return;
1833 }
1834 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1835 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1836 } finally {
1837 Binder.restoreCallingIdentity(identity);
1838 }
pkanwar32d516d2016-10-14 19:37:38 -07001839 };
1840
Wink Savilleb564aae2014-10-23 10:18:09 -07001841 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001843
1844 final long identity = Binder.clearCallingIdentity();
1845 try {
1846 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1847 return false;
1848 }
1849 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1850 } finally {
1851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 }
1854
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001856 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001857 }
1858
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001859 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001860 final long identity = Binder.clearCallingIdentity();
1861 try {
1862 Phone phone = PhoneFactory.getPhone(slotIndex);
1863 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1864 PhoneConstantConversions.convertCallState(phone.getState());
1865 } finally {
1866 Binder.restoreCallingIdentity(identity);
1867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 }
1869
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1875 if (phone != null) {
1876 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1877 } else {
1878 return PhoneConstantConversions.convertDataState(
1879 PhoneConstants.DataState.DISCONNECTED);
1880 }
1881 } finally {
1882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001888 final long identity = Binder.clearCallingIdentity();
1889 try {
1890 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1891 if (phone != null) {
1892 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1893 } else {
1894 return TelephonyManager.DATA_ACTIVITY_NONE;
1895 }
1896 } finally {
1897 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 }
1900
1901 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001902 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001903 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001904 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001905
1906 LocationAccessPolicy.LocationPermissionResult locationResult =
1907 LocationAccessPolicy.checkLocationPermission(mApp,
1908 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1909 .setCallingPackage(callingPackage)
1910 .setCallingPid(Binder.getCallingPid())
1911 .setCallingUid(Binder.getCallingUid())
1912 .setMethod("getCellLocation")
1913 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1914 .build());
1915 switch (locationResult) {
1916 case DENIED_HARD:
1917 throw new SecurityException("Not allowed to access cell location");
1918 case DENIED_SOFT:
1919 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001922 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001923 final long identity = Binder.clearCallingIdentity();
1924 try {
1925 if (DBG_LOC) log("getCellLocation: is active user");
1926 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001927 int subId = mSubscriptionController.getDefaultDataSubId();
1928 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1929 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001930 return data;
1931 } finally {
1932 Binder.restoreCallingIdentity(identity);
1933 }
Svetoslav64fad262015-04-14 14:35:21 -07001934 }
1935
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001937 public String getNetworkCountryIsoForPhone(int phoneId) {
1938 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1939 // registered cell info, so return a NULL country instead.
1940 final long identity = Binder.clearCallingIdentity();
1941 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001942 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1943 // Get default phone in this case.
1944 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1945 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001946 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001947 // Todo: fix this when we can get the actual cellular network info when the device
1948 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001949 if (TelephonyManager.NETWORK_TYPE_IWLAN
1950 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1951 return "";
1952 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001953 Phone phone = PhoneFactory.getPhone(phoneId);
1954 if (phone != null) {
1955 ServiceStateTracker sst = phone.getServiceStateTracker();
1956 if (sst != null) {
1957 LocaleTracker lt = sst.getLocaleTracker();
1958 if (lt != null) {
1959 return lt.getCurrentCountry();
1960 }
1961 }
1962 }
1963 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001964 } finally {
1965 Binder.restoreCallingIdentity(identity);
1966 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001967 }
1968
1969 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001971 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001972 }
1973
Sanket Padawe356d7632015-06-22 14:03:32 -07001974 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001975 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 mApp.enforceCallingOrSelfPermission(
1977 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001978
1979 final long identity = Binder.clearCallingIdentity();
1980 try {
1981 final Phone phone = getPhone(subId);
1982 if (phone != null) {
1983 phone.enableLocationUpdates();
1984 }
1985 } finally {
1986 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 }
1989
1990 @Override
1991 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001992 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001993 }
1994
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001996 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 mApp.enforceCallingOrSelfPermission(
1998 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001999
2000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 final Phone phone = getPhone(subId);
2003 if (phone != null) {
2004 phone.disableLocationUpdates();
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
Nathan Harold31d7ff32018-10-15 20:20:30 -07002011 /**
2012 * Returns the target SDK version number for a given package name.
2013 *
2014 * @return target SDK if the package is found or INT_MAX.
2015 */
2016 private int getTargetSdk(String packageName) {
2017 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002018 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2019 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002020 if (ai != null) return ai.targetSdkVersion;
2021 } catch (PackageManager.NameNotFoundException unexpected) {
2022 }
2023 return Integer.MAX_VALUE;
2024 }
2025
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 @Override
2027 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002028 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2029 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002030 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2031 throw new SecurityException(
2032 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2033 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002034
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2036 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2037 return null;
2038 }
Svetoslav64fad262015-04-14 14:35:21 -07002039
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002040 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041
Nathan Haroldf180aac2018-06-01 18:43:55 -07002042 List<CellInfo> info = getAllCellInfo(callingPackage);
2043 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044
Nathan Haroldf180aac2018-06-01 18:43:55 -07002045 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2046 for (CellInfo ci : info) {
2047 if (ci instanceof CellInfoGsm) {
2048 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2049 } else if (ci instanceof CellInfoWcdma) {
2050 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002053 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 }
2055
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002056 private List<CellInfo> getCachedCellInfo() {
2057 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2058 for (Phone phone : PhoneFactory.getPhones()) {
2059 List<CellInfo> info = phone.getAllCellInfo();
2060 if (info != null) cellInfos.addAll(info);
2061 }
2062 return cellInfos;
2063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064
2065 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002066 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002067 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002068 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002069
2070 LocationAccessPolicy.LocationPermissionResult locationResult =
2071 LocationAccessPolicy.checkLocationPermission(mApp,
2072 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2073 .setCallingPackage(callingPackage)
2074 .setCallingPid(Binder.getCallingPid())
2075 .setCallingUid(Binder.getCallingUid())
2076 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002077 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002078 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2079 .build());
2080 switch (locationResult) {
2081 case DENIED_HARD:
2082 throw new SecurityException("Not allowed to access cell info");
2083 case DENIED_SOFT:
2084 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 }
2086
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002087 final int targetSdk = getTargetSdk(callingPackage);
2088 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2089 return getCachedCellInfo();
2090 }
2091
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002092 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002093 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002094 final long identity = Binder.clearCallingIdentity();
2095 try {
2096 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2097 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002098 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002099 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002100 if (info != null) cellInfos.addAll(info);
2101 }
2102 return cellInfos;
2103 } finally {
2104 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 }
2106 }
2107
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002108 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002109 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2110 requestCellInfoUpdateInternal(
2111 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2112 }
2113
2114 @Override
2115 public void requestCellInfoUpdateWithWorkSource(
2116 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2117 enforceModifyPermission();
2118 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2119 }
2120
2121 private void requestCellInfoUpdateInternal(
2122 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002123 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002124 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002125
2126 LocationAccessPolicy.LocationPermissionResult locationResult =
2127 LocationAccessPolicy.checkLocationPermission(mApp,
2128 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2129 .setCallingPackage(callingPackage)
2130 .setCallingPid(Binder.getCallingPid())
2131 .setCallingUid(Binder.getCallingUid())
2132 .setMethod("requestCellInfoUpdate")
2133 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2134 .build());
2135 switch (locationResult) {
2136 case DENIED_HARD:
2137 throw new SecurityException("Not allowed to access cell info");
2138 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002139 try {
2140 cb.onCellInfo(new ArrayList<CellInfo>());
2141 } catch (RemoteException re) {
2142 // Drop without consequences
2143 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002144 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002145 }
2146
Nathan Harolda939a962019-05-09 10:13:47 -07002147
2148 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002149 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2150
2151 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2152 }
2153
2154 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002156 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002157 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002158
2159 final long identity = Binder.clearCallingIdentity();
2160 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002161 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002162 } finally {
2163 Binder.restoreCallingIdentity(identity);
2164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
Shishir Agrawala9f32182016-04-12 12:00:16 -07002167 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002168 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002169 Phone phone = PhoneFactory.getPhone(slotIndex);
2170 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002171 return null;
2172 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002173 int subId = phone.getSubId();
2174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2175 mApp, subId, callingPackage, "getImeiForSlot")) {
2176 return null;
2177 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002178
2179 final long identity = Binder.clearCallingIdentity();
2180 try {
2181 return phone.getImei();
2182 } finally {
2183 Binder.restoreCallingIdentity(identity);
2184 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002185 }
2186
2187 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002188 public String getTypeAllocationCodeForSlot(int slotIndex) {
2189 Phone phone = PhoneFactory.getPhone(slotIndex);
2190 String tac = null;
2191 if (phone != null) {
2192 String imei = phone.getImei();
2193 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2194 }
2195 return tac;
2196 }
2197
2198 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002199 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002200 Phone phone = PhoneFactory.getPhone(slotIndex);
2201 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002202 return null;
2203 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002204
Jeff Davidson913390f2018-02-23 17:11:49 -08002205 int subId = phone.getSubId();
2206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2207 mApp, subId, callingPackage, "getMeidForSlot")) {
2208 return null;
2209 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002210
2211 final long identity = Binder.clearCallingIdentity();
2212 try {
2213 return phone.getMeid();
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
2216 }
Jack Yu2af8d712017-03-15 17:14:14 -07002217 }
2218
2219 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002220 public String getManufacturerCodeForSlot(int slotIndex) {
2221 Phone phone = PhoneFactory.getPhone(slotIndex);
2222 String manufacturerCode = null;
2223 if (phone != null) {
2224 String meid = phone.getMeid();
2225 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2226 }
2227 return manufacturerCode;
2228 }
2229
2230 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002231 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002232 Phone phone = PhoneFactory.getPhone(slotIndex);
2233 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002234 return null;
2235 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002236 int subId = phone.getSubId();
2237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2238 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2239 return null;
2240 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002241
2242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 return phone.getDeviceSvn();
2245 } finally {
2246 Binder.restoreCallingIdentity(identity);
2247 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002248 }
2249
fionaxu43304da2017-11-27 22:51:16 -08002250 @Override
2251 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 final Phone phone = getPhone(subId);
2255 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
2258 }
fionaxu43304da2017-11-27 22:51:16 -08002259 }
2260
2261 @Override
2262 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002263 final long identity = Binder.clearCallingIdentity();
2264 try {
2265 final Phone phone = getPhone(subId);
2266 return phone == null ? null : phone.getCarrierName();
2267 } finally {
2268 Binder.restoreCallingIdentity(identity);
2269 }
fionaxu43304da2017-11-27 22:51:16 -08002270 }
2271
calvinpaneed9ae82018-11-01 19:43:06 +08002272 @Override
chen xua31f22b2019-03-06 15:28:50 -08002273 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002274 final long identity = Binder.clearCallingIdentity();
2275 try {
2276 final Phone phone = getPhone(subId);
2277 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002278 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002279 } finally {
2280 Binder.restoreCallingIdentity(identity);
2281 }
2282 }
2283
2284 @Override
chen xua31f22b2019-03-06 15:28:50 -08002285 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002286 final long identity = Binder.clearCallingIdentity();
2287 try {
2288 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002289 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002290 } finally {
2291 Binder.restoreCallingIdentity(identity);
2292 }
2293 }
2294
chen xu02581692018-11-11 19:03:44 -08002295 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002296 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2297 if (!isSubscriptionMccMnc) {
2298 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2299 }
chen xu02581692018-11-11 19:03:44 -08002300 final Phone phone = PhoneFactory.getPhone(slotIndex);
2301 if (phone == null) {
2302 return TelephonyManager.UNKNOWN_CARRIER_ID;
2303 }
2304 final long identity = Binder.clearCallingIdentity();
2305 try {
2306 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2307 } finally {
2308 Binder.restoreCallingIdentity(identity);
2309 }
2310 }
2311
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 //
2313 // Internal helper methods.
2314 //
2315
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002316 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2318 *
2319 * @throws SecurityException if the caller does not have the required permission
2320 */
2321 private void enforceModifyPermission() {
2322 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2323 }
2324
2325 /**
2326 * Make sure the caller has the CALL_PHONE permission.
2327 *
2328 * @throws SecurityException if the caller does not have the required permission
2329 */
2330 private void enforceCallPermission() {
2331 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2332 }
2333
Stuart Scott8eef64f2015-04-08 15:13:54 -07002334 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002335 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002336 "ConnectivityService");
2337 }
2338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 private String createTelUrl(String number) {
2340 if (TextUtils.isEmpty(number)) {
2341 return null;
2342 }
2343
Jake Hambye994d462014-02-03 13:10:13 -08002344 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 }
2346
Ihab Awadf9e92732013-12-05 18:02:52 -08002347 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2349 }
2350
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002351 private static void logv(String msg) {
2352 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2353 }
2354
Ihab Awadf9e92732013-12-05 18:02:52 -08002355 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2357 }
2358
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002359 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002361 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002362 }
2363
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002365 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = PhoneFactory.getPhone(slotIndex);
2369 if (phone == null) {
2370 return PhoneConstants.PHONE_TYPE_NONE;
2371 } else {
2372 return phone.getPhoneType();
2373 }
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002376 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 }
2378
2379 /**
2380 * Returns the CDMA ERI icon index to display
2381 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002382 @Override
2383 public int getCdmaEriIconIndex(String callingPackage) {
2384 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002385 }
2386
Sanket Padawe356d7632015-06-22 14:03:32 -07002387 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002388 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002390 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002391 return -1;
2392 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002393
2394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 final Phone phone = getPhone(subId);
2397 if (phone != null) {
2398 return phone.getCdmaEriIconIndex();
2399 } else {
2400 return -1;
2401 }
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
2406
2407 /**
2408 * Returns the CDMA ERI icon mode,
2409 * 0 - ON
2410 * 1 - FLASHING
2411 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002412 @Override
2413 public int getCdmaEriIconMode(String callingPackage) {
2414 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002415 }
2416
Sanket Padawe356d7632015-06-22 14:03:32 -07002417 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002418 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002420 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002421 return -1;
2422 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002423
2424 final long identity = Binder.clearCallingIdentity();
2425 try {
2426 final Phone phone = getPhone(subId);
2427 if (phone != null) {
2428 return phone.getCdmaEriIconMode();
2429 } else {
2430 return -1;
2431 }
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
2437 /**
2438 * Returns the CDMA ERI text,
2439 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002440 @Override
2441 public String getCdmaEriText(String callingPackage) {
2442 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002443 }
2444
Sanket Padawe356d7632015-06-22 14:03:32 -07002445 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002446 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002448 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002449 return null;
2450 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002451
2452 final long identity = Binder.clearCallingIdentity();
2453 try {
2454 final Phone phone = getPhone(subId);
2455 if (phone != null) {
2456 return phone.getCdmaEriText();
2457 } else {
2458 return null;
2459 }
2460 } finally {
2461 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464
2465 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002466 * Returns the CDMA MDN.
2467 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002468 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002469 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2471 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002472
2473 final long identity = Binder.clearCallingIdentity();
2474 try {
2475 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002476 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002477 return phone.getLine1Number();
2478 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002479 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002480 return null;
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002484 }
2485 }
2486
2487 /**
2488 * Returns the CDMA MIN.
2489 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002490 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2493 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002494
2495 final long identity = Binder.clearCallingIdentity();
2496 try {
2497 final Phone phone = getPhone(subId);
2498 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2499 return phone.getCdmaMin();
2500 } else {
2501 return null;
2502 }
2503 } finally {
2504 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002505 }
2506 }
2507
Hall Liud892bec2018-11-30 14:51:45 -08002508 @Override
2509 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2510 INumberVerificationCallback callback, String callingPackage) {
2511 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2512 != PERMISSION_GRANTED) {
2513 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2514 }
2515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2516
2517 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2518 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2519 throw new SecurityException("Calling package must be configured in the device config");
2520 }
2521
2522 if (range == null) {
2523 throw new NullPointerException("Range must be non-null");
2524 }
2525
2526 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002527 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002528
2529 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2530 }
2531
Junda Liuca05d5d2014-08-14 22:36:34 -07002532 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 * Returns true if CDMA provisioning needs to run.
2534 */
2535 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002536 final long identity = Binder.clearCallingIdentity();
2537 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002538 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002539 } finally {
2540 Binder.restoreCallingIdentity(identity);
2541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 }
2543
2544 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002545 * Sets the voice mail number of a given subId.
2546 */
2547 @Override
2548 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002549 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002550
2551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2554 new Pair<String, String>(alphaTag, number), new Integer(subId));
2555 return success;
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
2558 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002559 }
2560
Ta-wei Yen87c49842016-05-13 21:19:52 -07002561 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002562 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2563 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002564 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002565 if (!TextUtils.equals(callingPackage, systemDialer)) {
2566 throw new SecurityException("caller must be system dialer");
2567 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2572 if (phoneAccountHandle == null) {
2573 return null;
2574 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002575 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002576 } finally {
2577 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002578 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002579 }
2580
2581 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002582 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002585 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002586 return null;
2587 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002588
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002589 final long identity = Binder.clearCallingIdentity();
2590 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002591 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002592 } finally {
2593 Binder.restoreCallingIdentity(identity);
2594 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002595 }
2596
2597 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002598 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2599 VisualVoicemailSmsFilterSettings settings) {
2600 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002601
2602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002605 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002606 } finally {
2607 Binder.restoreCallingIdentity(identity);
2608 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002609 }
2610
2611 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002612 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2613 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002618 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002622 }
2623
2624 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002625 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2626 String callingPackage, int subId) {
2627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002632 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002636 }
2637
2638 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002639 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002640 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002645 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002649 }
2650
2651 @Override
2652 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2653 String number, int port, String text, PendingIntent sentIntent) {
2654 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002655 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002656 enforceSendSmsPermission();
Amit Mahajan716e76c2019-05-13 13:48:32 -07002657 SmsController smsController = PhoneFactory.getSmsController();
2658 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2659 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002660 }
Amit Mahajan716e76c2019-05-13 13:48:32 -07002661
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002662 /**
fionaxu0152e512016-11-14 13:36:14 -08002663 * Sets the voice activation state of a given subId.
2664 */
2665 @Override
2666 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2668 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002669
2670 final long identity = Binder.clearCallingIdentity();
2671 try {
2672 final Phone phone = getPhone(subId);
2673 if (phone != null) {
2674 phone.setVoiceActivationState(activationState);
2675 } else {
2676 loge("setVoiceActivationState fails with invalid subId: " + subId);
2677 }
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002680 }
2681 }
2682
2683 /**
2684 * Sets the data activation state of a given subId.
2685 */
2686 @Override
2687 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2689 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002690
2691 final long identity = Binder.clearCallingIdentity();
2692 try {
2693 final Phone phone = getPhone(subId);
2694 if (phone != null) {
2695 phone.setDataActivationState(activationState);
2696 } else {
2697 loge("setVoiceActivationState fails with invalid subId: " + subId);
2698 }
2699 } finally {
2700 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002701 }
2702 }
2703
2704 /**
2705 * Returns the voice activation state of a given subId.
2706 */
2707 @Override
2708 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002709 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002710
fionaxu0152e512016-11-14 13:36:14 -08002711 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002712 final long identity = Binder.clearCallingIdentity();
2713 try {
2714 if (phone != null) {
2715 return phone.getVoiceActivationState();
2716 } else {
2717 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2718 }
2719 } finally {
2720 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002721 }
2722 }
2723
2724 /**
2725 * Returns the data activation state of a given subId.
2726 */
2727 @Override
2728 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002729 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002730
fionaxu0152e512016-11-14 13:36:14 -08002731 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002732 final long identity = Binder.clearCallingIdentity();
2733 try {
2734 if (phone != null) {
2735 return phone.getDataActivationState();
2736 } else {
2737 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2738 }
2739 } finally {
2740 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002741 }
2742 }
2743
2744 /**
Wink Saville36469e72014-06-11 15:17:00 -07002745 * Returns the unread count of voicemails for a subId
2746 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002747 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002748 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2750 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2751 return 0;
2752 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002753 final long identity = Binder.clearCallingIdentity();
2754 try {
2755 final Phone phone = getPhone(subId);
2756 if (phone != null) {
2757 return phone.getVoiceMessageCount();
2758 } else {
2759 return 0;
2760 }
2761 } finally {
2762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 }
2765
2766 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002767 * returns true, if the device is in a state where both voice and data
2768 * are supported simultaneously. This can change based on location or network condition.
2769 */
2770 @Override
2771 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 final Phone phone = getPhone(subId);
2775 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
2778 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002779 }
2780
2781 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002782 * Send the dialer code if called from the current default dialer or the caller has
2783 * carrier privilege.
2784 * @param inputCode The dialer code to send
2785 */
2786 @Override
2787 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002788 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002789 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002790 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2791 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002792 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002793 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2794 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002795 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002799 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002800 } finally {
2801 Binder.restoreCallingIdentity(identity);
2802 }
fionaxu235cc5e2017-03-06 22:25:57 -08002803 }
2804
Pengquan Meng0c05b502018-09-06 09:59:22 -07002805 @Override
2806 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002807 if (!isActiveSubscription(subId)) {
2808 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2809 }
2810
Pengquan Meng0c05b502018-09-06 09:59:22 -07002811 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2812 }
2813
Brad Ebinger4c460712018-10-01 10:40:55 -07002814 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002815 public boolean isInEmergencySmsMode() {
2816 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 for (Phone phone : PhoneFactory.getPhones()) {
2820 if (phone.isInEmergencySmsMode()) {
2821 return true;
2822 }
2823 }
2824 } finally {
2825 Binder.restoreCallingIdentity(identity);
2826 }
2827 return false;
2828 }
2829
2830 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002831 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2832 throws RemoteException {
2833 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002834 final long token = Binder.clearCallingIdentity();
2835 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002837 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002838 .addRegistrationCallbackForSubscription(c, subId);
2839 } finally {
2840 Binder.restoreCallingIdentity(token);
2841 }
2842 }
2843
2844 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002845 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2846 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002847 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2848 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2849 }
2850 Binder.withCleanCallingIdentity(() -> {
2851 try {
2852 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002853 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002854 .removeRegistrationCallbackForSubscription(c, subId);
2855 } catch (IllegalArgumentException e) {
2856 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2857 + "is inactive, ignoring unregister.");
2858 // If the subscription is no longer active, just return, since the callback
2859 // will already have been removed internally.
2860 }
2861 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002862 }
2863
2864 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002865 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2866 throws RemoteException {
2867 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2869 final long token = Binder.clearCallingIdentity();
2870 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002871 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002872 .addCapabilitiesCallbackForSubscription(c, subId);
2873 } finally {
2874 Binder.restoreCallingIdentity(token);
2875 }
2876 }
2877
2878 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002879 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2880 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002881
2882 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2883 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2884 }
2885 Binder.withCleanCallingIdentity(() -> {
2886 try {
2887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002888 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002889 .removeCapabilitiesCallbackForSubscription(c, subId);
2890 } catch (IllegalArgumentException e) {
2891 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2892 + "is inactive, ignoring unregister.");
2893 // If the subscription is no longer active, just return, since the callback
2894 // will already have been removed internally.
2895 }
2896 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002897 }
2898
2899 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002900 public boolean isCapable(int subId, int capability, int regTech) {
2901 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002902 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2903 final long token = Binder.clearCallingIdentity();
2904 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002905 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002906 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2907 } catch (ImsException e) {
2908 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2909 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002910 } catch (IllegalArgumentException e) {
2911 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2912 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002913 } finally {
2914 Binder.restoreCallingIdentity(token);
2915 }
2916 }
2917
2918 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002919 public boolean isAvailable(int subId, int capability, int regTech) {
2920 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002921 final long token = Binder.clearCallingIdentity();
2922 try {
2923 Phone phone = getPhone(subId);
2924 if (phone == null) return false;
2925 return phone.isImsCapabilityAvailable(capability, regTech);
2926 } finally {
2927 Binder.restoreCallingIdentity(token);
2928 }
2929 }
2930
2931 @Override
2932 public boolean isAdvancedCallingSettingEnabled(int subId) {
2933 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2935 final long token = Binder.clearCallingIdentity();
2936 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002937 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002938 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2939 } finally {
2940 Binder.restoreCallingIdentity(token);
2941 }
2942 }
2943
2944 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002945 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002947 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002951 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002952 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
2955 }
2956 }
2957
2958 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002959 public boolean isVtSettingEnabled(int subId) {
2960 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002964 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002965 getSlotIndexOrException(subId)).isVtEnabledByUser();
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002972 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002974 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002978 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
2985 public boolean isVoWiFiSettingEnabled(int subId) {
2986 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002990 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002991 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
2997 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002998 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003000 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003004 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 }
3009
3010 @Override
3011 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3012 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003016 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003017 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
3021 }
3022
3023 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003024 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003026 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003030 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003031 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
3035 }
3036
3037 @Override
3038 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3040 "setVoWiFiNonPersistent");
3041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003044 ImsManager.getInstance(mApp,
Brad Ebinger2bc95702019-05-07 18:33:46 -07003045 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger4c460712018-10-01 10:40:55 -07003046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
3049 }
3050
3051 @Override
3052 public int getVoWiFiModeSetting(int subId) {
3053 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3054 final long identity = Binder.clearCallingIdentity();
3055 try {
3056 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003057 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003058 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
3062 }
3063
3064 @Override
3065 public void setVoWiFiModeSetting(int subId, int mode) {
3066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3067 "setVoWiFiModeSetting");
3068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003071 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003072 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
3076 }
3077
3078 @Override
3079 public int getVoWiFiRoamingModeSetting(int subId) {
3080 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003084 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003085 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
3089 }
3090
3091 @Override
3092 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3094 "setVoWiFiRoamingModeSetting");
3095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003098 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003099 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3100 } finally {
3101 Binder.restoreCallingIdentity(identity);
3102 }
3103 }
3104
3105 @Override
3106 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3108 "setRttCapabilityEnabled");
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003112 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003113 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
3117 }
3118
3119 @Override
3120 public boolean isTtyOverVolteEnabled(int subId) {
3121 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003125 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003126 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
3130 }
3131
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003132 @Override
3133 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3134 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003138 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003139 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
3143 }
3144
3145 @Override
3146 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3147 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3148 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003149 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3150 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3151 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003152 try {
3153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003154 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003155 .removeProvisioningCallbackForSubscription(callback, subId);
3156 } catch (IllegalArgumentException e) {
3157 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3158 + "is inactive, ignoring unregister.");
3159 // If the subscription is no longer active, just return, since the callback will already
3160 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003161 } finally {
3162 Binder.restoreCallingIdentity(identity);
3163 }
3164 }
3165
3166 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003167 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3168 boolean isProvisioned) {
3169 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3170 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3171 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3172 }
3173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3174 "setProvisioningStatusForCapability");
3175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3178 Phone phone = getPhone(subId);
3179 if (phone == null) {
3180 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3181 + subId);
3182 return;
3183 }
3184 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3185 return;
3186 }
3187
3188 // this capability requires provisioning, route to the correct API.
3189 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3190 switch (capability) {
3191 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3192 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3193 ims.setVolteProvisioned(isProvisioned);
3194 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3195 ims.setWfcProvisioned(isProvisioned);
3196 }
3197 break;
3198 }
3199 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3200 // There is currently no difference in VT provisioning type.
3201 ims.setVtProvisioned(isProvisioned);
3202 break;
3203 }
3204 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3205 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3206 // change the capability of the feature instead if needed.
3207 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3208 == isProvisioned) {
3209 // No change in provisioning.
3210 return;
3211 }
3212 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3213 try {
3214 ims.changeMmTelCapability(capability, tech, isProvisioned);
3215 } catch (ImsException e) {
3216 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3217 + ", Exception" + e.getMessage());
3218 }
3219 break;
3220 }
3221 default: {
3222 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3223 + capability + "', which does not require provisioning.");
3224 }
3225 }
3226
3227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
3230 }
3231
3232 @Override
3233 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3234 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3235 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3236 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3237 }
3238 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3242 Phone phone = getPhone(subId);
3243 if (phone == null) {
3244 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3245 + subId);
3246 // We will fail with "true" as the provisioning status because this is the default
3247 // if we do not require provisioning.
3248 return true;
3249 }
3250
3251 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3252 return true;
3253 }
3254
3255 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3256 switch (capability) {
3257 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3258 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3259 return ims.isVolteProvisionedOnDevice();
3260 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3261 return ims.isWfcProvisionedOnDevice();
3262 }
3263 // This should never happen, since we are checking tech above to make sure it
3264 // is either LTE or IWLAN.
3265 throw new IllegalArgumentException("Invalid radio technology for voice "
3266 + "capability.");
3267 }
3268 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3269 // There is currently no difference in VT provisioning type.
3270 return ims.isVtProvisionedOnDevice();
3271 }
3272 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3273 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3274 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3275 }
3276 default: {
3277 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3278 + capability + "', which does not require provisioning.");
3279 }
3280 }
3281
3282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
3285 }
3286
3287 @Override
3288 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3289 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3290 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3291 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3292 }
3293 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3294 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3295 return (provisionedBits & capability) > 0;
3296 }
3297
3298 @Override
3299 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3300 boolean isProvisioned) {
3301 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3302 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3303 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3304 }
3305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3306 "setProvisioningStatusForCapability");
3307 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3308 // If the current provisioning status for capability already matches isProvisioned,
3309 // do nothing.
3310 if (((provisionedBits & capability) > 0) == isProvisioned) {
3311 return;
3312 }
3313 if (isProvisioned) {
3314 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3315 } else {
3316 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3317 }
3318 }
3319
3320 /**
3321 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3322 * technology. The bitfield should mirror the bitfield defined by
3323 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3324 */
3325 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3326 String key = getMmTelProvisioningKey(subId, tech);
3327 // Default is no capabilities are provisioned.
3328 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3329 }
3330
3331 /**
3332 * Sets the MmTel capability provisioning bitfield (defined by
3333 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3334 * technology specified.
3335 *
3336 * Note: This is a synchronous command and should not be called on UI thread.
3337 */
3338 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3339 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3340 String key = getMmTelProvisioningKey(subId, tech);
3341 editor.putInt(key, newField);
3342 editor.commit();
3343 }
3344
3345 private static String getMmTelProvisioningKey(int subId, int tech) {
3346 // resulting key is provision_ims_mmtel_{subId}_{tech}
3347 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3348 }
3349
3350 /**
3351 * Query CarrierConfig to see if the specified capability requires provisioning for the
3352 * carrier associated with the subscription id.
3353 */
3354 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3355 int capability) {
3356 CarrierConfigManager configManager = new CarrierConfigManager(context);
3357 PersistableBundle c = configManager.getConfigForSubId(subId);
3358 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003359 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003360 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3361 false);
3362 boolean requireVoiceVtProvisioning = c.getBoolean(
3363 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3364
3365 // First check to make sure that the capability requires provisioning.
3366 switch (capability) {
3367 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3368 // intentional fallthrough
3369 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3370 if (requireVoiceVtProvisioning) {
3371 // Voice and Video requires provisioning
3372 return true;
3373 }
3374 break;
3375 }
3376 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3377 if (requireUtProvisioning) {
3378 // UT requires provisioning
3379 return true;
3380 }
3381 break;
3382 }
3383 }
3384 return false;
3385 }
3386
3387 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003388 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003389 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3390 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3391 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003392 enforceReadPrivilegedPermission("getImsProvisioningInt");
3393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003396 int slotId = getSlotIndex(subId);
3397 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3398 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3399 + subId + "' for key:" + key);
3400 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3401 }
3402 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003403 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003404 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3405 + subId + "' for key:" + key);
3406 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003407 } finally {
3408 Binder.restoreCallingIdentity(identity);
3409 }
3410 }
3411
3412 @Override
3413 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003414 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3415 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3416 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003417 enforceReadPrivilegedPermission("getImsProvisioningString");
3418 final long identity = Binder.clearCallingIdentity();
3419 try {
3420 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 int slotId = getSlotIndex(subId);
3422 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3423 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3424 + subId + "' for key:" + key);
3425 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3426 }
3427 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003428 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003429 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3430 + subId + "' for key:" + key);
3431 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
3435 }
3436
3437 @Override
3438 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003439 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3440 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3441 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3443 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003447 int slotId = getSlotIndex(subId);
3448 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3449 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3450 + subId + "' for key:" + key);
3451 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3452 }
3453 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003454 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003455 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3456 + "' for key:" + key);
3457 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003458 } finally {
3459 Binder.restoreCallingIdentity(identity);
3460 }
3461 }
3462
3463 @Override
3464 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003465 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3466 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3467 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3469 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003473 int slotId = getSlotIndex(subId);
3474 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3475 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3476 + subId + "' for key:" + key);
3477 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3478 }
3479 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003480 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003481 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3482 + "' for key:" + key);
3483 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003484 } finally {
3485 Binder.restoreCallingIdentity(identity);
3486 }
3487 }
3488
Brad Ebinger4c460712018-10-01 10:40:55 -07003489 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3490 int slotId = SubscriptionManager.getSlotIndex(subId);
3491 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003492 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003493 }
3494 return slotId;
3495 }
3496
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003497 private int getSlotIndex(int subId) {
3498 int slotId = SubscriptionManager.getSlotIndex(subId);
3499 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3500 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3501 }
3502 return slotId;
3503 }
3504
Wink Saville36469e72014-06-11 15:17:00 -07003505 /**
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003506 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003507 */
3508 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003509 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003510 if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q
3511 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3512 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003513 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3514 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003515
Malcolm Chend965c8b2018-02-28 15:00:40 -08003516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 final Phone phone = getPhone(subId);
3519 if (phone != null) {
3520 return phone.getServiceState().getDataNetworkType();
3521 } else {
3522 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3523 }
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003527 }
3528
3529 /**
3530 * Returns the data network type
3531 */
3532 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003533 public int getDataNetworkType(String callingPackage) {
3534 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003535 }
3536
3537 /**
3538 * Returns the data network type for a subId
3539 */
3540 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003543 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003544 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3545 }
3546
Malcolm Chend965c8b2018-02-28 15:00:40 -08003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 final Phone phone = getPhone(subId);
3550 if (phone != null) {
3551 return phone.getServiceState().getDataNetworkType();
3552 } else {
3553 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003558 }
3559
3560 /**
Wink Saville36469e72014-06-11 15:17:00 -07003561 * Returns the Voice network type for a subId
3562 */
3563 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003564 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003566 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003567 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3568 }
3569
Malcolm Chend965c8b2018-02-28 15:00:40 -08003570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 final Phone phone = getPhone(subId);
3573 if (phone != null) {
3574 return phone.getServiceState().getVoiceNetworkType();
3575 } else {
3576 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3577 }
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003581 }
3582
3583 /**
3584 * @return true if a ICC card is present
3585 */
3586 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003587 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003588 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3589 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003590 }
3591
3592 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003593 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003594 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003595 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003596 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 final Phone phone = PhoneFactory.getPhone(slotIndex);
3600 if (phone != null) {
3601 return phone.getIccCard().hasIccCard();
3602 } else {
3603 return false;
3604 }
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003608 }
3609
3610 /**
3611 * Return if the current radio is LTE on CDMA. This
3612 * is a tri-state return value as for a period of time
3613 * the mode may be unknown.
3614 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003615 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003616 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003617 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003618 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003619 @Override
3620 public int getLteOnCdmaMode(String callingPackage) {
3621 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003622 }
3623
Sanket Padawe356d7632015-06-22 14:03:32 -07003624 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003625 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003627 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003628 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3629 }
3630
Malcolm Chend965c8b2018-02-28 15:00:40 -08003631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 final Phone phone = getPhone(subId);
3634 if (phone == null) {
3635 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3636 } else {
3637 return phone.getLteOnCdmaMode();
3638 }
3639 } finally {
3640 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003641 }
Wink Saville36469e72014-06-11 15:17:00 -07003642 }
3643
Wink Saville36469e72014-06-11 15:17:00 -07003644 /**
3645 * {@hide}
3646 * Returns Default subId, 0 in the case of single standby.
3647 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003648 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003649 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003650 }
3651
Shishir Agrawala9f32182016-04-12 12:00:16 -07003652 private int getSlotForDefaultSubscription() {
3653 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3654 }
3655
Wink Savilleb564aae2014-10-23 10:18:09 -07003656 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003657 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003658 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003659
Pengquan Meng466e2482018-09-21 15:54:48 -07003660 private boolean isActiveSubscription(int subId) {
3661 return mSubscriptionController.isActiveSubId(subId);
3662 }
3663
Ihab Awadf2177b72013-11-25 13:33:23 -08003664 /**
3665 * @see android.telephony.TelephonyManager.WifiCallingChoices
3666 */
3667 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003668 final long identity = Binder.clearCallingIdentity();
3669 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003670 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003671 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3672 getWhenToMakeWifiCallsDefaultPreference());
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003676 }
3677
3678 /**
3679 * @see android.telephony.TelephonyManager.WifiCallingChoices
3680 */
3681 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003685 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003686 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003690 }
3691
Sailesh Nepald1e68152013-12-12 19:08:02 -08003692 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003693 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003694 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003695 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003696
Jordan Liu73b078d2019-02-28 12:03:40 -08003697 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3698 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3699 if (phoneId == -1) {
3700 throw new IllegalArgumentException("Given slot index: " + slotIndex
3701 + " does not correspond to an active phone");
3702 }
3703 return PhoneFactory.getPhone(phoneId);
3704 }
3705
Shishir Agrawal566b7612013-10-28 14:41:00 -07003706 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003707 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3708 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3710 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003712 if (DBG) {
3713 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3714 }
3715 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3716 p2);
3717 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003718
Jordan Liu73b078d2019-02-28 12:03:40 -08003719
3720 @Override
3721 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3722 int slotIndex, String callingPackage, String aid, int p2) {
3723 enforceModifyPermission();
3724 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3725 if (DBG) {
3726 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3727 }
3728 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3729 callingPackage, aid, p2);
3730 }
3731
3732 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3733 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 if (TextUtils.equals(ISDR_AID, aid)) {
3737 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003738 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3739 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003740 if (bestComponent == null
3741 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3742 loge("The calling package is not allowed to access ISD-R.");
3743 throw new SecurityException(
3744 "The calling package is not allowed to access ISD-R.");
3745 }
Derek Tan740e1672017-06-27 14:56:27 -07003746 }
Derek Tan740e1672017-06-27 14:56:27 -07003747
Malcolm Chend965c8b2018-02-28 15:00:40 -08003748 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003749 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3750 null /* workSource */);
3751 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003752 return response;
3753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003756 }
3757
3758 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003759 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3761 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003762 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3763 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3764 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003765
Jordan Liu73b078d2019-02-28 12:03:40 -08003766 @Override
3767 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3768 enforceModifyPermission();
3769 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3770 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3771 channel);
3772 }
3773
3774 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003775 final long identity = Binder.clearCallingIdentity();
3776 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003777 if (channel < 0) {
3778 return false;
3779 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003780 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3781 null /* workSource */);
3782 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003783 return success;
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003786 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003787 }
3788
3789 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003790 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003791 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3793 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003794 if (DBG) {
3795 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3796 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3797 + p3 + " data=" + data);
3798 }
3799 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3800 command, p1, p2, p3, data);
3801 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003802
Jordan Liu73b078d2019-02-28 12:03:40 -08003803 @Override
3804 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3805 int command, int p1, int p2, int p3, String data) {
3806 enforceModifyPermission();
3807 if (DBG) {
3808 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3809 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3810 + p3 + " data=" + data);
3811 }
3812 return iccTransmitApduLogicalChannelWithPermission(
3813 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3814 data);
3815 }
3816
3817 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3818 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003819 final long identity = Binder.clearCallingIdentity();
3820 try {
Hall Liucdcfa292019-05-02 09:16:29 -07003821 if (channel <= 0) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003822 return "";
3823 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003824
Malcolm Chend965c8b2018-02-28 15:00:40 -08003825 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003826 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3827 null /* workSource */);
3828 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003829
Malcolm Chend965c8b2018-02-28 15:00:40 -08003830 // Append the returned status code to the end of the response payload.
3831 String s = Integer.toHexString(
3832 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3833 if (response.payload != null) {
3834 s = IccUtils.bytesToHexString(response.payload) + s;
3835 }
3836 return s;
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003839 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003840 }
Jake Hambye994d462014-02-03 13:10:13 -08003841
Evan Charltonc66da362014-05-16 14:06:40 -07003842 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003843 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3844 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3846 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003847 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003848 if (DBG) {
3849 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3850 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3851 }
3852 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3853 cla, command, p1, p2, p3, data);
3854 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003855
Jordan Liu73b078d2019-02-28 12:03:40 -08003856 @Override
3857 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3858 int command, int p1, int p2, int p3, String data) {
3859 enforceModifyPermission();
3860 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3861 if (DBG) {
3862 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3863 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3864 + " data=" + data);
3865 }
3866
3867 return iccTransmitApduBasicChannelWithPermission(
3868 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3869 p2, p3, data);
3870 }
3871
3872 // open APDU basic channel assuming the caller has sufficient permissions
3873 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3874 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003875 final long identity = Binder.clearCallingIdentity();
3876 try {
3877 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3878 && TextUtils.equals(ISDR_AID, data)) {
3879 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003880 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3881 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003882 if (bestComponent == null
3883 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3884 loge("The calling package is not allowed to select ISD-R.");
3885 throw new SecurityException(
3886 "The calling package is not allowed to select ISD-R.");
3887 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003888 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003889
Malcolm Chend965c8b2018-02-28 15:00:40 -08003890 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003891 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3892 null /* workSource */);
3893 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003894
Malcolm Chend965c8b2018-02-28 15:00:40 -08003895 // Append the returned status code to the end of the response payload.
3896 String s = Integer.toHexString(
3897 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3898 if (response.payload != null) {
3899 s = IccUtils.bytesToHexString(response.payload) + s;
3900 }
3901 return s;
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003904 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003905 }
3906
3907 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003908 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003909 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3911 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003912
Malcolm Chend965c8b2018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 if (DBG) {
3916 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3917 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3918 }
3919
3920 IccIoResult response =
3921 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3922 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3923 subId);
3924
3925 if (DBG) {
3926 log("Exchange SIM_IO [R]" + response);
3927 }
3928
3929 byte[] result = null;
3930 int length = 2;
3931 if (response.payload != null) {
3932 length = 2 + response.payload.length;
3933 result = new byte[length];
3934 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3935 } else {
3936 result = new byte[length];
3937 }
3938
3939 result[length - 1] = (byte) response.sw2;
3940 result[length - 2] = (byte) response.sw1;
3941 return result;
3942 } finally {
3943 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003944 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003945 }
3946
Nathan Haroldb3014052017-01-25 15:57:32 -08003947 /**
3948 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3949 * on a particular subscription
3950 */
sqianb6e41952018-03-12 14:54:01 -07003951 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3953 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3954 return null;
3955 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003956
3957 final long identity = Binder.clearCallingIdentity();
3958 try {
3959 if (appType != TelephonyManager.APPTYPE_USIM
3960 && appType != TelephonyManager.APPTYPE_SIM) {
3961 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3962 return null;
3963 }
3964 Object response = sendRequest(
3965 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3966 if (response instanceof String[]) {
3967 return (String[]) response;
3968 }
3969 // Response is an Exception of some kind,
3970 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003971 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003972 } finally {
3973 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003974 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003975 }
3976
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003977 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003978 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3980 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003981
Malcolm Chend965c8b2018-02-28 15:00:40 -08003982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3985 if (response.payload == null) {
3986 return "";
3987 }
Evan Charltonc66da362014-05-16 14:06:40 -07003988
Malcolm Chend965c8b2018-02-28 15:00:40 -08003989 // Append the returned status code to the end of the response payload.
3990 String s = Integer.toHexString(
3991 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3992 s = IccUtils.bytesToHexString(response.payload) + s;
3993 return s;
3994 } finally {
3995 Binder.restoreCallingIdentity(identity);
3996 }
Evan Charltonc66da362014-05-16 14:06:40 -07003997 }
3998
Jake Hambye994d462014-02-03 13:10:13 -08003999 /**
4000 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4001 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4002 *
4003 * @param itemID the ID of the item to read
4004 * @return the NV item as a String, or null on error.
4005 */
4006 @Override
4007 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004008 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4010 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004011
4012 final long identity = Binder.clearCallingIdentity();
4013 try {
4014 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004015 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004016 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4017 return value;
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
4020 }
Jake Hambye994d462014-02-03 13:10:13 -08004021 }
4022
4023 /**
4024 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4025 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4026 *
4027 * @param itemID the ID of the item to read
4028 * @param itemValue the value to write, as a String
4029 * @return true on success; false on any failure
4030 */
4031 @Override
4032 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4035 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004036
4037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4040 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004041 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004042 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4043 return success;
4044 } finally {
4045 Binder.restoreCallingIdentity(identity);
4046 }
Jake Hambye994d462014-02-03 13:10:13 -08004047 }
4048
4049 /**
4050 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4051 * Used for device configuration by some CDMA operators.
4052 *
4053 * @param preferredRoamingList byte array containing the new PRL
4054 * @return true on success; false on any failure
4055 */
4056 @Override
4057 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4059 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004060
4061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4064 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4065 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4066 return success;
4067 } finally {
4068 Binder.restoreCallingIdentity(identity);
4069 }
Jake Hambye994d462014-02-03 13:10:13 -08004070 }
4071
4072 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004073 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004074 * Used for device configuration by some CDMA operators.
4075 *
chen xu1cc0abe2018-10-26 17:39:23 -07004076 * @param slotIndex - device slot.
4077 *
Jake Hambye994d462014-02-03 13:10:13 -08004078 * @return true on success; false on any failure
4079 */
4080 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004081 public boolean resetModemConfig(int slotIndex) {
4082 Phone phone = PhoneFactory.getPhone(slotIndex);
4083 if (phone != null) {
4084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4085 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004086
chen xu1cc0abe2018-10-26 17:39:23 -07004087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4090 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4091 return success;
4092 } finally {
4093 Binder.restoreCallingIdentity(identity);
4094 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004095 }
chen xu1cc0abe2018-10-26 17:39:23 -07004096 return false;
4097 }
4098
4099 /**
4100 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4101 *
4102 * @param slotIndex - device slot.
4103 *
4104 * @return true on success; false on any failure
4105 */
4106 @Override
4107 public boolean rebootModem(int slotIndex) {
4108 Phone phone = PhoneFactory.getPhone(slotIndex);
4109 if (phone != null) {
4110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4111 mApp, phone.getSubId(), "rebootModem");
4112
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4116 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4117 return success;
4118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
4121 }
4122 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004123 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004124
Svet Ganovb320e182015-04-16 12:30:10 -07004125 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004126 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004128 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004129 return new String[0];
4130 }
4131
Malcolm Chend965c8b2018-02-28 15:00:40 -08004132 final long identity = Binder.clearCallingIdentity();
4133 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004134 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004135 } finally {
4136 Binder.restoreCallingIdentity(identity);
4137 }
Wink Saville36469e72014-06-11 15:17:00 -07004138 }
4139
Brad Ebinger51f743a2017-01-23 13:50:20 -08004140 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004141 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4142 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004143 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004144 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004145 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004146
4147 final long identity = Binder.clearCallingIdentity();
4148 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004149 ImsResolver resolver = PhoneFactory.getImsResolver();
4150 if (resolver == null) {
4151 // may happen if the device does not support IMS.
4152 return;
4153 }
4154 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004155 } finally {
4156 Binder.restoreCallingIdentity(identity);
4157 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004158 }
4159
4160 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004161 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4162 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004163 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004164 public void disableIms(int slotId) {
4165 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004166
4167 final long identity = Binder.clearCallingIdentity();
4168 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004169 ImsResolver resolver = PhoneFactory.getImsResolver();
4170 if (resolver == null) {
4171 // may happen if the device does not support IMS.
4172 return;
4173 }
4174 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004178 }
4179
4180 /**
4181 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4182 * feature or {@link null} if the service is not available. If the feature is available, the
4183 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4184 */
4185 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004186 IImsServiceFeatureCallback callback) {
4187 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004188
4189 final long identity = Binder.clearCallingIdentity();
4190 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004191 ImsResolver resolver = PhoneFactory.getImsResolver();
4192 if (resolver == null) {
4193 // may happen if the device does not support IMS.
4194 return null;
4195 }
4196 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004197 } finally {
4198 Binder.restoreCallingIdentity(identity);
4199 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004200 }
4201
4202 /**
4203 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4204 * feature during emergency calling or {@link null} if the service is not available. If the
4205 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4206 * listener for feature updates.
4207 */
4208 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4209 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004210
4211 final long identity = Binder.clearCallingIdentity();
4212 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004213 ImsResolver resolver = PhoneFactory.getImsResolver();
4214 if (resolver == null) {
4215 // may happen if the device does not support IMS.
4216 return null;
4217 }
4218 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004222 }
4223
Brad Ebinger5f64b052017-12-14 14:26:15 -08004224 /**
4225 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004226 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004227 */
4228 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4229 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004230
4231 final long identity = Binder.clearCallingIdentity();
4232 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004233 ImsResolver resolver = PhoneFactory.getImsResolver();
4234 if (resolver == null) {
4235 // may happen if the device does not support IMS.
4236 return null;
4237 }
4238 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004242 }
4243
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004244 /**
4245 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004246 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004247 */
4248 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4249 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004250
4251 final long identity = Binder.clearCallingIdentity();
4252 try {
Brad Ebingereb160e22019-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.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004262 }
4263
Brad Ebinger884c07b2018-02-15 16:17:40 -08004264 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004265 * Sets the ImsService Package Name that Telephony will bind to.
4266 *
4267 * @param slotId the slot ID that the ImsService should bind for.
4268 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4269 * ImsService is the device default ImsService.
4270 * @param packageName The package name of the application that contains the ImsService to bind
4271 * to.
4272 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4273 * @hide
4274 */
4275 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004276 int[] subIds = SubscriptionManager.getSubId(slotId);
4277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4278 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4279 "setImsService");
4280
Malcolm Chend965c8b2018-02-28 15:00:40 -08004281 final long identity = Binder.clearCallingIdentity();
4282 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004283 ImsResolver resolver = PhoneFactory.getImsResolver();
4284 if (resolver == null) {
4285 // may happen if the device does not support IMS.
4286 return false;
4287 }
4288 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4289 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004293 }
4294
4295 /**
4296 * Return the ImsService configuration.
4297 *
4298 * @param slotId The slot that the ImsService is associated with.
4299 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4300 * the device default.
4301 * @return the package name of the ImsService configuration.
4302 */
4303 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004304 int[] subIds = SubscriptionManager.getSubId(slotId);
4305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4306 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4307 "getImsService");
4308
Malcolm Chend965c8b2018-02-28 15:00:40 -08004309 final long identity = Binder.clearCallingIdentity();
4310 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004311 ImsResolver resolver = PhoneFactory.getImsResolver();
4312 if (resolver == null) {
4313 // may happen if the device does not support IMS.
4314 return "";
4315 }
4316 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004320 }
4321
Wink Saville36469e72014-06-11 15:17:00 -07004322 public void setImsRegistrationState(boolean registered) {
4323 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004324
4325 final long identity = Binder.clearCallingIdentity();
4326 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004327 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
Wink Saville36469e72014-06-11 15:17:00 -07004331 }
4332
4333 /**
Stuart Scott54788802015-03-30 13:18:01 -07004334 * Set the network selection mode to automatic.
4335 *
4336 */
4337 @Override
4338 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4340 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004341
Pengquan Meng466e2482018-09-21 15:54:48 -07004342 if (!isActiveSubscription(subId)) {
4343 return;
4344 }
4345
Malcolm Chend965c8b2018-02-28 15:00:40 -08004346 final long identity = Binder.clearCallingIdentity();
4347 try {
4348 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4349 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
Stuart Scott54788802015-03-30 13:18:01 -07004353 }
4354
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004355 /**
4356 * Ask the radio to connect to the input network and change selection mode to manual.
4357 *
4358 * @param subId the id of the subscription.
4359 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4360 * the operator to attach to.
4361 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4362 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4363 * normal network selection next time.
4364 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004365 */
4366 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004367 public boolean setNetworkSelectionModeManual(
4368 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4370 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004371
4372 if (!isActiveSubscription(subId)) {
4373 return false;
4374 }
4375
Malcolm Chend965c8b2018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004378 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004379 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004380 if (DBG) {
4381 log("setNetworkSelectionModeManual: subId: " + subId
4382 + " operator: " + operatorInfo);
4383 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004384 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004388 }
4389
4390 /**
4391 * Scans for available networks.
4392 */
4393 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004394 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4396 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004397 LocationAccessPolicy.LocationPermissionResult locationResult =
4398 LocationAccessPolicy.checkLocationPermission(mApp,
4399 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4400 .setCallingPackage(callingPackage)
4401 .setCallingPid(Binder.getCallingPid())
4402 .setCallingUid(Binder.getCallingUid())
4403 .setMethod("getCellNetworkScanResults")
4404 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4405 .build());
4406 switch (locationResult) {
4407 case DENIED_HARD:
4408 throw new SecurityException("Not allowed to access scan results -- location");
4409 case DENIED_SOFT:
4410 return null;
4411 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004412
Pengquan Meng0c05b502018-09-06 09:59:22 -07004413 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004414 try {
4415 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004416 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004417 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004418 } finally {
4419 Binder.restoreCallingIdentity(identity);
4420 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004421 }
4422
4423 /**
yinxub1bed742017-04-17 11:45:04 -07004424 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004425 *
yinxub1bed742017-04-17 11:45:04 -07004426 * @param subId id of the subscription
4427 * @param request contains the radio access networks with bands/channels to scan
4428 * @param messenger callback messenger for scan results or errors
4429 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004430 * @return the id of the requested scan which can be used to stop the scan.
4431 */
4432 @Override
4433 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004434 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4436 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004437 LocationAccessPolicy.LocationPermissionResult locationResult =
4438 LocationAccessPolicy.checkLocationPermission(mApp,
4439 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4440 .setCallingPackage(callingPackage)
4441 .setCallingPid(Binder.getCallingPid())
4442 .setCallingUid(Binder.getCallingUid())
4443 .setMethod("requestNetworkScan")
4444 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4445 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004446 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4447 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4448 if (e != null) {
4449 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4450 throw e;
4451 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004452 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004453 return TelephonyScanManager.INVALID_SCAN_ID;
4454 }
4455 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004456 }
Hall Liubac7d482019-04-25 14:02:26 -07004457 int callingUid = Binder.getCallingUid();
4458 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004459 final long identity = Binder.clearCallingIdentity();
4460 try {
4461 return mNetworkScanRequestTracker.startNetworkScan(
4462 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004463 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
yinxu504e1392017-04-12 16:03:22 -07004467 }
4468
Hall Liub2ac8ef2019-02-28 15:56:23 -08004469 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4470 NetworkScanRequest request) {
4471 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4472 != PERMISSION_GRANTED) {
4473 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4474 + " without location access.");
4475 }
4476
4477 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4478 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004479 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4480 return new SecurityException("Specific channels must not be"
4481 + " scanned without location access.");
4482 }
4483 }
4484 }
4485
Hall Liub2ac8ef2019-02-28 15:56:23 -08004486 return null;
4487 }
4488
yinxu504e1392017-04-12 16:03:22 -07004489 /**
4490 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004491 *
4492 * @param subId id of the subscription
4493 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004494 */
4495 @Override
4496 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4498 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004499
Hall Liubac7d482019-04-25 14:02:26 -07004500 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004501 final long identity = Binder.clearCallingIdentity();
4502 try {
Hall Liubac7d482019-04-25 14:02:26 -07004503 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
yinxu504e1392017-04-12 16:03:22 -07004507 }
4508
4509 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004510 * Get the calculated preferred network type.
4511 * Used for debugging incorrect network type.
4512 *
4513 * @return the preferred network type, defined in RILConstants.java.
4514 */
4515 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004516 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004517 final Phone defaultPhone = getDefaultPhone();
4518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4519 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004520 return RILConstants.PREFERRED_NETWORK_MODE;
4521 }
4522
Malcolm Chend965c8b2018-02-28 15:00:40 -08004523 final long identity = Binder.clearCallingIdentity();
4524 try {
4525 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004526 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004527 } finally {
4528 Binder.restoreCallingIdentity(identity);
4529 }
Junda Liu84d15a22014-07-02 11:21:04 -07004530 }
4531
4532 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004533 * Get the preferred network type.
4534 * Used for device configuration by some CDMA operators.
4535 *
4536 * @return the preferred network type, defined in RILConstants.java.
4537 */
4538 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004539 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004540 TelephonyPermissions
4541 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4542 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004543
4544 final long identity = Binder.clearCallingIdentity();
4545 try {
4546 if (DBG) log("getPreferredNetworkType");
4547 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4548 int networkType = (result != null ? result[0] : -1);
4549 if (DBG) log("getPreferredNetworkType: " + networkType);
4550 return networkType;
4551 } finally {
4552 Binder.restoreCallingIdentity(identity);
4553 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004554 }
4555
4556 /**
4557 * Set the preferred network type.
4558 * Used for device configuration by some CDMA operators.
4559 *
4560 * @param networkType the preferred network type, defined in RILConstants.java.
4561 * @return true on success; false on any failure.
4562 */
4563 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004564 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4566 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004567
4568 final long identity = Binder.clearCallingIdentity();
4569 try {
4570 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4571 Boolean success = (Boolean) sendRequest(
4572 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4573 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4574 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004575 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004576 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4577 }
4578 return success;
4579 } finally {
4580 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004581 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004582 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004583
4584 /**
Miaoa84611c2019-03-15 09:21:10 +08004585 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004586 *
Miaoa84611c2019-03-15 09:21:10 +08004587 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004588 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004589 * @hide
4590 */
4591 @Override
Miaoa84611c2019-03-15 09:21:10 +08004592 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004593 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004594 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004595 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004596 try {
Miaoa84611c2019-03-15 09:21:10 +08004597 if (phone != null) {
4598 return phone.hasMatchedTetherApnSetting();
4599 } else {
4600 return false;
4601 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004602 } finally {
4603 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004604 }
Junda Liu475951f2014-11-07 16:45:03 -08004605 }
4606
4607 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004608 * Set mobile data enabled
4609 * Used by the user through settings etc to turn on/off mobile data
4610 *
4611 * @param enable {@code true} turn turn data on, else {@code false}
4612 */
4613 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004614 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4616 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004617
4618 final long identity = Binder.clearCallingIdentity();
4619 try {
4620 int phoneId = mSubscriptionController.getPhoneId(subId);
4621 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4622 Phone phone = PhoneFactory.getPhone(phoneId);
4623 if (phone != null) {
4624 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004625 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004626 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004627 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004628 }
4629 } finally {
4630 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004631 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004632 }
4633
4634 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004635 * Get the user enabled state of Mobile Data.
4636 *
4637 * TODO: remove and use isUserDataEnabled.
4638 * This can't be removed now because some vendor codes
4639 * calls through ITelephony directly while they should
4640 * use TelephonyManager.
4641 *
4642 * @return true on enabled
4643 */
4644 @Override
4645 public boolean getDataEnabled(int subId) {
4646 return isUserDataEnabled(subId);
4647 }
4648
4649 /**
4650 * Get whether mobile data is enabled per user setting.
4651 *
4652 * There are other factors deciding whether mobile data is actually enabled, but they are
4653 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004654 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004655 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004656 *
4657 * @return {@code true} if data is enabled else {@code false}
4658 */
4659 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004660 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004661 try {
4662 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4663 null);
4664 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4666 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004667 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004668
4669 final long identity = Binder.clearCallingIdentity();
4670 try {
4671 int phoneId = mSubscriptionController.getPhoneId(subId);
4672 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4673 Phone phone = PhoneFactory.getPhone(phoneId);
4674 if (phone != null) {
4675 boolean retVal = phone.isUserDataEnabled();
4676 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4677 return retVal;
4678 } else {
4679 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4680 return false;
4681 }
4682 } finally {
4683 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004684 }
4685 }
4686
4687 /**
4688 * Get whether mobile data is enabled.
4689 *
4690 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4691 * whether mobile data is actually enabled.
4692 *
4693 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4694 *
4695 * @return {@code true} if data is enabled else {@code false}
4696 */
4697 @Override
4698 public boolean isDataEnabled(int subId) {
4699 try {
4700 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4701 null);
4702 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4704 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004705 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004706
4707 final long identity = Binder.clearCallingIdentity();
4708 try {
4709 int phoneId = mSubscriptionController.getPhoneId(subId);
4710 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4711 Phone phone = PhoneFactory.getPhone(phoneId);
4712 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004713 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004714 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4715 return retVal;
4716 } else {
4717 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4718 return false;
4719 }
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004722 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004723 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004724
4725 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004726 public int getCarrierPrivilegeStatus(int subId) {
4727 final Phone phone = getPhone(subId);
4728 if (phone == null) {
4729 loge("getCarrierPrivilegeStatus: Invalid subId");
4730 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4731 }
4732 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004733 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004734 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004735 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4736 }
4737 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004738 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004739 }
Junda Liu29340342014-07-10 15:23:27 -07004740
4741 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004742 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4743 final Phone phone = getPhone(subId);
4744 if (phone == null) {
4745 loge("getCarrierPrivilegeStatus: Invalid subId");
4746 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4747 }
4748 UiccProfile profile =
4749 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4750 if (profile == null) {
4751 loge("getCarrierPrivilegeStatus: No UICC");
4752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4753 }
4754 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4755 }
4756
4757 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004758 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004759 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004760 if (TextUtils.isEmpty(pkgName))
4761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004762 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004763 if (card == null) {
4764 loge("checkCarrierPrivilegesForPackage: No UICC");
4765 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4766 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004767 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4768 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004769 }
4770
4771 @Override
4772 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004773 if (TextUtils.isEmpty(pkgName))
4774 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004775 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4776 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4777 UiccCard card = UiccController.getInstance().getUiccCard(i);
4778 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004779 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004780 continue;
4781 }
4782
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004783 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004784 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4785 break;
4786 }
4787 }
4788
4789 return result;
Junda Liu29340342014-07-10 15:23:27 -07004790 }
Derek Tan89e89d42014-07-08 17:00:10 -07004791
4792 @Override
Junda Liue64de782015-04-16 17:19:16 -07004793 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4794 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4795 loge("phoneId " + phoneId + " is not valid.");
4796 return null;
4797 }
4798 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004799 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004800 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004801 return null ;
4802 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004803 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004804 }
4805
Amith Yamasani6e118872016-02-19 12:53:51 -08004806 @Override
4807 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004808 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004809 List<String> privilegedPackages = new ArrayList<>();
4810 List<PackageInfo> packages = null;
4811 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4812 UiccCard card = UiccController.getInstance().getUiccCard(i);
4813 if (card == null) {
4814 // No UICC in that slot.
4815 continue;
4816 }
4817 if (card.hasCarrierPrivilegeRules()) {
4818 if (packages == null) {
4819 // Only check packages in user 0 for now
4820 packages = pm.getInstalledPackagesAsUser(
4821 PackageManager.MATCH_DISABLED_COMPONENTS
4822 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4823 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4824 }
4825 for (int p = packages.size() - 1; p >= 0; p--) {
4826 PackageInfo pkgInfo = packages.get(p);
4827 if (pkgInfo != null && pkgInfo.packageName != null
4828 && card.getCarrierPrivilegeStatus(pkgInfo)
4829 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4830 privilegedPackages.add(pkgInfo.packageName);
4831 }
4832 }
4833 }
4834 }
4835 return privilegedPackages;
4836 }
4837
Wink Savilleb564aae2014-10-23 10:18:09 -07004838 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004839 final Phone phone = getPhone(subId);
4840 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004841 if (card == null) {
4842 loge("getIccId: No UICC");
4843 return null;
4844 }
4845 String iccId = card.getIccId();
4846 if (TextUtils.isEmpty(iccId)) {
4847 loge("getIccId: ICC ID is null or empty.");
4848 return null;
4849 }
4850 return iccId;
4851 }
4852
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004853 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004854 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4855 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004856 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4857 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004858
Malcolm Chend965c8b2018-02-28 15:00:40 -08004859 final long identity = Binder.clearCallingIdentity();
4860 try {
4861 final String iccId = getIccId(subId);
4862 final Phone phone = getPhone(subId);
4863 if (phone == null) {
4864 return false;
4865 }
4866 final String subscriberId = phone.getSubscriberId();
4867
4868 if (DBG_MERGE) {
4869 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4870 + subscriberId + " to " + number);
4871 }
4872
4873 if (TextUtils.isEmpty(iccId)) {
4874 return false;
4875 }
4876
4877 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4878
4879 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4880 if (alphaTag == null) {
4881 editor.remove(alphaTagPrefKey);
4882 } else {
4883 editor.putString(alphaTagPrefKey, alphaTag);
4884 }
4885
4886 // Record both the line number and IMSI for this ICCID, since we need to
4887 // track all merged IMSIs based on line number
4888 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4889 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4890 if (number == null) {
4891 editor.remove(numberPrefKey);
4892 editor.remove(subscriberPrefKey);
4893 } else {
4894 editor.putString(numberPrefKey, number);
4895 editor.putString(subscriberPrefKey, subscriberId);
4896 }
4897
4898 editor.commit();
4899 return true;
4900 } finally {
4901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004902 }
Derek Tan7226c842014-07-02 17:42:23 -07004903 }
4904
4905 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004906 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004907 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004909 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004910 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004911 return null;
4912 }
Derek Tan97ebb422014-09-05 16:55:38 -07004913
Malcolm Chend965c8b2018-02-28 15:00:40 -08004914 final long identity = Binder.clearCallingIdentity();
4915 try {
4916 String iccId = getIccId(subId);
4917 if (iccId != null) {
4918 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4919 if (DBG_MERGE) {
4920 log("getLine1NumberForDisplay returning "
4921 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4922 }
4923 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004924 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004925 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4926 return null;
4927 } finally {
4928 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004929 }
Derek Tan7226c842014-07-02 17:42:23 -07004930 }
4931
4932 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004933 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004935 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004936 return null;
4937 }
Derek Tan97ebb422014-09-05 16:55:38 -07004938
Malcolm Chend965c8b2018-02-28 15:00:40 -08004939 final long identity = Binder.clearCallingIdentity();
4940 try {
4941 String iccId = getIccId(subId);
4942 if (iccId != null) {
4943 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4944 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4945 }
4946 return null;
4947 } finally {
4948 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004949 }
Derek Tan7226c842014-07-02 17:42:23 -07004950 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004951
4952 @Override
Jordan Liu9775d4b2019-05-06 14:45:15 -07004953 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004954 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4955 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004957 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4958 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004959 return null;
4960 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004961
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004962 final long identity = Binder.clearCallingIdentity();
4963 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004964 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004965 final TelephonyManager tele = TelephonyManager.from(context);
4966 final SubscriptionManager sub = SubscriptionManager.from(context);
4967
4968 // Figure out what subscribers are currently active
4969 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4970 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4971 // the process, where TelephonyManager was instantiated.
4972 // Otherwise AppOps check will fail.
4973
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004974 final int[] subIds = sub.getActiveSubscriptionIdList();
Jordan Liu9775d4b2019-05-06 14:45:15 -07004975 for (int id : subIds) {
4976 // Only consider subs which match the current subId
4977 // This logic can be simplified. See b/131189269 for progress.
4978 if (subId != id) {
4979 continue;
4980 }
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004981 activeSubscriberIds.add(tele.getSubscriberId(subId));
4982 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004983
4984 // First pass, find a number override for an active subscriber
4985 String mergeNumber = null;
4986 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4987 for (String key : prefs.keySet()) {
4988 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4989 final String subscriberId = (String) prefs.get(key);
4990 if (activeSubscriberIds.contains(subscriberId)) {
4991 final String iccId = key.substring(
4992 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4993 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4994 mergeNumber = (String) prefs.get(numberKey);
4995 if (DBG_MERGE) {
4996 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4997 + " for active subscriber " + subscriberId);
4998 }
4999 if (!TextUtils.isEmpty(mergeNumber)) {
5000 break;
5001 }
5002 }
5003 }
5004 }
5005
5006 // Shortcut when no active merged subscribers
5007 if (TextUtils.isEmpty(mergeNumber)) {
5008 return null;
5009 }
5010
5011 // Second pass, find all subscribers under that line override
5012 final ArraySet<String> result = new ArraySet<>();
5013 for (String key : prefs.keySet()) {
5014 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5015 final String number = (String) prefs.get(key);
5016 if (mergeNumber.equals(number)) {
5017 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5018 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5019 final String subscriberId = (String) prefs.get(subscriberKey);
5020 if (!TextUtils.isEmpty(subscriberId)) {
5021 result.add(subscriberId);
5022 }
5023 }
5024 }
5025 }
5026
5027 final String[] resultArray = result.toArray(new String[result.size()]);
5028 Arrays.sort(resultArray);
5029 if (DBG_MERGE) {
5030 Slog.d(LOG_TAG,
5031 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5032 }
5033 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005034 } finally {
5035 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005036 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005037 }
5038
5039 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005040 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005041 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5042 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005043
5044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 final Phone phone = getPhone(subId);
5047 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5048 } finally {
5049 Binder.restoreCallingIdentity(identity);
5050 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005051 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005052
5053 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005054 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005055 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5056 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005057 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005058
5059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 final Phone phone = getPhone(subId);
5062 if (phone == null) {
5063 return false;
5064 }
5065 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5066 cdmaNonRoamingList);
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005069 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005070 }
5071
5072 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005073 @Deprecated
5074 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5075 enforceModifyPermission();
5076
5077 int returnValue = 0;
5078 try {
vagdevie435a3e2018-08-15 16:01:53 -07005079 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005080 if(result.exception == null) {
5081 if (result.result != null) {
5082 byte[] responseData = (byte[])(result.result);
5083 if(responseData.length > oemResp.length) {
5084 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5085 responseData.length + "bytes. Buffer Size is " +
5086 oemResp.length + "bytes.");
5087 }
5088 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5089 returnValue = responseData.length;
5090 }
5091 } else {
5092 CommandException ex = (CommandException) result.exception;
5093 returnValue = ex.getCommandError().ordinal();
5094 if(returnValue > 0) returnValue *= -1;
5095 }
5096 } catch (RuntimeException e) {
5097 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5098 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5099 if(returnValue > 0) returnValue *= -1;
5100 }
5101
5102 return returnValue;
5103 }
5104
5105 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005106 public void setRadioCapability(RadioAccessFamily[] rafs) {
5107 try {
5108 ProxyController.getInstance().setRadioCapability(rafs);
5109 } catch (RuntimeException e) {
5110 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5111 }
5112 }
5113
5114 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005115 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005116 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005117 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005118 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005119 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005120 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
chen xufeeed752018-10-26 14:17:57 -07005123 TelephonyPermissions
5124 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5125 mApp, phone.getSubId(), "getRadioAccessFamily");
5126 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005127 } finally {
5128 Binder.restoreCallingIdentity(identity);
5129 }
chen xufeeed752018-10-26 14:17:57 -07005130 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005131 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005132
5133 @Override
5134 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005135 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005136 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005137
5138 final long identity = Binder.clearCallingIdentity();
5139 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005140 ImsManager.getInstance(defaultPhone.getContext(),
5141 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005142 } finally {
5143 Binder.restoreCallingIdentity(identity);
5144 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005145 }
5146
5147 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005148 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005149 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005151 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005152 return false;
5153 }
Svet Ganovb320e182015-04-16 12:30:10 -07005154
Malcolm Chend965c8b2018-02-28 15:00:40 -08005155 final long identity = Binder.clearCallingIdentity();
5156 try {
5157 // Check the user preference and the system-level IMS setting. Even if the user has
5158 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5159 // In the long run, we may instead need to check if there exists a connection service
5160 // which can support video calling.
5161 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005162 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005163 return imsManager.isVtEnabledByPlatform()
5164 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5165 && imsManager.isVtEnabledByUser();
5166 } finally {
5167 Binder.restoreCallingIdentity(identity);
5168 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005169 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005170
Andrew Leea1239f22015-03-02 17:44:07 -08005171 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005172 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5174 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5175 return false;
5176 }
5177
5178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 CarrierConfigManager configManager =
5181 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005182 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005183 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
Andrew Leea1239f22015-03-02 17:44:07 -08005187 }
5188
5189 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005190 public boolean isWorldPhone(int subId, String callingPackage) {
5191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5192 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5193 return false;
5194 }
5195
5196 final long identity = Binder.clearCallingIdentity();
5197 try {
5198 CarrierConfigManager configManager =
5199 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005200 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005201 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5202 } finally {
5203 Binder.restoreCallingIdentity(identity);
5204 }
Andrew Leea1239f22015-03-02 17:44:07 -08005205 }
5206
Andrew Lee9431b832015-03-09 18:46:45 -07005207 @Override
5208 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005209 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005210 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005211 }
5212
5213 @Override
5214 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005215 final long identity = Binder.clearCallingIdentity();
5216 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005217 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Andrew Lee9431b832015-03-09 18:46:45 -07005221 }
5222
Hall Liuf6668912018-10-31 17:05:23 -07005223 /**
5224 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5225 * support for the feature and device firmware support.
5226 *
5227 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5228 */
5229 @Override
5230 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005231 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005232 final Phone phone = getPhone(subscriptionId);
5233 if (phone == null) {
5234 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5235 return false;
5236 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005237 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005238 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005239 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5240 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005241 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005242 return isCarrierSupported && isDeviceSupported;
5243 } finally {
5244 Binder.restoreCallingIdentity(identity);
5245 }
Hall Liu98187582018-01-22 19:15:32 -08005246 }
5247
Hall Liuf6668912018-10-31 17:05:23 -07005248 /**
5249 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5250 * both also support RTT.
5251 */
5252 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005253 final long identity = Binder.clearCallingIdentity();
5254 try {
Hall Liuf6668912018-10-31 17:05:23 -07005255 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005256 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005260 }
5261
Sanket Padawe7310cc72015-01-14 09:53:20 -08005262 /**
5263 * Returns the unique device ID of phone, for example, the IMEI for
5264 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5265 *
5266 * <p>Requires Permission:
5267 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5268 */
5269 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005270 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005271 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005272 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005273 return null;
5274 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005275 int subId = phone.getSubId();
5276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5277 mApp, subId, callingPackage, "getDeviceId")) {
5278 return null;
5279 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005280
5281 final long identity = Binder.clearCallingIdentity();
5282 try {
5283 return phone.getDeviceId();
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005287 }
5288
Ping Sunc67b7c22016-03-02 19:16:45 +08005289 /**
5290 * {@hide}
5291 * Returns the IMS Registration Status on a particular subid
5292 *
5293 * @param subId
5294 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005295 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005296 Phone phone = getPhone(subId);
5297 if (phone != null) {
5298 return phone.isImsRegistered();
5299 } else {
5300 return false;
5301 }
5302 }
5303
Santos Cordon7a1885b2015-02-03 11:15:19 -08005304 @Override
5305 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005306 final long identity = Binder.clearCallingIdentity();
5307 try {
5308 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005312 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005313
Tyler Gunn327a9722019-04-03 15:28:53 -07005314 @Override
5315 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5316 final long identity = Binder.clearCallingIdentity();
5317 try {
5318 Phone phone = getPhone(subscriptionId);
5319 if (phone == null) {
5320 return null;
5321 }
5322 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
5326 }
5327
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005328 /**
5329 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005330 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005331 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 Phone phone = getPhone(subId);
5335 if (phone != null) {
5336 return phone.isWifiCallingEnabled();
5337 } else {
5338 return false;
5339 }
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005342 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005343 }
5344
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005345 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005346 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005347 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005348 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005349 final long identity = Binder.clearCallingIdentity();
5350 try {
5351 Phone phone = getPhone(subId);
5352 if (phone != null) {
5353 return phone.isVideoEnabled();
5354 } else {
5355 return false;
5356 }
5357 } finally {
5358 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005359 }
5360 }
5361
5362 /**
5363 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5364 * defined in {@link ImsRegistrationImplBase}.
5365 */
5366 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005367 final long identity = Binder.clearCallingIdentity();
5368 try {
5369 Phone phone = getPhone(subId);
5370 if (phone != null) {
5371 return phone.getImsRegistrationTech();
5372 } else {
5373 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5374 }
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005377 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005378 }
5379
Stuart Scott8eef64f2015-04-08 15:13:54 -07005380 @Override
5381 public void factoryReset(int subId) {
5382 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005383 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5384 return;
5385 }
5386
Svet Ganovcc087f82015-05-12 20:35:54 -07005387 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005388
Svet Ganovcc087f82015-05-12 20:35:54 -07005389 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005390 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5391 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005392 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005393 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005394 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005395 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5396 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005397 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005398 // There has been issues when Sms raw table somehow stores orphan
5399 // fragments. They lead to garbled message when new fragments come
5400 // in and combined with those stale ones. In case this happens again,
5401 // user can reset all network settings which will clean up this table.
5402 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005403 } finally {
5404 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005405 }
5406 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005407
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005408 private void cleanUpSmsRawTable(Context context) {
5409 ContentResolver resolver = context.getContentResolver();
5410 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5411 resolver.delete(uri, null, null);
5412 }
5413
Narayan Kamath1c496c22015-04-16 14:40:19 +01005414 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005415 public String getSimLocaleForSubscriber(int subId) {
5416 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5417 final Phone phone = getPhone(subId);
5418 if (phone == null) {
5419 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005420 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005421 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005422 final long identity = Binder.clearCallingIdentity();
5423 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005424 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5425 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005426 // Try and fetch the locale from the carrier properties or from the SIM language
5427 // preferences (EF-PL and EF-LI)...
5428 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005429 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005430 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5431 if (localeFromDefaultSim != null) {
5432 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5433 if (DBG) log("Using locale from subId: " + subId + " locale: "
5434 + localeFromDefaultSim);
5435 return localeFromDefaultSim.toLanguageTag();
5436 } else {
5437 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005438 }
5439 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005440
Malcolm Chend965c8b2018-02-28 15:00:40 -08005441 // The SIM language preferences only store a language (e.g. fr = French), not an
5442 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5443 // the SIM and carrier preferences does not include a country we add the country
5444 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005445 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005446 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005447 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005448 return mccLocale.toLanguageTag();
5449 }
5450
5451 if (DBG) log("No locale found - returning null");
5452 return null;
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
5455 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005456 }
5457
5458 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005459 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005460 }
5461
Malcolm Chend965c8b2018-02-28 15:00:40 -08005462 /**
5463 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5464 */
5465 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005466 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005467 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005468
Chenjie Yu1ba97252018-01-11 18:16:20 -08005469 private final ModemActivityInfo mLastModemActivityInfo =
5470 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5471
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005472 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005473 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5474 * representing the state of the modem.
5475 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005476 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5477 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005478 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005479 */
5480 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005481 public void requestModemActivityInfo(ResultReceiver result) {
5482 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005483 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005484
5485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 ModemActivityInfo ret = null;
5488 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005489 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5490 CMD_GET_MODEM_ACTIVITY_INFO,
5491 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005492 if (isModemActivityInfoValid(info)) {
5493 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5494 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5495 mergedTxTimeMs[i] =
5496 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5497 }
5498 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5499 mLastModemActivityInfo.setSleepTimeMillis(
5500 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5501 mLastModemActivityInfo.setIdleTimeMillis(
5502 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5503 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5504 mLastModemActivityInfo.setRxTimeMillis(
5505 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5506 mLastModemActivityInfo.setEnergyUsed(
5507 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005508 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005509 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5510 mLastModemActivityInfo.getSleepTimeMillis(),
5511 mLastModemActivityInfo.getIdleTimeMillis(),
5512 mLastModemActivityInfo.getTxTimeMillis(),
5513 mLastModemActivityInfo.getRxTimeMillis(),
5514 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005515 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005516 Bundle bundle = new Bundle();
5517 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5518 result.send(0, bundle);
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005521 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005522 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005523
Siddharth Rayf5d29552018-06-17 15:02:38 -07005524 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5525 // less than total activity duration.
5526 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5527 if (info == null) {
5528 return false;
5529 }
5530 int activityDurationMs =
5531 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5532 int totalTxTimeMs = 0;
5533 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5534 totalTxTimeMs += info.getTxTimeMillis()[i];
5535 }
5536 return (info.isValid()
5537 && (info.getSleepTimeMillis() <= activityDurationMs)
5538 && (info.getIdleTimeMillis() <= activityDurationMs)
5539 && (info.getRxTimeMillis() <= activityDurationMs)
5540 && (totalTxTimeMs <= activityDurationMs));
5541 }
5542
Jack Yu85bd38a2015-11-09 11:34:32 -08005543 /**
5544 * {@hide}
5545 * Returns the service state information on specified subscription.
5546 */
5547 @Override
5548 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005550 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005551 return null;
5552 }
5553
Hall Liuf19c44f2018-11-27 14:38:17 -08005554 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5555 LocationAccessPolicy.checkLocationPermission(mApp,
5556 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5557 .setCallingPackage(callingPackage)
5558 .setCallingPid(Binder.getCallingPid())
5559 .setCallingUid(Binder.getCallingUid())
5560 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005561 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005562 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5563 .build());
5564
5565 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5566 LocationAccessPolicy.checkLocationPermission(mApp,
5567 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5568 .setCallingPackage(callingPackage)
5569 .setCallingPid(Binder.getCallingPid())
5570 .setCallingUid(Binder.getCallingUid())
5571 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005572 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005573 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5574 .build());
5575 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5576 boolean hasFinePermission =
5577 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5578 boolean hasCoarsePermission =
5579 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5580
Malcolm Chend965c8b2018-02-28 15:00:40 -08005581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 final Phone phone = getPhone(subId);
5584 if (phone == null) {
5585 return null;
5586 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005587
Hall Liuf19c44f2018-11-27 14:38:17 -08005588 ServiceState ss = phone.getServiceState();
5589
5590 // Scrub out the location info in ServiceState depending on what level of access
5591 // the caller has.
5592 if (hasFinePermission) return ss;
5593 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5594 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005598 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005599
5600 /**
5601 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5602 *
5603 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5604 * voicemail ringtone.
5605 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5606 * PhoneAccount.
5607 */
5608 @Override
5609 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005610 final long identity = Binder.clearCallingIdentity();
5611 try {
5612 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5613 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005614 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005615 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005616
Malcolm Chend965c8b2018-02-28 15:00:40 -08005617 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5618 } finally {
5619 Binder.restoreCallingIdentity(identity);
5620 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005621 }
5622
5623 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005624 * Sets the per-account voicemail ringtone.
5625 *
5626 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5627 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5628 *
5629 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5630 * voicemail ringtone.
5631 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5632 * PhoneAccount.
5633 */
5634 @Override
5635 public void setVoicemailRingtoneUri(String callingPackage,
5636 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005637 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005638 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5639 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005640 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5642 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5643 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005644 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005645
5646 final long identity = Binder.clearCallingIdentity();
5647 try {
5648 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5649 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005650 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005651 }
5652 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005655 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005656 }
5657
5658 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005659 * Returns whether vibration is set for voicemail notification in Phone settings.
5660 *
5661 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5662 * voicemail vibration setting.
5663 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5664 */
5665 @Override
5666 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5670 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005671 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005672 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005673
Malcolm Chend965c8b2018-02-28 15:00:40 -08005674 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005678 }
5679
Youhan Wange64578a2016-05-02 15:32:42 -07005680 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005681 * Sets the per-account voicemail vibration.
5682 *
5683 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5684 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5685 *
5686 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5687 * voicemail vibration setting.
5688 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5689 * specific PhoneAccount.
5690 */
5691 @Override
5692 public void setVoicemailVibrationEnabled(String callingPackage,
5693 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005694 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5696 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005697 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5699 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5700 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005701 }
5702
Malcolm Chend965c8b2018-02-28 15:00:40 -08005703 final long identity = Binder.clearCallingIdentity();
5704 try {
5705 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5706 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005707 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005708 }
5709 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5710 } finally {
5711 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005712 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005713 }
5714
5715 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005716 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5717 *
5718 * @throws SecurityException if the caller does not have the required permission
5719 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005720 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005721 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005722 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005723 }
5724
5725 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005726 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5727 * permission.
5728 *
5729 * @throws SecurityException if the caller does not have the required permission
5730 */
5731 private void enforceSendSmsPermission() {
5732 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5733 }
5734
5735 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005736 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005737 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005738 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005739 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005740 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005741 final long identity = Binder.clearCallingIdentity();
5742 try {
5743 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005744 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005745 if (componentName == null) {
5746 throw new SecurityException(
5747 "Caller not current active visual voicemail package[null]");
5748 }
5749 String vvmPackage = componentName.getPackageName();
5750 if (!callingPackage.equals(vvmPackage)) {
5751 throw new SecurityException("Caller not current active visual voicemail package["
5752 + vvmPackage + "]");
5753 }
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005756 }
5757 }
5758
5759 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005760 * Return the application ID for the app type.
5761 *
5762 * @param subId the subscription ID that this request applies to.
5763 * @param appType the uicc app type.
5764 * @return Application ID for specificied app type, or null if no uicc.
5765 */
5766 @Override
5767 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005768 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005769 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005770
5771 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005772 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005773 if (phone == null) {
5774 return null;
5775 }
5776 String aid = null;
5777 try {
5778 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5779 .getApplicationByType(appType).getAid();
5780 } catch (Exception e) {
5781 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5782 }
5783 return aid;
5784 } finally {
5785 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005786 }
Youhan Wange64578a2016-05-02 15:32:42 -07005787 }
5788
Youhan Wang4001d252016-05-11 10:29:41 -07005789 /**
5790 * Return the Electronic Serial Number.
5791 *
5792 * @param subId the subscription ID that this request applies to.
5793 * @return ESN or null if error.
5794 */
5795 @Override
5796 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005797 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005798 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005799
5800 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005801 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005802 if (phone == null) {
5803 return null;
5804 }
5805 String esn = null;
5806 try {
5807 esn = phone.getEsn();
5808 } catch (Exception e) {
5809 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5810 }
5811 return esn;
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005814 }
Youhan Wang4001d252016-05-11 10:29:41 -07005815 }
5816
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005817 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005818 * Return the Preferred Roaming List Version.
5819 *
5820 * @param subId the subscription ID that this request applies to.
5821 * @return PRLVersion or null if error.
5822 */
5823 @Override
5824 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005825 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005826 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005827
5828 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005829 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005830 if (phone == null) {
5831 return null;
5832 }
5833 String cdmaPrlVersion = null;
5834 try {
5835 cdmaPrlVersion = phone.getCdmaPrlVersion();
5836 } catch (Exception e) {
5837 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5838 }
5839 return cdmaPrlVersion;
5840 } finally {
5841 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005842 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005843 }
5844
5845 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005846 * Get snapshot of Telephony histograms
5847 * @return List of Telephony histograms
5848 * @hide
5849 */
5850 @Override
5851 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5853 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005854
5855 final long identity = Binder.clearCallingIdentity();
5856 try {
5857 return RIL.getTelephonyRILTimingHistograms();
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005861 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005862
5863 /**
5864 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005865 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5866 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005867 * Require system privileges. In the future we may add this to carrier APIs.
5868 *
Michele Berionne0963c862018-11-27 18:57:59 -08005869 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005870 */
5871 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005872 @TelephonyManager.SetCarrierRestrictionResult
5873 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005874 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005875 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005876
Michele Berionne0963c862018-11-27 18:57:59 -08005877 if (carrierRestrictionRules == null) {
5878 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005879 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005880
Malcolm Chend965c8b2018-02-28 15:00:40 -08005881 final long identity = Binder.clearCallingIdentity();
5882 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005883 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005884 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005888 }
5889
5890 /**
5891 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005892 * Get the allowed carrier list and the excluded carrier list, including the priority between
5893 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005894 * Require system privileges. In the future we may add this to carrier APIs.
5895 *
Michele Berionne0963c862018-11-27 18:57:59 -08005896 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005897 */
5898 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005899 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005900 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005901 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005902
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005905 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5906 if (response instanceof CarrierRestrictionRules) {
5907 return (CarrierRestrictionRules) response;
5908 }
5909 // Response is an Exception of some kind,
5910 // which is signalled to the user as a NULL retval
5911 return null;
5912 } catch (Exception e) {
5913 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5914 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005918 }
5919
fionaxu59545b42016-05-25 15:53:37 -07005920 /**
5921 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5922 * @param subId the subscription ID that this action applies to.
5923 * @param enabled control enable or disable metered apns.
5924 * {@hide}
5925 */
5926 @Override
5927 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5928 enforceModifyPermission();
5929 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005930
5931 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005932 if (phone == null) {
5933 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5934 return;
5935 }
5936 try {
5937 phone.carrierActionSetMeteredApnsEnabled(enabled);
5938 } catch (Exception e) {
5939 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005940 } finally {
5941 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005942 }
5943 }
5944
5945 /**
5946 * Action set from carrier signalling broadcast receivers to enable/disable radio
5947 * @param subId the subscription ID that this action applies to.
5948 * @param enabled control enable or disable radio.
5949 * {@hide}
5950 */
5951 @Override
5952 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5953 enforceModifyPermission();
5954 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005955
5956 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005957 if (phone == null) {
5958 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5959 return;
5960 }
5961 try {
5962 phone.carrierActionSetRadioEnabled(enabled);
5963 } catch (Exception e) {
5964 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005967 }
5968 }
5969
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005970 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005971 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5972 * network status based on which carrier apps could apply actions accordingly,
5973 * enable/disable default url handler for example.
5974 *
5975 * @param subId the subscription ID that this action applies to.
5976 * @param report control start/stop reporting the default network status.
5977 * {@hide}
5978 */
5979 @Override
5980 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5981 enforceModifyPermission();
5982 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005983
5984 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005985 if (phone == null) {
5986 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5987 return;
5988 }
5989 try {
5990 phone.carrierActionReportDefaultNetworkStatus(report);
5991 } catch (Exception e) {
5992 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005993 } finally {
5994 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005995 }
5996 }
5997
5998 /**
fionaxud9622282017-07-17 17:51:30 -07005999 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6000 * @param subId the subscription ID that this action applies to.
6001 * {@hide}
6002 */
6003 @Override
6004 public void carrierActionResetAll(int subId) {
6005 enforceModifyPermission();
6006 final Phone phone = getPhone(subId);
6007 if (phone == null) {
6008 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6009 return;
6010 }
6011 try {
6012 phone.carrierActionResetAll();
6013 } catch (Exception e) {
6014 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6015 }
6016 }
6017
6018 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006019 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6020 * bug report is being generated.
6021 */
6022 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006023 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006024 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6025 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006026 writer.println("Permission Denial: can't dump Phone from pid="
6027 + Binder.getCallingPid()
6028 + ", uid=" + Binder.getCallingUid()
6029 + "without permission "
6030 + android.Manifest.permission.DUMP);
6031 return;
6032 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006033 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006034 }
Jack Yueb89b242016-06-22 13:27:47 -07006035
Brad Ebingerdac2f002018-04-03 15:17:52 -07006036 @Override
6037 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6038 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6039 throws RemoteException {
6040 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6041 }
6042
Jack Yueb89b242016-06-22 13:27:47 -07006043 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006044 * Get aggregated video call data usage since boot.
6045 *
6046 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6047 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006048 * {@hide}
6049 */
6050 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006051 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006052 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6053 null);
6054
Malcolm Chend965c8b2018-02-28 15:00:40 -08006055 final long identity = Binder.clearCallingIdentity();
6056 try {
6057 // NetworkStatsService keeps tracking the active network interface and identity. It
6058 // records the delta with the corresponding network identity.
6059 // We just return the total video call data usage snapshot since boot.
6060 Phone phone = getPhone(subId);
6061 if (phone != null) {
6062 return phone.getVtDataUsage(perUidStats);
6063 }
6064 return null;
6065 } finally {
6066 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006067 }
Jack Yueb89b242016-06-22 13:27:47 -07006068 }
Jack Yu75ab2952016-07-08 14:29:33 -07006069
6070 /**
6071 * Policy control of data connection. Usually used when data limit is passed.
6072 * @param enabled True if enabling the data, otherwise disabling.
6073 * @param subId Subscription index
6074 * {@hide}
6075 */
6076 @Override
6077 public void setPolicyDataEnabled(boolean enabled, int subId) {
6078 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006079
6080 final long identity = Binder.clearCallingIdentity();
6081 try {
6082 Phone phone = getPhone(subId);
6083 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006084 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006085 }
6086 } finally {
6087 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006088 }
6089 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006090
6091 /**
6092 * Get Client request stats
6093 * @return List of Client Request Stats
6094 * @hide
6095 */
6096 @Override
6097 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006099 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006100 return null;
6101 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006102 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006103
Malcolm Chend965c8b2018-02-28 15:00:40 -08006104 final long identity = Binder.clearCallingIdentity();
6105 try {
6106 if (phone != null) {
6107 return phone.getClientRequestStats();
6108 }
6109
6110 return null;
6111 } finally {
6112 Binder.restoreCallingIdentity(identity);
6113 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006114 }
6115
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006116 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006117 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006118 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006119 }
Jack Yueb4124c2017-02-16 15:32:43 -08006120
6121 /**
Grace Chen70990072017-03-24 17:21:30 -07006122 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006123 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006124 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006125 * @param state State of SIM (power down, power up, pass through)
6126 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6127 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6128 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006129 *
6130 **/
6131 @Override
Grace Chen70990072017-03-24 17:21:30 -07006132 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006133 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006134 Phone phone = PhoneFactory.getPhone(slotIndex);
6135
vagdevie435a3e2018-08-15 16:01:53 -07006136 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6137
Malcolm Chend965c8b2018-02-28 15:00:40 -08006138 final long identity = Binder.clearCallingIdentity();
6139 try {
6140 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006141 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006142 }
6143 } finally {
6144 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006145 }
6146 }
Shuo Qiandd210312017-04-12 22:11:33 +00006147
Tyler Gunn65d45c22017-06-05 11:22:26 -07006148 private boolean isUssdApiAllowed(int subId) {
6149 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006150 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006151 if (configManager == null) {
6152 return false;
6153 }
6154 PersistableBundle pb = configManager.getConfigForSubId(subId);
6155 if (pb == null) {
6156 return false;
6157 }
6158 return pb.getBoolean(
6159 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6160 }
6161
Shuo Qiandd210312017-04-12 22:11:33 +00006162 /**
6163 * Check if phone is in emergency callback mode
6164 * @return true if phone is in emergency callback mode
6165 * @param subId sub id
6166 */
goneil9c5f4872017-12-05 14:07:56 -08006167 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006168 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006169 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006170 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006171
6172 final long identity = Binder.clearCallingIdentity();
6173 try {
6174 if (phone != null) {
6175 return phone.isInEcm();
6176 } else {
6177 return false;
6178 }
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006181 }
6182 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006183
6184 /**
6185 * Get the current signal strength information for the given subscription.
6186 * Because this information is not updated when the device is in a low power state
6187 * it should not be relied-upon to be current.
6188 * @param subId Subscription index
6189 * @return the most recent cached signal strength info from the modem
6190 */
6191 @Override
6192 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006193 final long identity = Binder.clearCallingIdentity();
6194 try {
6195 Phone p = getPhone(subId);
6196 if (p == null) {
6197 return null;
6198 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006199
Malcolm Chend965c8b2018-02-28 15:00:40 -08006200 return p.getSignalStrength();
6201 } finally {
6202 Binder.restoreCallingIdentity(identity);
6203 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006204 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006205
Pengquan Meng9140aec2018-08-22 14:49:57 -07006206 /**
chen xu907e5a22018-10-11 13:21:04 -07006207 * Get the current modem radio state for the given slot.
6208 * @param slotIndex slot index.
6209 * @param callingPackage the name of the package making the call.
6210 * @return the current radio power state from the modem
6211 */
6212 @Override
6213 public int getRadioPowerState(int slotIndex, String callingPackage) {
6214 Phone phone = PhoneFactory.getPhone(slotIndex);
6215 if (phone != null) {
6216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6217 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6218 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6219 }
6220
6221 final long identity = Binder.clearCallingIdentity();
6222 try {
6223 return phone.getRadioPowerState();
6224 } finally {
6225 Binder.restoreCallingIdentity(identity);
6226 }
6227 }
6228 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6229 }
6230
6231 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006232 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6233 *
6234 * <p>Requires one of the following permissions:
6235 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6236 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6237 * privileges.
6238 *
6239 * @param subId subscription id
6240 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6241 * {@code false}.
6242 */
6243 @Override
6244 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006245 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6246 null /* message */);
6247
Pengquan Meng0c05b502018-09-06 09:59:22 -07006248 boolean isEnabled = false;
6249 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006250 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006251 Phone phone = getPhone(subId);
6252 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006253 } catch (Exception e) {
6254 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6255 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006256 } finally {
6257 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006258 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006259 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006260 }
6261
6262
6263 /**
6264 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6265 *
6266 * <p> Requires permission:
6267 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6268 * privileges.
6269 *
6270 * @param subId subscription id
6271 * @param isEnabled {@code true} means enable, {@code false} means disable.
6272 */
6273 @Override
6274 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6276 mApp, subId, "setDataRoamingEnabled");
6277
Pengquan Meng0c05b502018-09-06 09:59:22 -07006278 final long identity = Binder.clearCallingIdentity();
6279 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006280 Phone phone = getPhone(subId);
6281 if (phone != null) {
6282 phone.setDataRoamingEnabled(isEnabled);
6283 }
6284 } finally {
6285 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006286 }
6287 }
6288
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006289 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006290 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006291 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6292 mApp, subId, "isManualNetworkSelectionAllowed");
6293
Pengquan Meng312de0c2018-10-03 12:19:13 -07006294 boolean isAllowed = true;
6295 final long identity = Binder.clearCallingIdentity();
6296 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006297 Phone phone = getPhone(subId);
6298 if (phone != null) {
6299 isAllowed = phone.isCspPlmnEnabled();
6300 }
6301 } finally {
6302 Binder.restoreCallingIdentity(identity);
6303 }
6304 return isAllowed;
6305 }
6306
6307 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006308 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006309 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006310 try {
6311 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006312 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006313 } catch (SecurityException e) {
6314 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6315 // has carrier privileges on an active UICC
6316 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6317 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006318 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006319 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006320 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006321
6322 final long identity = Binder.clearCallingIdentity();
6323 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006324 UiccController uiccController = UiccController.getInstance();
6325 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006326 if (hasReadPermission) {
6327 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006328 }
Jordan Liu67997952019-04-22 15:10:43 -07006329
6330 // Remove private info if the caller doesn't have access
6331 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6332 for (UiccCardInfo cardInfo : cardInfos) {
6333 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6334 // is available
6335 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6336 if (card == null || card.getUiccProfile() == null) {
6337 // assume no access if the card or profile is unavailable
6338 filteredInfos.add(cardInfo.getUnprivileged());
6339 continue;
6340 }
6341 UiccProfile profile = card.getUiccProfile();
6342 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6343 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6344 filteredInfos.add(cardInfo);
6345 } else {
6346 filteredInfos.add(cardInfo.getUnprivileged());
6347 }
6348 }
6349 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006350 } finally {
6351 Binder.restoreCallingIdentity(identity);
6352 }
6353 }
6354
6355 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006356 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006357 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006358
Malcolm Chend965c8b2018-02-28 15:00:40 -08006359 final long identity = Binder.clearCallingIdentity();
6360 try {
6361 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6362 if (slots == null) {
6363 Rlog.i(LOG_TAG, "slots is null.");
6364 return null;
6365 }
6366
6367 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6368 for (int i = 0; i < slots.length; i++) {
6369 UiccSlot slot = slots[i];
6370 if (slot == null) {
6371 continue;
6372 }
6373
6374 String cardId;
6375 UiccCard card = slot.getUiccCard();
6376 if (card != null) {
6377 cardId = card.getCardId();
6378 } else {
6379 cardId = slot.getIccId();
6380 }
6381
Jordan Liu857451f2019-05-09 16:35:35 -07006382 if (cardId != null) {
6383 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6384 // if cardId is an EID, it's all digits so this is fine
6385 cardId = IccUtils.stripTrailingFs(cardId);
6386 }
6387
Malcolm Chend965c8b2018-02-28 15:00:40 -08006388 int cardState = 0;
6389 switch (slot.getCardState()) {
6390 case CARDSTATE_ABSENT:
6391 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6392 break;
6393 case CARDSTATE_PRESENT:
6394 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6395 break;
6396 case CARDSTATE_ERROR:
6397 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6398 break;
6399 case CARDSTATE_RESTRICTED:
6400 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6401 break;
6402 default:
6403 break;
6404
6405 }
6406
6407 infos[i] = new UiccSlotInfo(
6408 slot.isActive(),
6409 slot.isEuicc(),
6410 cardId,
6411 cardState,
6412 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006413 slot.isExtendedApduSupported(),
6414 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006415 }
6416 return infos;
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006419 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006420 }
6421
6422 @Override
6423 public boolean switchSlots(int[] physicalSlots) {
6424 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006425
6426 final long identity = Binder.clearCallingIdentity();
6427 try {
6428 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6429 } finally {
6430 Binder.restoreCallingIdentity(identity);
6431 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006432 }
Jack Yu4c988042018-02-27 15:30:01 -08006433
6434 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006435 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 return UiccController.getInstance().getCardIdForDefaultEuicc();
6439 } finally {
6440 Binder.restoreCallingIdentity(identity);
6441 }
6442 }
6443
6444 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006445 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6446 enforceModifyPermission();
6447 final Phone phone = getPhone(subId);
6448 if (phone == null) {
6449 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6450 return;
6451 }
6452
Malcolm Chend965c8b2018-02-28 15:00:40 -08006453 final long identity = Binder.clearCallingIdentity();
6454 try {
6455 phone.setRadioIndicationUpdateMode(filters, mode);
6456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
Jack Yu4c988042018-02-27 15:30:01 -08006459 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006460
6461 /**
goneil47ffb6e2018-04-06 15:40:58 -07006462 * A test API to reload the UICC profile.
6463 *
6464 * <p>Requires that the calling app has permission
6465 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6466 * @hide
6467 */
6468 @Override
6469 public void refreshUiccProfile(int subId) {
6470 enforceModifyPermission();
6471
6472 final long identity = Binder.clearCallingIdentity();
6473 try {
6474 Phone phone = getPhone(subId);
6475 if (phone == null) {
6476 return;
6477 }
6478 UiccCard uiccCard = phone.getUiccCard();
6479 if (uiccCard == null) {
6480 return;
6481 }
6482 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6483 if (uiccProfile == null) {
6484 return;
6485 }
6486 uiccProfile.refresh();
6487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
6490 }
6491
6492 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006493 * Returns false if the mobile data is disabled by default, otherwise return true.
6494 */
6495 private boolean getDefaultDataEnabled() {
6496 return "true".equalsIgnoreCase(
6497 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6498 }
6499
6500 /**
6501 * Returns true if the data roaming is enabled by default, i.e the system property
6502 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6503 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6504 */
6505 private boolean getDefaultDataRoamingEnabled(int subId) {
6506 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006507 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006508 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6509 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6510 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6511 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6512 return isDataRoamingEnabled;
6513 }
6514
6515 /**
6516 * Returns the default network type for the given {@code subId}, if the default network type is
6517 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6518 */
6519 private int getDefaultNetworkType(int subId) {
6520 return Integer.parseInt(
6521 TelephonyManager.getTelephonyProperty(
6522 mSubscriptionController.getPhoneId(subId),
6523 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6524 String.valueOf(Phone.PREFERRED_NT_MODE)));
6525 }
fionaxua13278b2018-03-21 00:08:13 -07006526
6527 @Override
6528 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6529 gid1, String gid2, String plmn, String spn) {
6530 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006531
6532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 final Phone phone = getPhone(subId);
6535 if (phone == null) {
6536 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6537 return;
6538 }
6539 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6540 } finally {
6541 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006542 }
fionaxua13278b2018-03-21 00:08:13 -07006543 }
6544
6545 @Override
6546 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006547 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006548
6549 final long identity = Binder.clearCallingIdentity();
6550 try {
6551 final Phone phone = getPhone(subId);
6552 if (phone == null) {
6553 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6554 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6555 }
6556 return phone.getCarrierIdListVersion();
6557 } finally {
6558 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006559 }
fionaxua13278b2018-03-21 00:08:13 -07006560 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006561
6562 @Override
6563 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6565 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6566 return -1;
6567 }
6568
6569 final long identity = Binder.clearCallingIdentity();
6570 try {
6571 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6572 } finally {
6573 Binder.restoreCallingIdentity(identity);
6574 }
6575 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006576
6577 @Override
6578 public int getCdmaRoamingMode(int subId) {
6579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6580 mApp, subId, "getCdmaRoamingMode");
6581
6582 final long identity = Binder.clearCallingIdentity();
6583 try {
6584 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6585 } finally {
6586 Binder.restoreCallingIdentity(identity);
6587 }
6588 }
6589
6590 @Override
6591 public boolean setCdmaRoamingMode(int subId, int mode) {
6592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6593 mApp, subId, "setCdmaRoamingMode");
6594
6595 final long identity = Binder.clearCallingIdentity();
6596 try {
6597 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6598 } finally {
6599 Binder.restoreCallingIdentity(identity);
6600 }
6601 }
6602
6603 @Override
6604 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6606 mApp, subId, "setCdmaSubscriptionMode");
6607
6608 final long identity = Binder.clearCallingIdentity();
6609 try {
6610 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
6614 }
chen xu7ee67862018-10-30 22:27:10 -07006615
sqian2fff4a32018-11-05 14:18:37 -08006616 private void ensureUserRunning(int userId) {
6617 if (!mUserManager.isUserRunning(userId)) {
6618 throw new IllegalStateException("User " + userId + " does not exist or not running");
6619 }
6620 }
6621
6622 /**
6623 * Returns a list of SMS apps on a given user.
6624 *
6625 * Only the shell user (UID 2000 or 0) can call it.
6626 * Target user must be running.
6627 */
6628 @Override
6629 public String[] getSmsApps(int userId) {
6630 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6631 ensureUserRunning(userId);
6632
6633 final Collection<SmsApplicationData> apps =
6634 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6635
6636 String[] ret = new String[apps.size()];
6637 int i = 0;
6638 for (SmsApplicationData app : apps) {
6639 ret[i++] = app.mPackageName;
6640 }
6641 return ret;
6642 }
6643
6644 /**
6645 * Returns the default SMS app package name on a given user.
6646 *
6647 * Only the shell user (UID 2000 or 0) can call it.
6648 * Target user must be running.
6649 */
6650 @Override
6651 public String getDefaultSmsApp(int userId) {
6652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6653 ensureUserRunning(userId);
6654
6655 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6656 /* updateIfNeeded= */ true, userId);
6657 return cn == null ? null : cn.getPackageName();
6658 }
6659
6660 /**
6661 * Set a package as the default SMS app on a given user.
6662 *
6663 * Only the shell user (UID 2000 or 0) can call it.
6664 * Target user must be running.
6665 */
6666 @Override
6667 public void setDefaultSmsApp(int userId, String packageName) {
6668 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6669 ensureUserRunning(userId);
6670
6671 boolean found = false;
6672 for (String pkg : getSmsApps(userId)) {
6673 if (TextUtils.equals(packageName, pkg)) {
6674 found = true;
6675 break;
6676 }
6677 }
6678 if (!found) {
6679 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6680 }
6681
6682 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6683 }
6684
chen xu7ee67862018-10-30 22:27:10 -07006685 @Override
sqian65eefe12019-02-22 15:55:18 -08006686 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006687 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006689 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006690 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6691 }
6692 final long identity = Binder.clearCallingIdentity();
6693 try {
sqian991b35e2018-12-12 16:48:18 -08006694 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6695 for (Phone phone: PhoneFactory.getPhones()) {
6696 if (phone.getEmergencyNumberTracker() != null
6697 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6698 emergencyNumberListInternal.put(
6699 phone.getSubId(),
6700 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6701 }
sqian03bca152018-12-05 18:48:28 -08006702 }
sqian991b35e2018-12-12 16:48:18 -08006703 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006704 } finally {
6705 Binder.restoreCallingIdentity(identity);
6706 }
sqian04b86072018-11-07 14:02:21 -08006707 }
6708
6709 @Override
sqian65eefe12019-02-22 15:55:18 -08006710 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006711 final Phone defaultPhone = getDefaultPhone();
6712 if (!exactMatch) {
6713 TelephonyPermissions
6714 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006715 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006716 }
6717 final long identity = Binder.clearCallingIdentity();
6718 try {
sqian991b35e2018-12-12 16:48:18 -08006719 for (Phone phone: PhoneFactory.getPhones()) {
6720 if (phone.getEmergencyNumberTracker() != null
6721 && phone.getEmergencyNumberTracker() != null) {
6722 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6723 number, exactMatch)) {
6724 return true;
sqian03bca152018-12-05 18:48:28 -08006725 }
6726 }
sqian03bca152018-12-05 18:48:28 -08006727 }
6728 return false;
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
6731 }
6732 }
6733
sqian9d4df8b2019-01-15 18:32:07 -08006734 /**
6735 * Update emergency number list for test mode.
6736 */
6737 @Override
6738 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6740 "updateEmergencyNumberListTestMode");
6741
6742 final long identity = Binder.clearCallingIdentity();
6743 try {
6744 for (Phone phone: PhoneFactory.getPhones()) {
6745 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6746 if (tracker != null) {
6747 tracker.executeEmergencyNumberTestModeCommand(action, num);
6748 }
6749 }
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
6753 }
6754
6755 /**
6756 * Get the full emergency number list for test mode.
6757 */
6758 @Override
6759 public List<String> getEmergencyNumberListTestMode() {
6760 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6761 "getEmergencyNumberListTestMode");
6762
6763 final long identity = Binder.clearCallingIdentity();
6764 try {
6765 Set<String> emergencyNumbers = new HashSet<>();
6766 for (Phone phone: PhoneFactory.getPhones()) {
6767 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6768 if (tracker != null) {
6769 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6770 emergencyNumbers.add(num.getNumber());
6771 }
6772 }
6773 }
6774 return new ArrayList<>(emergencyNumbers);
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
6778 }
6779
sqian04b86072018-11-07 14:02:21 -08006780 @Override
chen xu7ee67862018-10-30 22:27:10 -07006781 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6782 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6783 Phone phone = getPhone(subId);
6784 if (phone == null) {
6785 return null;
6786 }
6787 final long identity = Binder.clearCallingIdentity();
6788 try {
6789 UiccProfile profile = UiccController.getInstance()
6790 .getUiccProfileForPhone(phone.getPhoneId());
6791 if (profile != null) {
6792 return profile.getCertsFromCarrierPrivilegeAccessRules();
6793 }
6794 } finally {
6795 Binder.restoreCallingIdentity(identity);
6796 }
6797 return null;
6798 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006799
6800 /**
6801 * Enable or disable a modem stack.
6802 */
6803 @Override
6804 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6805 enforceModifyPermission();
6806
6807 final long identity = Binder.clearCallingIdentity();
6808 try {
6809 Phone phone = PhoneFactory.getPhone(slotIndex);
6810 if (phone == null) {
6811 return false;
6812 } else {
6813 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6814 }
6815 } finally {
6816 Binder.restoreCallingIdentity(identity);
6817 }
6818 }
Micheled3107c52018-12-21 15:00:11 -08006819
Malcolm Chen33f55e12019-03-27 18:34:05 -07006820 /**
6821 * Whether a modem stack is enabled or not.
6822 */
6823 @Override
6824 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6825 Phone phone = PhoneFactory.getPhone(slotIndex);
6826 if (phone == null) return false;
6827
6828 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6829 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6830 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6831 }
6832
6833 final long identity = Binder.clearCallingIdentity();
6834 try {
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07006835 try {
6836 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6837 } catch (NoSuchElementException ex) {
6838 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6839 }
Malcolm Chen33f55e12019-03-27 18:34:05 -07006840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842 }
6843 }
6844
Micheled3107c52018-12-21 15:00:11 -08006845 @Override
Michele2fb0f222019-03-19 14:58:42 -07006846 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006847 enforceModifyPermission();
6848
6849 final long identity = Binder.clearCallingIdentity();
6850 try {
6851 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006852 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006853 .commit();
6854 } finally {
6855 Binder.restoreCallingIdentity(identity);
6856 }
6857 }
6858
6859 @Override
Michele2fb0f222019-03-19 14:58:42 -07006860 @TelephonyManager.IsMultiSimSupportedResult
6861 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006863 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6864 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006865 }
Micheled3107c52018-12-21 15:00:11 -08006866
6867 final long identity = Binder.clearCallingIdentity();
6868 try {
Michele2fb0f222019-03-19 14:58:42 -07006869 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006870 } finally {
6871 Binder.restoreCallingIdentity(identity);
6872 }
6873 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006874
Michele2fb0f222019-03-19 14:58:42 -07006875 @TelephonyManager.IsMultiSimSupportedResult
6876 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006877 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6878 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6879 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006880 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6881 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006882 }
6883 // Check if the hardware supports multisim functionality. If usage of multisim is not
6884 // supported by the modem, indicate that it is restricted.
6885 PhoneCapability staticCapability =
6886 mPhoneConfigurationManager.getStaticPhoneCapability();
6887 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006888 loge("isMultiSimSupportedInternal: no static configuration available");
6889 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006890 }
6891 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006892 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6893 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006894 }
6895 // Check if support of multiple SIMs is restricted by carrier
6896 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006897 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006898 }
6899
Michele2fb0f222019-03-19 14:58:42 -07006900 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006901 }
6902
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006903 /**
6904 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006905 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6906 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6907 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006908 * @param numOfSims number of active sims we want to switch to
6909 */
6910 @Override
6911 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006912 if (numOfSims == 1) {
6913 enforceModifyPermission();
6914 } else {
6915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6916 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6917 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006918 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006919
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006920 try {
Michele30b57b22019-03-01 12:01:14 -08006921 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006922 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006923 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6924 return;
6925 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006926 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6927 } finally {
6928 Binder.restoreCallingIdentity(identity);
6929 }
6930 }
6931
6932 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006933 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006934 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006935 */
6936 @Override
6937 public boolean isRebootRequiredForModemConfigChange() {
6938 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6939 final long identity = Binder.clearCallingIdentity();
6940 try {
6941 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6942 } finally {
6943 Binder.restoreCallingIdentity(identity);
6944 }
6945 }
6946
Pengquan Meng92d253b2019-02-06 11:12:53 -08006947 private void updateModemStateMetrics() {
6948 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6949 // TODO: check the state for each modem if the api is ready.
6950 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6951 }
6952
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006953 @Override
6954 public int[] getSlotsMapping() {
6955 enforceReadPrivilegedPermission("getSlotsMapping");
6956
6957 final long identity = Binder.clearCallingIdentity();
6958 try {
6959 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6960 // All logical slots should have a mapping to a physical slot.
6961 int[] logicalSlotsMapping = new int[phoneCount];
6962 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6963 for (int i = 0; i < slotInfos.length; i++) {
6964 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6965 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6966 }
6967 }
6968 return logicalSlotsMapping;
6969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
6972 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006973
6974 /**
6975 * Get the IRadio HAL Version
6976 */
6977 @Override
6978 public int getRadioHalVersion() {
6979 Phone phone = getDefaultPhone();
6980 if (phone == null) return -1;
6981 HalVersion hv = phone.getHalVersion();
6982 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6983 return hv.major * 100 + hv.minor;
6984 }
Malcolm Chen460810d2019-04-10 18:25:07 -07006985
6986 /**
Malcolm Chen29739692019-04-18 13:51:02 -07006987 * Return whether data is enabled for certain APN type. This will tell if framework will accept
6988 * corresponding network requests on a subId.
6989 *
6990 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07006991 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07006992 * 2) APN is un-metered for this subscription, or
6993 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
6994 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
6995 *
6996 * @return whether data is allowed for a apn type.
6997 *
6998 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07006999 */
7000 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07007001 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07007002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07007003 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7004 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07007005 }
7006
7007 // Now that all security checks passes, perform the operation as ourselves.
7008 final long identity = Binder.clearCallingIdentity();
7009 try {
7010 Phone phone = getPhone(subId);
7011 if (phone == null) return false;
7012
Jack Yu40306fc2019-05-13 16:54:09 -07007013 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen29739692019-04-18 13:51:02 -07007014 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7015 } finally {
7016 Binder.restoreCallingIdentity(identity);
7017 }
7018 }
7019
7020 @Override
Jack Yu40306fc2019-05-13 16:54:09 -07007021 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chen29739692019-04-18 13:51:02 -07007022 enforceReadPrivilegedPermission("isApnMetered");
7023
7024 // Now that all security checks passes, perform the operation as ourselves.
7025 final long identity = Binder.clearCallingIdentity();
7026 try {
7027 Phone phone = getPhone(subId);
7028 if (phone == null) return true; // By default return true.
7029
Jack Yu40306fc2019-05-13 16:54:09 -07007030 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07007031 } finally {
7032 Binder.restoreCallingIdentity(identity);
7033 }
7034 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007035}