blob: 9ccba80151db8602816adc077141850cec4ceb45 [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;
Jack Yu84291ec2017-05-26 16:07:50 -070082import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
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;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800142import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800143import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chen460810d2019-04-10 18:25:07 -0700144import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqian9d4df8b2019-01-15 18:32:07 -0800145import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700146import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800147import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800148import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.uicc.IccIoResult;
150import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800151import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700152import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800153import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000156import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700157import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700159import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800160import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700161import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700162import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800163
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700164import java.io.FileDescriptor;
165import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800166import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800168import java.util.Arrays;
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:
2139 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002140 }
2141
Nathan Harolda939a962019-05-09 10:13:47 -07002142
2143 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002144 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2145
2146 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2147 }
2148
2149 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002151 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002152 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002153
2154 final long identity = Binder.clearCallingIdentity();
2155 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002156 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002157 } finally {
2158 Binder.restoreCallingIdentity(identity);
2159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 }
2161
Shishir Agrawala9f32182016-04-12 12:00:16 -07002162 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002163 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002164 Phone phone = PhoneFactory.getPhone(slotIndex);
2165 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002166 return null;
2167 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002168 int subId = phone.getSubId();
2169 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2170 mApp, subId, callingPackage, "getImeiForSlot")) {
2171 return null;
2172 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002173
2174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 return phone.getImei();
2177 } finally {
2178 Binder.restoreCallingIdentity(identity);
2179 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002180 }
2181
2182 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002183 public String getTypeAllocationCodeForSlot(int slotIndex) {
2184 Phone phone = PhoneFactory.getPhone(slotIndex);
2185 String tac = null;
2186 if (phone != null) {
2187 String imei = phone.getImei();
2188 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2189 }
2190 return tac;
2191 }
2192
2193 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002194 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002195 Phone phone = PhoneFactory.getPhone(slotIndex);
2196 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002197 return null;
2198 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002199
Jeff Davidson913390f2018-02-23 17:11:49 -08002200 int subId = phone.getSubId();
2201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2202 mApp, subId, callingPackage, "getMeidForSlot")) {
2203 return null;
2204 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 return phone.getMeid();
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
2211 }
Jack Yu2af8d712017-03-15 17:14:14 -07002212 }
2213
2214 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002215 public String getManufacturerCodeForSlot(int slotIndex) {
2216 Phone phone = PhoneFactory.getPhone(slotIndex);
2217 String manufacturerCode = null;
2218 if (phone != null) {
2219 String meid = phone.getMeid();
2220 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2221 }
2222 return manufacturerCode;
2223 }
2224
2225 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002226 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002227 Phone phone = PhoneFactory.getPhone(slotIndex);
2228 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002229 return null;
2230 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002231 int subId = phone.getSubId();
2232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2233 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2234 return null;
2235 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002236
2237 final long identity = Binder.clearCallingIdentity();
2238 try {
2239 return phone.getDeviceSvn();
2240 } finally {
2241 Binder.restoreCallingIdentity(identity);
2242 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002243 }
2244
fionaxu43304da2017-11-27 22:51:16 -08002245 @Override
2246 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002247 final long identity = Binder.clearCallingIdentity();
2248 try {
2249 final Phone phone = getPhone(subId);
2250 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2251 } finally {
2252 Binder.restoreCallingIdentity(identity);
2253 }
fionaxu43304da2017-11-27 22:51:16 -08002254 }
2255
2256 @Override
2257 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002258 final long identity = Binder.clearCallingIdentity();
2259 try {
2260 final Phone phone = getPhone(subId);
2261 return phone == null ? null : phone.getCarrierName();
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
fionaxu43304da2017-11-27 22:51:16 -08002265 }
2266
calvinpaneed9ae82018-11-01 19:43:06 +08002267 @Override
chen xua31f22b2019-03-06 15:28:50 -08002268 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 final Phone phone = getPhone(subId);
2272 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002273 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002274 } finally {
2275 Binder.restoreCallingIdentity(identity);
2276 }
2277 }
2278
2279 @Override
chen xua31f22b2019-03-06 15:28:50 -08002280 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002281 final long identity = Binder.clearCallingIdentity();
2282 try {
2283 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002284 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002285 } finally {
2286 Binder.restoreCallingIdentity(identity);
2287 }
2288 }
2289
chen xu02581692018-11-11 19:03:44 -08002290 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002291 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2292 if (!isSubscriptionMccMnc) {
2293 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2294 }
chen xu02581692018-11-11 19:03:44 -08002295 final Phone phone = PhoneFactory.getPhone(slotIndex);
2296 if (phone == null) {
2297 return TelephonyManager.UNKNOWN_CARRIER_ID;
2298 }
2299 final long identity = Binder.clearCallingIdentity();
2300 try {
2301 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2302 } finally {
2303 Binder.restoreCallingIdentity(identity);
2304 }
2305 }
2306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 //
2308 // Internal helper methods.
2309 //
2310
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002311 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2313 *
2314 * @throws SecurityException if the caller does not have the required permission
2315 */
2316 private void enforceModifyPermission() {
2317 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2318 }
2319
2320 /**
2321 * Make sure the caller has the CALL_PHONE permission.
2322 *
2323 * @throws SecurityException if the caller does not have the required permission
2324 */
2325 private void enforceCallPermission() {
2326 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2327 }
2328
Stuart Scott8eef64f2015-04-08 15:13:54 -07002329 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002330 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002331 "ConnectivityService");
2332 }
2333
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 private String createTelUrl(String number) {
2335 if (TextUtils.isEmpty(number)) {
2336 return null;
2337 }
2338
Jake Hambye994d462014-02-03 13:10:13 -08002339 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
2341
Ihab Awadf9e92732013-12-05 18:02:52 -08002342 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2344 }
2345
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002346 private static void logv(String msg) {
2347 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2348 }
2349
Ihab Awadf9e92732013-12-05 18:02:52 -08002350 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2352 }
2353
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002354 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002356 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002357 }
2358
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002360 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 final Phone phone = PhoneFactory.getPhone(slotIndex);
2364 if (phone == null) {
2365 return PhoneConstants.PHONE_TYPE_NONE;
2366 } else {
2367 return phone.getPhoneType();
2368 }
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
2374 /**
2375 * Returns the CDMA ERI icon index to display
2376 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002377 @Override
2378 public int getCdmaEriIconIndex(String callingPackage) {
2379 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002380 }
2381
Sanket Padawe356d7632015-06-22 14:03:32 -07002382 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002383 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002385 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002386 return -1;
2387 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002388
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 final Phone phone = getPhone(subId);
2392 if (phone != null) {
2393 return phone.getCdmaEriIconIndex();
2394 } else {
2395 return -1;
2396 }
2397 } finally {
2398 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 }
2401
2402 /**
2403 * Returns the CDMA ERI icon mode,
2404 * 0 - ON
2405 * 1 - FLASHING
2406 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002407 @Override
2408 public int getCdmaEriIconMode(String callingPackage) {
2409 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002410 }
2411
Sanket Padawe356d7632015-06-22 14:03:32 -07002412 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002413 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002415 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002416 return -1;
2417 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002418
2419 final long identity = Binder.clearCallingIdentity();
2420 try {
2421 final Phone phone = getPhone(subId);
2422 if (phone != null) {
2423 return phone.getCdmaEriIconMode();
2424 } else {
2425 return -1;
2426 }
2427 } finally {
2428 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 }
2431
2432 /**
2433 * Returns the CDMA ERI text,
2434 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002435 @Override
2436 public String getCdmaEriText(String callingPackage) {
2437 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002438 }
2439
Sanket Padawe356d7632015-06-22 14:03:32 -07002440 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002441 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002443 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002444 return null;
2445 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002446
2447 final long identity = Binder.clearCallingIdentity();
2448 try {
2449 final Phone phone = getPhone(subId);
2450 if (phone != null) {
2451 return phone.getCdmaEriText();
2452 } else {
2453 return null;
2454 }
2455 } finally {
2456 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 }
2459
2460 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002461 * Returns the CDMA MDN.
2462 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002463 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002464 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2466 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002467
2468 final long identity = Binder.clearCallingIdentity();
2469 try {
2470 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002471 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002472 return phone.getLine1Number();
2473 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002474 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002475 return null;
2476 }
2477 } finally {
2478 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002479 }
2480 }
2481
2482 /**
2483 * Returns the CDMA MIN.
2484 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002485 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002486 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2488 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002489
2490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 final Phone phone = getPhone(subId);
2493 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2494 return phone.getCdmaMin();
2495 } else {
2496 return null;
2497 }
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002500 }
2501 }
2502
Hall Liud892bec2018-11-30 14:51:45 -08002503 @Override
2504 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2505 INumberVerificationCallback callback, String callingPackage) {
2506 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2507 != PERMISSION_GRANTED) {
2508 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2509 }
2510 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2511
2512 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2513 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2514 throw new SecurityException("Calling package must be configured in the device config");
2515 }
2516
2517 if (range == null) {
2518 throw new NullPointerException("Range must be non-null");
2519 }
2520
2521 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002522 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002523
2524 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2525 }
2526
Junda Liuca05d5d2014-08-14 22:36:34 -07002527 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 * Returns true if CDMA provisioning needs to run.
2529 */
2530 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002531 final long identity = Binder.clearCallingIdentity();
2532 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002533 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 }
2538
2539 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002540 * Sets the voice mail number of a given subId.
2541 */
2542 @Override
2543 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002544 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002545
2546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2549 new Pair<String, String>(alphaTag, number), new Integer(subId));
2550 return success;
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
2553 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002554 }
2555
Ta-wei Yen87c49842016-05-13 21:19:52 -07002556 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002557 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2558 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002559 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002560 if (!TextUtils.equals(callingPackage, systemDialer)) {
2561 throw new SecurityException("caller must be system dialer");
2562 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002563
2564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2567 if (phoneAccountHandle == null) {
2568 return null;
2569 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002570 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002571 } finally {
2572 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002573 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002574 }
2575
2576 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002577 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002578 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002579 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002580 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002581 return null;
2582 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002583
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002584 final long identity = Binder.clearCallingIdentity();
2585 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002586 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002587 } finally {
2588 Binder.restoreCallingIdentity(identity);
2589 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002590 }
2591
2592 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002593 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2594 VisualVoicemailSmsFilterSettings settings) {
2595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002600 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002601 } finally {
2602 Binder.restoreCallingIdentity(identity);
2603 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002604 }
2605
2606 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002607 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2608 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002609
2610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002613 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002614 } finally {
2615 Binder.restoreCallingIdentity(identity);
2616 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002617 }
2618
2619 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002620 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2621 String callingPackage, int subId) {
2622 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002627 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002628 } finally {
2629 Binder.restoreCallingIdentity(identity);
2630 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002631 }
2632
2633 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002634 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002635 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002640 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002644 }
2645
2646 @Override
2647 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2648 String number, int port, String text, PendingIntent sentIntent) {
2649 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002650 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002651 enforceSendSmsPermission();
2652 // Make the calls as the phone process.
2653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2656 if (port == 0) {
2657 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2658 sentIntent, null, false);
2659 } else {
2660 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2661 smsManager.sendDataMessageWithSelfPermissions(number, null,
2662 (short) port, data, sentIntent, null);
2663 }
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
2666 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002667 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002668 /**
fionaxu0152e512016-11-14 13:36:14 -08002669 * Sets the voice activation state of a given subId.
2670 */
2671 @Override
2672 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2674 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002675
2676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 final Phone phone = getPhone(subId);
2679 if (phone != null) {
2680 phone.setVoiceActivationState(activationState);
2681 } else {
2682 loge("setVoiceActivationState fails with invalid subId: " + subId);
2683 }
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002686 }
2687 }
2688
2689 /**
2690 * Sets the data activation state of a given subId.
2691 */
2692 @Override
2693 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2695 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 final Phone phone = getPhone(subId);
2700 if (phone != null) {
2701 phone.setDataActivationState(activationState);
2702 } else {
2703 loge("setVoiceActivationState fails with invalid subId: " + subId);
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002707 }
2708 }
2709
2710 /**
2711 * Returns the voice activation state of a given subId.
2712 */
2713 @Override
2714 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002715 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002716
fionaxu0152e512016-11-14 13:36:14 -08002717 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 if (phone != null) {
2721 return phone.getVoiceActivationState();
2722 } else {
2723 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002727 }
2728 }
2729
2730 /**
2731 * Returns the data activation state of a given subId.
2732 */
2733 @Override
2734 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002735 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002736
fionaxu0152e512016-11-14 13:36:14 -08002737 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 if (phone != null) {
2741 return phone.getDataActivationState();
2742 } else {
2743 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002747 }
2748 }
2749
2750 /**
Wink Saville36469e72014-06-11 15:17:00 -07002751 * Returns the unread count of voicemails for a subId
2752 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002754 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2756 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2757 return 0;
2758 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 final Phone phone = getPhone(subId);
2762 if (phone != null) {
2763 return phone.getVoiceMessageCount();
2764 } else {
2765 return 0;
2766 }
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771
2772 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002773 * returns true, if the device is in a state where both voice and data
2774 * are supported simultaneously. This can change based on location or network condition.
2775 */
2776 @Override
2777 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 final Phone phone = getPhone(subId);
2781 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2782 } finally {
2783 Binder.restoreCallingIdentity(identity);
2784 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002785 }
2786
2787 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002788 * Send the dialer code if called from the current default dialer or the caller has
2789 * carrier privilege.
2790 * @param inputCode The dialer code to send
2791 */
2792 @Override
2793 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002794 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002795 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002796 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2797 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002798 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002799 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2800 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002801 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002805 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002806 } finally {
2807 Binder.restoreCallingIdentity(identity);
2808 }
fionaxu235cc5e2017-03-06 22:25:57 -08002809 }
2810
2811 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002812 * Returns the data network type.
2813 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 *
2815 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2816 */
2817 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002818 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 final Phone phone = getPhone(getDefaultSubscription());
2822 if (phone != null) {
2823 return phone.getServiceState().getDataNetworkType();
2824 } else {
2825 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2826 }
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002829 }
Wink Saville36469e72014-06-11 15:17:00 -07002830 }
2831
Pengquan Meng0c05b502018-09-06 09:59:22 -07002832 @Override
2833 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002834 if (!isActiveSubscription(subId)) {
2835 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2836 }
2837
Pengquan Meng0c05b502018-09-06 09:59:22 -07002838 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2839 }
2840
Brad Ebinger4c460712018-10-01 10:40:55 -07002841 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002842 public boolean isInEmergencySmsMode() {
2843 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 for (Phone phone : PhoneFactory.getPhones()) {
2847 if (phone.isInEmergencySmsMode()) {
2848 return true;
2849 }
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
2853 }
2854 return false;
2855 }
2856
2857 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002858 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2859 throws RemoteException {
2860 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002861 final long token = Binder.clearCallingIdentity();
2862 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002864 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002865 .addRegistrationCallbackForSubscription(c, subId);
2866 } finally {
2867 Binder.restoreCallingIdentity(token);
2868 }
2869 }
2870
2871 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002872 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2873 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002874 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2875 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2876 }
2877 Binder.withCleanCallingIdentity(() -> {
2878 try {
2879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002880 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002881 .removeRegistrationCallbackForSubscription(c, subId);
2882 } catch (IllegalArgumentException e) {
2883 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2884 + "is inactive, ignoring unregister.");
2885 // If the subscription is no longer active, just return, since the callback
2886 // will already have been removed internally.
2887 }
2888 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002889 }
2890
2891 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002892 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2893 throws RemoteException {
2894 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2896 final long token = Binder.clearCallingIdentity();
2897 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002898 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002899 .addCapabilitiesCallbackForSubscription(c, subId);
2900 } finally {
2901 Binder.restoreCallingIdentity(token);
2902 }
2903 }
2904
2905 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002906 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2907 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002908
2909 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2910 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2911 }
2912 Binder.withCleanCallingIdentity(() -> {
2913 try {
2914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002915 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002916 .removeCapabilitiesCallbackForSubscription(c, subId);
2917 } catch (IllegalArgumentException e) {
2918 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2919 + "is inactive, ignoring unregister.");
2920 // If the subscription is no longer active, just return, since the callback
2921 // will already have been removed internally.
2922 }
2923 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002924 }
2925
2926 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002927 public boolean isCapable(int subId, int capability, int regTech) {
2928 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002929 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2930 final long token = Binder.clearCallingIdentity();
2931 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002932 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002933 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2934 } catch (ImsException e) {
2935 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2936 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002937 } catch (IllegalArgumentException e) {
2938 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2939 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002940 } finally {
2941 Binder.restoreCallingIdentity(token);
2942 }
2943 }
2944
2945 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002946 public boolean isAvailable(int subId, int capability, int regTech) {
2947 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002948 final long token = Binder.clearCallingIdentity();
2949 try {
2950 Phone phone = getPhone(subId);
2951 if (phone == null) return false;
2952 return phone.isImsCapabilityAvailable(capability, regTech);
2953 } finally {
2954 Binder.restoreCallingIdentity(token);
2955 }
2956 }
2957
2958 @Override
2959 public boolean isAdvancedCallingSettingEnabled(int subId) {
2960 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2962 final long token = Binder.clearCallingIdentity();
2963 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002964 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002965 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2966 } finally {
2967 Binder.restoreCallingIdentity(token);
2968 }
2969 }
2970
2971 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002972 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002974 "setAdvancedCallingSettingEnabled");
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,
Brad Ebinger4c460712018-10-01 10:40:55 -07002979 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
2983 }
2984
2985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002986 public boolean isVtSettingEnabled(int subId) {
2987 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002991 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002992 getSlotIndexOrException(subId)).isVtEnabledByUser();
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
2998 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002999 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003001 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003005 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07003006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
3011 @Override
3012 public boolean isVoWiFiSettingEnabled(int subId) {
3013 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003017 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003018 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003025 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003027 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003031 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07003032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
3035 }
3036
3037 @Override
3038 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3039 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003043 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003044 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
3048 }
3049
3050 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003051 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003053 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003054 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 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003058 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
3062 }
3063
3064 @Override
3065 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3067 "setVoWiFiNonPersistent");
3068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003071 boolean isRoaming = TelephonyManager.from(
3072 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003073 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003074 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
3081 public int getVoWiFiModeSetting(int subId) {
3082 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003086 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003087 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
3091 }
3092
3093 @Override
3094 public void setVoWiFiModeSetting(int subId, int mode) {
3095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3096 "setVoWiFiModeSetting");
3097 final long identity = Binder.clearCallingIdentity();
3098 try {
3099 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003100 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003101 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
3105 }
3106
3107 @Override
3108 public int getVoWiFiRoamingModeSetting(int subId) {
3109 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003113 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003114 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
3117 }
3118 }
3119
3120 @Override
3121 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3123 "setVoWiFiRoamingModeSetting");
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003127 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003128 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
3132 }
3133
3134 @Override
3135 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3137 "setRttCapabilityEnabled");
3138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003141 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003142 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
3146 }
3147
3148 @Override
3149 public boolean isTtyOverVolteEnabled(int subId) {
3150 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003154 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003155 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
3158 }
3159 }
3160
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003161 @Override
3162 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3163 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003167 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003168 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
3172 }
3173
3174 @Override
3175 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3176 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3177 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003178 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3179 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3180 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003181 try {
3182 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003183 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003184 .removeProvisioningCallbackForSubscription(callback, subId);
3185 } catch (IllegalArgumentException e) {
3186 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3187 + "is inactive, ignoring unregister.");
3188 // If the subscription is no longer active, just return, since the callback will already
3189 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003190 } finally {
3191 Binder.restoreCallingIdentity(identity);
3192 }
3193 }
3194
3195 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003196 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3197 boolean isProvisioned) {
3198 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3199 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3200 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3201 }
3202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3203 "setProvisioningStatusForCapability");
3204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3207 Phone phone = getPhone(subId);
3208 if (phone == null) {
3209 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3210 + subId);
3211 return;
3212 }
3213 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3214 return;
3215 }
3216
3217 // this capability requires provisioning, route to the correct API.
3218 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3219 switch (capability) {
3220 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3221 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3222 ims.setVolteProvisioned(isProvisioned);
3223 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3224 ims.setWfcProvisioned(isProvisioned);
3225 }
3226 break;
3227 }
3228 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3229 // There is currently no difference in VT provisioning type.
3230 ims.setVtProvisioned(isProvisioned);
3231 break;
3232 }
3233 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3234 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3235 // change the capability of the feature instead if needed.
3236 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3237 == isProvisioned) {
3238 // No change in provisioning.
3239 return;
3240 }
3241 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3242 try {
3243 ims.changeMmTelCapability(capability, tech, isProvisioned);
3244 } catch (ImsException e) {
3245 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3246 + ", Exception" + e.getMessage());
3247 }
3248 break;
3249 }
3250 default: {
3251 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3252 + capability + "', which does not require provisioning.");
3253 }
3254 }
3255
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
3259 }
3260
3261 @Override
3262 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3263 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3264 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3265 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3266 }
3267 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3271 Phone phone = getPhone(subId);
3272 if (phone == null) {
3273 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3274 + subId);
3275 // We will fail with "true" as the provisioning status because this is the default
3276 // if we do not require provisioning.
3277 return true;
3278 }
3279
3280 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3281 return true;
3282 }
3283
3284 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3285 switch (capability) {
3286 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3287 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3288 return ims.isVolteProvisionedOnDevice();
3289 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3290 return ims.isWfcProvisionedOnDevice();
3291 }
3292 // This should never happen, since we are checking tech above to make sure it
3293 // is either LTE or IWLAN.
3294 throw new IllegalArgumentException("Invalid radio technology for voice "
3295 + "capability.");
3296 }
3297 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3298 // There is currently no difference in VT provisioning type.
3299 return ims.isVtProvisionedOnDevice();
3300 }
3301 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3302 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3303 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3304 }
3305 default: {
3306 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3307 + capability + "', which does not require provisioning.");
3308 }
3309 }
3310
3311 } finally {
3312 Binder.restoreCallingIdentity(identity);
3313 }
3314 }
3315
3316 @Override
3317 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3318 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3319 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3320 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3321 }
3322 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3323 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3324 return (provisionedBits & capability) > 0;
3325 }
3326
3327 @Override
3328 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3329 boolean isProvisioned) {
3330 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3331 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3332 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3333 }
3334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3335 "setProvisioningStatusForCapability");
3336 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3337 // If the current provisioning status for capability already matches isProvisioned,
3338 // do nothing.
3339 if (((provisionedBits & capability) > 0) == isProvisioned) {
3340 return;
3341 }
3342 if (isProvisioned) {
3343 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3344 } else {
3345 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3346 }
3347 }
3348
3349 /**
3350 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3351 * technology. The bitfield should mirror the bitfield defined by
3352 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3353 */
3354 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3355 String key = getMmTelProvisioningKey(subId, tech);
3356 // Default is no capabilities are provisioned.
3357 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3358 }
3359
3360 /**
3361 * Sets the MmTel capability provisioning bitfield (defined by
3362 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3363 * technology specified.
3364 *
3365 * Note: This is a synchronous command and should not be called on UI thread.
3366 */
3367 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3368 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3369 String key = getMmTelProvisioningKey(subId, tech);
3370 editor.putInt(key, newField);
3371 editor.commit();
3372 }
3373
3374 private static String getMmTelProvisioningKey(int subId, int tech) {
3375 // resulting key is provision_ims_mmtel_{subId}_{tech}
3376 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3377 }
3378
3379 /**
3380 * Query CarrierConfig to see if the specified capability requires provisioning for the
3381 * carrier associated with the subscription id.
3382 */
3383 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3384 int capability) {
3385 CarrierConfigManager configManager = new CarrierConfigManager(context);
3386 PersistableBundle c = configManager.getConfigForSubId(subId);
3387 boolean requireUtProvisioning = c.getBoolean(
3388 // By default, this config is true (even if there is no SIM). We also check to make
3389 // sure the subscription needs provisioning here, so we do not need to check for
3390 // the no-SIM case, where we would normally shortcut this to false.
3391 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3392 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3393 false);
3394 boolean requireVoiceVtProvisioning = c.getBoolean(
3395 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3396
3397 // First check to make sure that the capability requires provisioning.
3398 switch (capability) {
3399 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3400 // intentional fallthrough
3401 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3402 if (requireVoiceVtProvisioning) {
3403 // Voice and Video requires provisioning
3404 return true;
3405 }
3406 break;
3407 }
3408 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3409 if (requireUtProvisioning) {
3410 // UT requires provisioning
3411 return true;
3412 }
3413 break;
3414 }
3415 }
3416 return false;
3417 }
3418
3419 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003420 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3422 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3423 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 enforceReadPrivilegedPermission("getImsProvisioningInt");
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003428 int slotId = getSlotIndex(subId);
3429 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3430 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3431 + subId + "' for key:" + key);
3432 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3433 }
3434 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003435 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003436 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3437 + subId + "' for key:" + key);
3438 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003439 } finally {
3440 Binder.restoreCallingIdentity(identity);
3441 }
3442 }
3443
3444 @Override
3445 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003446 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3447 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3448 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 enforceReadPrivilegedPermission("getImsProvisioningString");
3450 final long identity = Binder.clearCallingIdentity();
3451 try {
3452 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003453 int slotId = getSlotIndex(subId);
3454 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3455 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3456 + subId + "' for key:" + key);
3457 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3458 }
3459 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003460 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003461 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3462 + subId + "' for key:" + key);
3463 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003464 } finally {
3465 Binder.restoreCallingIdentity(identity);
3466 }
3467 }
3468
3469 @Override
3470 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003471 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3472 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3473 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3475 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003479 int slotId = getSlotIndex(subId);
3480 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3481 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3482 + subId + "' for key:" + key);
3483 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3484 }
3485 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003486 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003487 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3488 + "' for key:" + key);
3489 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
3493 }
3494
3495 @Override
3496 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003497 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3498 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3499 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3501 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003505 int slotId = getSlotIndex(subId);
3506 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3507 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3508 + subId + "' for key:" + key);
3509 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3510 }
3511 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003512 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003513 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3514 + "' for key:" + key);
3515 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003516 } finally {
3517 Binder.restoreCallingIdentity(identity);
3518 }
3519 }
3520
Brad Ebinger4c460712018-10-01 10:40:55 -07003521 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3522 int slotId = SubscriptionManager.getSlotIndex(subId);
3523 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003524 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003525 }
3526 return slotId;
3527 }
3528
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003529 private int getSlotIndex(int subId) {
3530 int slotId = SubscriptionManager.getSlotIndex(subId);
3531 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3532 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3533 }
3534 return slotId;
3535 }
3536
Wink Saville36469e72014-06-11 15:17:00 -07003537 /**
3538 * Returns the network type for a subId
3539 */
3540 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 public int getNetworkTypeForSubscriber(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, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003544 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3545 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003546
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 /**
3561 * Returns the data network type
3562 */
3563 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003564 public int getDataNetworkType(String callingPackage) {
3565 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003566 }
3567
3568 /**
3569 * Returns the data network type for a subId
3570 */
3571 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003572 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003574 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003575 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3576 }
3577
Malcolm Chend965c8b2018-02-28 15:00:40 -08003578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 final Phone phone = getPhone(subId);
3581 if (phone != null) {
3582 return phone.getServiceState().getDataNetworkType();
3583 } else {
3584 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003589 }
3590
3591 /**
Wink Saville36469e72014-06-11 15:17:00 -07003592 * Returns the Voice network type for a subId
3593 */
3594 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003595 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003597 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003598 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3599 }
3600
Malcolm Chend965c8b2018-02-28 15:00:40 -08003601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 final Phone phone = getPhone(subId);
3604 if (phone != null) {
3605 return phone.getServiceState().getVoiceNetworkType();
3606 } else {
3607 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3608 }
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003612 }
3613
3614 /**
3615 * @return true if a ICC card is present
3616 */
3617 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003618 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003619 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3620 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003621 }
3622
3623 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003624 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003625 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003626 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003627 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003628 final long identity = Binder.clearCallingIdentity();
3629 try {
3630 final Phone phone = PhoneFactory.getPhone(slotIndex);
3631 if (phone != null) {
3632 return phone.getIccCard().hasIccCard();
3633 } else {
3634 return false;
3635 }
3636 } finally {
3637 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003639 }
3640
3641 /**
3642 * Return if the current radio is LTE on CDMA. This
3643 * is a tri-state return value as for a period of time
3644 * the mode may be unknown.
3645 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003646 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003647 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003648 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003650 @Override
3651 public int getLteOnCdmaMode(String callingPackage) {
3652 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003653 }
3654
Sanket Padawe356d7632015-06-22 14:03:32 -07003655 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003656 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003658 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003659 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3660 }
3661
Malcolm Chend965c8b2018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = getPhone(subId);
3665 if (phone == null) {
3666 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3667 } else {
3668 return phone.getLteOnCdmaMode();
3669 }
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003672 }
Wink Saville36469e72014-06-11 15:17:00 -07003673 }
3674
Wink Saville36469e72014-06-11 15:17:00 -07003675 /**
3676 * {@hide}
3677 * Returns Default subId, 0 in the case of single standby.
3678 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003679 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003680 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003681 }
3682
Shishir Agrawala9f32182016-04-12 12:00:16 -07003683 private int getSlotForDefaultSubscription() {
3684 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3685 }
3686
Wink Savilleb564aae2014-10-23 10:18:09 -07003687 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003688 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003689 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003690
Pengquan Meng466e2482018-09-21 15:54:48 -07003691 private boolean isActiveSubscription(int subId) {
3692 return mSubscriptionController.isActiveSubId(subId);
3693 }
3694
Ihab Awadf2177b72013-11-25 13:33:23 -08003695 /**
3696 * @see android.telephony.TelephonyManager.WifiCallingChoices
3697 */
3698 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003699 final long identity = Binder.clearCallingIdentity();
3700 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003701 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003702 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3703 getWhenToMakeWifiCallsDefaultPreference());
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003707 }
3708
3709 /**
3710 * @see android.telephony.TelephonyManager.WifiCallingChoices
3711 */
3712 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003716 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003717 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003721 }
3722
Sailesh Nepald1e68152013-12-12 19:08:02 -08003723 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003724 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003725 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003726 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003727
Jordan Liu73b078d2019-02-28 12:03:40 -08003728 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3729 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3730 if (phoneId == -1) {
3731 throw new IllegalArgumentException("Given slot index: " + slotIndex
3732 + " does not correspond to an active phone");
3733 }
3734 return PhoneFactory.getPhone(phoneId);
3735 }
3736
Shishir Agrawal566b7612013-10-28 14:41:00 -07003737 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003738 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3739 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3741 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003742 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003743 if (DBG) {
3744 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3745 }
3746 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3747 p2);
3748 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003749
Jordan Liu73b078d2019-02-28 12:03:40 -08003750
3751 @Override
3752 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3753 int slotIndex, String callingPackage, String aid, int p2) {
3754 enforceModifyPermission();
3755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3756 if (DBG) {
3757 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3758 }
3759 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3760 callingPackage, aid, p2);
3761 }
3762
3763 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3764 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003765 final long identity = Binder.clearCallingIdentity();
3766 try {
3767 if (TextUtils.equals(ISDR_AID, aid)) {
3768 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003769 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3770 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003771 if (bestComponent == null
3772 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3773 loge("The calling package is not allowed to access ISD-R.");
3774 throw new SecurityException(
3775 "The calling package is not allowed to access ISD-R.");
3776 }
Derek Tan740e1672017-06-27 14:56:27 -07003777 }
Derek Tan740e1672017-06-27 14:56:27 -07003778
Malcolm Chend965c8b2018-02-28 15:00:40 -08003779 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003780 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3781 null /* workSource */);
3782 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003783 return response;
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
3786 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003787 }
3788
3789 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003790 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3792 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003793 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3794 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3795 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003796
Jordan Liu73b078d2019-02-28 12:03:40 -08003797 @Override
3798 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3799 enforceModifyPermission();
3800 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3801 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3802 channel);
3803 }
3804
3805 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003806 final long identity = Binder.clearCallingIdentity();
3807 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003808 if (channel < 0) {
3809 return false;
3810 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003811 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3812 null /* workSource */);
3813 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003814 return success;
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003817 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003818 }
3819
3820 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003821 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003822 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3824 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003825 if (DBG) {
3826 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3827 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3828 + p3 + " data=" + data);
3829 }
3830 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3831 command, p1, p2, p3, data);
3832 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003833
Jordan Liu73b078d2019-02-28 12:03:40 -08003834 @Override
3835 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3836 int command, int p1, int p2, int p3, String data) {
3837 enforceModifyPermission();
3838 if (DBG) {
3839 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3840 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3841 + p3 + " data=" + data);
3842 }
3843 return iccTransmitApduLogicalChannelWithPermission(
3844 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3845 data);
3846 }
3847
3848 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3849 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003850 final long identity = Binder.clearCallingIdentity();
3851 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003852 if (channel < 0) {
3853 return "";
3854 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003855
Malcolm Chend965c8b2018-02-28 15:00:40 -08003856 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003857 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3858 null /* workSource */);
3859 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003860
Malcolm Chend965c8b2018-02-28 15:00:40 -08003861 // Append the returned status code to the end of the response payload.
3862 String s = Integer.toHexString(
3863 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3864 if (response.payload != null) {
3865 s = IccUtils.bytesToHexString(response.payload) + s;
3866 }
3867 return s;
3868 } finally {
3869 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003870 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003871 }
Jake Hambye994d462014-02-03 13:10:13 -08003872
Evan Charltonc66da362014-05-16 14:06:40 -07003873 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003874 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3875 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3877 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003878 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003879 if (DBG) {
3880 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3881 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3882 }
3883 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3884 cla, command, p1, p2, p3, data);
3885 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003886
Jordan Liu73b078d2019-02-28 12:03:40 -08003887 @Override
3888 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3889 int command, int p1, int p2, int p3, String data) {
3890 enforceModifyPermission();
3891 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3892 if (DBG) {
3893 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3894 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3895 + " data=" + data);
3896 }
3897
3898 return iccTransmitApduBasicChannelWithPermission(
3899 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3900 p2, p3, data);
3901 }
3902
3903 // open APDU basic channel assuming the caller has sufficient permissions
3904 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3905 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003906 final long identity = Binder.clearCallingIdentity();
3907 try {
3908 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3909 && TextUtils.equals(ISDR_AID, data)) {
3910 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003911 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3912 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003913 if (bestComponent == null
3914 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3915 loge("The calling package is not allowed to select ISD-R.");
3916 throw new SecurityException(
3917 "The calling package is not allowed to select ISD-R.");
3918 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003919 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003920
Malcolm Chend965c8b2018-02-28 15:00:40 -08003921 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003922 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3923 null /* workSource */);
3924 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003925
Malcolm Chend965c8b2018-02-28 15:00:40 -08003926 // Append the returned status code to the end of the response payload.
3927 String s = Integer.toHexString(
3928 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3929 if (response.payload != null) {
3930 s = IccUtils.bytesToHexString(response.payload) + s;
3931 }
3932 return s;
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003935 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003936 }
3937
3938 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003939 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003940 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3942 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003943
Malcolm Chend965c8b2018-02-28 15:00:40 -08003944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 if (DBG) {
3947 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3948 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3949 }
3950
3951 IccIoResult response =
3952 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3953 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3954 subId);
3955
3956 if (DBG) {
3957 log("Exchange SIM_IO [R]" + response);
3958 }
3959
3960 byte[] result = null;
3961 int length = 2;
3962 if (response.payload != null) {
3963 length = 2 + response.payload.length;
3964 result = new byte[length];
3965 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3966 } else {
3967 result = new byte[length];
3968 }
3969
3970 result[length - 1] = (byte) response.sw2;
3971 result[length - 2] = (byte) response.sw1;
3972 return result;
3973 } finally {
3974 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003975 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003976 }
3977
Nathan Haroldb3014052017-01-25 15:57:32 -08003978 /**
3979 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3980 * on a particular subscription
3981 */
sqianb6e41952018-03-12 14:54:01 -07003982 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3984 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3985 return null;
3986 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003987
3988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 if (appType != TelephonyManager.APPTYPE_USIM
3991 && appType != TelephonyManager.APPTYPE_SIM) {
3992 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3993 return null;
3994 }
3995 Object response = sendRequest(
3996 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3997 if (response instanceof String[]) {
3998 return (String[]) response;
3999 }
4000 // Response is an Exception of some kind,
4001 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004002 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004003 } finally {
4004 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004005 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004006 }
4007
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004008 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004009 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4011 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004012
Malcolm Chend965c8b2018-02-28 15:00:40 -08004013 final long identity = Binder.clearCallingIdentity();
4014 try {
4015 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4016 if (response.payload == null) {
4017 return "";
4018 }
Evan Charltonc66da362014-05-16 14:06:40 -07004019
Malcolm Chend965c8b2018-02-28 15:00:40 -08004020 // Append the returned status code to the end of the response payload.
4021 String s = Integer.toHexString(
4022 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4023 s = IccUtils.bytesToHexString(response.payload) + s;
4024 return s;
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
Evan Charltonc66da362014-05-16 14:06:40 -07004028 }
4029
Jake Hambye994d462014-02-03 13:10:13 -08004030 /**
4031 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4032 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4033 *
4034 * @param itemID the ID of the item to read
4035 * @return the NV item as a String, or null on error.
4036 */
4037 @Override
4038 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004039 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4041 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004042
4043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004046 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004047 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4048 return value;
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
4051 }
Jake Hambye994d462014-02-03 13:10:13 -08004052 }
4053
4054 /**
4055 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4056 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4057 *
4058 * @param itemID the ID of the item to read
4059 * @param itemValue the value to write, as a String
4060 * @return true on success; false on any failure
4061 */
4062 @Override
4063 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004064 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4066 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004067
4068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4071 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004072 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004073 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4074 return success;
4075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
Jake Hambye994d462014-02-03 13:10:13 -08004078 }
4079
4080 /**
4081 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4082 * Used for device configuration by some CDMA operators.
4083 *
4084 * @param preferredRoamingList byte array containing the new PRL
4085 * @return true on success; false on any failure
4086 */
4087 @Override
4088 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4090 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004091
4092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4095 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4096 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4097 return success;
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
4100 }
Jake Hambye994d462014-02-03 13:10:13 -08004101 }
4102
4103 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004104 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004105 * Used for device configuration by some CDMA operators.
4106 *
chen xu1cc0abe2018-10-26 17:39:23 -07004107 * @param slotIndex - device slot.
4108 *
Jake Hambye994d462014-02-03 13:10:13 -08004109 * @return true on success; false on any failure
4110 */
4111 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004112 public boolean resetModemConfig(int slotIndex) {
4113 Phone phone = PhoneFactory.getPhone(slotIndex);
4114 if (phone != null) {
4115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4116 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004117
chen xu1cc0abe2018-10-26 17:39:23 -07004118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4121 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4122 return success;
4123 } finally {
4124 Binder.restoreCallingIdentity(identity);
4125 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004126 }
chen xu1cc0abe2018-10-26 17:39:23 -07004127 return false;
4128 }
4129
4130 /**
4131 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4132 *
4133 * @param slotIndex - device slot.
4134 *
4135 * @return true on success; false on any failure
4136 */
4137 @Override
4138 public boolean rebootModem(int slotIndex) {
4139 Phone phone = PhoneFactory.getPhone(slotIndex);
4140 if (phone != null) {
4141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4142 mApp, phone.getSubId(), "rebootModem");
4143
4144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4147 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4148 return success;
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
4151 }
4152 }
4153 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004154 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004155
Svet Ganovb320e182015-04-16 12:30:10 -07004156 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004157 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004159 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004160 return new String[0];
4161 }
4162
Malcolm Chend965c8b2018-02-28 15:00:40 -08004163 final long identity = Binder.clearCallingIdentity();
4164 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004165 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
Wink Saville36469e72014-06-11 15:17:00 -07004169 }
4170
Brad Ebinger51f743a2017-01-23 13:50:20 -08004171 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004172 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4173 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004174 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004175 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004176 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004177
4178 final long identity = Binder.clearCallingIdentity();
4179 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004180 ImsResolver resolver = PhoneFactory.getImsResolver();
4181 if (resolver == null) {
4182 // may happen if the device does not support IMS.
4183 return;
4184 }
4185 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004189 }
4190
4191 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004192 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4193 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004194 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004195 public void disableIms(int slotId) {
4196 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004197
4198 final long identity = Binder.clearCallingIdentity();
4199 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004200 ImsResolver resolver = PhoneFactory.getImsResolver();
4201 if (resolver == null) {
4202 // may happen if the device does not support IMS.
4203 return;
4204 }
4205 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004206 } finally {
4207 Binder.restoreCallingIdentity(identity);
4208 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004209 }
4210
4211 /**
4212 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4213 * feature or {@link null} if the service is not available. If the feature is available, the
4214 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4215 */
4216 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004217 IImsServiceFeatureCallback callback) {
4218 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004219
4220 final long identity = Binder.clearCallingIdentity();
4221 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004222 ImsResolver resolver = PhoneFactory.getImsResolver();
4223 if (resolver == null) {
4224 // may happen if the device does not support IMS.
4225 return null;
4226 }
4227 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004231 }
4232
4233 /**
4234 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4235 * feature during emergency calling or {@link null} if the service is not available. If the
4236 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4237 * listener for feature updates.
4238 */
4239 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4240 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004241
4242 final long identity = Binder.clearCallingIdentity();
4243 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004244 ImsResolver resolver = PhoneFactory.getImsResolver();
4245 if (resolver == null) {
4246 // may happen if the device does not support IMS.
4247 return null;
4248 }
4249 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004253 }
4254
Brad Ebinger5f64b052017-12-14 14:26:15 -08004255 /**
4256 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004257 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004258 */
4259 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4260 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004261
4262 final long identity = Binder.clearCallingIdentity();
4263 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004264 ImsResolver resolver = PhoneFactory.getImsResolver();
4265 if (resolver == null) {
4266 // may happen if the device does not support IMS.
4267 return null;
4268 }
4269 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004273 }
4274
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004275 /**
4276 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004277 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004278 */
4279 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4280 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004281
4282 final long identity = Binder.clearCallingIdentity();
4283 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004284 ImsResolver resolver = PhoneFactory.getImsResolver();
4285 if (resolver == null) {
4286 // may happen if the device does not support IMS.
4287 return null;
4288 }
4289 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004293 }
4294
Brad Ebinger884c07b2018-02-15 16:17:40 -08004295 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004296 * Sets the ImsService Package Name that Telephony will bind to.
4297 *
4298 * @param slotId the slot ID that the ImsService should bind for.
4299 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4300 * ImsService is the device default ImsService.
4301 * @param packageName The package name of the application that contains the ImsService to bind
4302 * to.
4303 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4304 * @hide
4305 */
4306 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004307 int[] subIds = SubscriptionManager.getSubId(slotId);
4308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4309 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4310 "setImsService");
4311
Malcolm Chend965c8b2018-02-28 15:00:40 -08004312 final long identity = Binder.clearCallingIdentity();
4313 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004314 ImsResolver resolver = PhoneFactory.getImsResolver();
4315 if (resolver == null) {
4316 // may happen if the device does not support IMS.
4317 return false;
4318 }
4319 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4320 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004324 }
4325
4326 /**
4327 * Return the ImsService configuration.
4328 *
4329 * @param slotId The slot that the ImsService is associated with.
4330 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4331 * the device default.
4332 * @return the package name of the ImsService configuration.
4333 */
4334 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004335 int[] subIds = SubscriptionManager.getSubId(slotId);
4336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4337 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4338 "getImsService");
4339
Malcolm Chend965c8b2018-02-28 15:00:40 -08004340 final long identity = Binder.clearCallingIdentity();
4341 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004342 ImsResolver resolver = PhoneFactory.getImsResolver();
4343 if (resolver == null) {
4344 // may happen if the device does not support IMS.
4345 return "";
4346 }
4347 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004348 } finally {
4349 Binder.restoreCallingIdentity(identity);
4350 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004351 }
4352
Wink Saville36469e72014-06-11 15:17:00 -07004353 public void setImsRegistrationState(boolean registered) {
4354 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004355
4356 final long identity = Binder.clearCallingIdentity();
4357 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004358 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
Wink Saville36469e72014-06-11 15:17:00 -07004362 }
4363
4364 /**
Stuart Scott54788802015-03-30 13:18:01 -07004365 * Set the network selection mode to automatic.
4366 *
4367 */
4368 @Override
4369 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4371 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004372
Pengquan Meng466e2482018-09-21 15:54:48 -07004373 if (!isActiveSubscription(subId)) {
4374 return;
4375 }
4376
Malcolm Chend965c8b2018-02-28 15:00:40 -08004377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4380 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
Stuart Scott54788802015-03-30 13:18:01 -07004384 }
4385
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004386 /**
4387 * Ask the radio to connect to the input network and change selection mode to manual.
4388 *
4389 * @param subId the id of the subscription.
4390 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4391 * the operator to attach to.
4392 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4393 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4394 * normal network selection next time.
4395 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004396 */
4397 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004398 public boolean setNetworkSelectionModeManual(
4399 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4401 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004402
4403 if (!isActiveSubscription(subId)) {
4404 return false;
4405 }
4406
Malcolm Chend965c8b2018-02-28 15:00:40 -08004407 final long identity = Binder.clearCallingIdentity();
4408 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004409 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004410 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004411 if (DBG) {
4412 log("setNetworkSelectionModeManual: subId: " + subId
4413 + " operator: " + operatorInfo);
4414 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004415 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4416 } finally {
4417 Binder.restoreCallingIdentity(identity);
4418 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004419 }
4420
4421 /**
4422 * Scans for available networks.
4423 */
4424 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004425 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4427 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004428 LocationAccessPolicy.LocationPermissionResult locationResult =
4429 LocationAccessPolicy.checkLocationPermission(mApp,
4430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4431 .setCallingPackage(callingPackage)
4432 .setCallingPid(Binder.getCallingPid())
4433 .setCallingUid(Binder.getCallingUid())
4434 .setMethod("getCellNetworkScanResults")
4435 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4436 .build());
4437 switch (locationResult) {
4438 case DENIED_HARD:
4439 throw new SecurityException("Not allowed to access scan results -- location");
4440 case DENIED_SOFT:
4441 return null;
4442 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004443
Pengquan Meng0c05b502018-09-06 09:59:22 -07004444 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004445 try {
4446 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004447 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004448 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004452 }
4453
4454 /**
yinxub1bed742017-04-17 11:45:04 -07004455 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004456 *
yinxub1bed742017-04-17 11:45:04 -07004457 * @param subId id of the subscription
4458 * @param request contains the radio access networks with bands/channels to scan
4459 * @param messenger callback messenger for scan results or errors
4460 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004461 * @return the id of the requested scan which can be used to stop the scan.
4462 */
4463 @Override
4464 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004465 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4467 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004468 LocationAccessPolicy.LocationPermissionResult locationResult =
4469 LocationAccessPolicy.checkLocationPermission(mApp,
4470 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4471 .setCallingPackage(callingPackage)
4472 .setCallingPid(Binder.getCallingPid())
4473 .setCallingUid(Binder.getCallingUid())
4474 .setMethod("requestNetworkScan")
4475 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4476 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004477 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4478 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4479 if (e != null) {
4480 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4481 throw e;
4482 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004483 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004484 return TelephonyScanManager.INVALID_SCAN_ID;
4485 }
4486 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004487 }
Hall Liubac7d482019-04-25 14:02:26 -07004488 int callingUid = Binder.getCallingUid();
4489 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004490 final long identity = Binder.clearCallingIdentity();
4491 try {
4492 return mNetworkScanRequestTracker.startNetworkScan(
4493 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004494 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004495 } finally {
4496 Binder.restoreCallingIdentity(identity);
4497 }
yinxu504e1392017-04-12 16:03:22 -07004498 }
4499
Hall Liub2ac8ef2019-02-28 15:56:23 -08004500 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4501 NetworkScanRequest request) {
4502 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4503 != PERMISSION_GRANTED) {
4504 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4505 + " without location access.");
4506 }
4507
4508 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4509 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004510 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4511 return new SecurityException("Specific channels must not be"
4512 + " scanned without location access.");
4513 }
4514 }
4515 }
4516
Hall Liub2ac8ef2019-02-28 15:56:23 -08004517 return null;
4518 }
4519
yinxu504e1392017-04-12 16:03:22 -07004520 /**
4521 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004522 *
4523 * @param subId id of the subscription
4524 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004525 */
4526 @Override
4527 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4529 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004530
Hall Liubac7d482019-04-25 14:02:26 -07004531 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004532 final long identity = Binder.clearCallingIdentity();
4533 try {
Hall Liubac7d482019-04-25 14:02:26 -07004534 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
yinxu504e1392017-04-12 16:03:22 -07004538 }
4539
4540 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004541 * Get the calculated preferred network type.
4542 * Used for debugging incorrect network type.
4543 *
4544 * @return the preferred network type, defined in RILConstants.java.
4545 */
4546 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004547 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004548 final Phone defaultPhone = getDefaultPhone();
4549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4550 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004551 return RILConstants.PREFERRED_NETWORK_MODE;
4552 }
4553
Malcolm Chend965c8b2018-02-28 15:00:40 -08004554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004557 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004558 } finally {
4559 Binder.restoreCallingIdentity(identity);
4560 }
Junda Liu84d15a22014-07-02 11:21:04 -07004561 }
4562
4563 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004564 * Get the preferred network type.
4565 * Used for device configuration by some CDMA operators.
4566 *
4567 * @return the preferred network type, defined in RILConstants.java.
4568 */
4569 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004570 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004571 TelephonyPermissions
4572 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4573 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004574
4575 final long identity = Binder.clearCallingIdentity();
4576 try {
4577 if (DBG) log("getPreferredNetworkType");
4578 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4579 int networkType = (result != null ? result[0] : -1);
4580 if (DBG) log("getPreferredNetworkType: " + networkType);
4581 return networkType;
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004585 }
4586
4587 /**
4588 * Set the preferred network type.
4589 * Used for device configuration by some CDMA operators.
4590 *
4591 * @param networkType the preferred network type, defined in RILConstants.java.
4592 * @return true on success; false on any failure.
4593 */
4594 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004595 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4597 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004598
4599 final long identity = Binder.clearCallingIdentity();
4600 try {
4601 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4602 Boolean success = (Boolean) sendRequest(
4603 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4604 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4605 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004606 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004607 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4608 }
4609 return success;
4610 } finally {
4611 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004612 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004613 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004614
4615 /**
Miaoa84611c2019-03-15 09:21:10 +08004616 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004617 *
Miaoa84611c2019-03-15 09:21:10 +08004618 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004619 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004620 * @hide
4621 */
4622 @Override
Miaoa84611c2019-03-15 09:21:10 +08004623 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004624 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004625 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004626 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004627 try {
Miaoa84611c2019-03-15 09:21:10 +08004628 if (phone != null) {
4629 return phone.hasMatchedTetherApnSetting();
4630 } else {
4631 return false;
4632 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004633 } finally {
4634 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004635 }
Junda Liu475951f2014-11-07 16:45:03 -08004636 }
4637
4638 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004639 * Set mobile data enabled
4640 * Used by the user through settings etc to turn on/off mobile data
4641 *
4642 * @param enable {@code true} turn turn data on, else {@code false}
4643 */
4644 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004645 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4647 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004648
4649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 int phoneId = mSubscriptionController.getPhoneId(subId);
4652 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4653 Phone phone = PhoneFactory.getPhone(phoneId);
4654 if (phone != null) {
4655 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004656 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004657 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004658 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004659 }
4660 } finally {
4661 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004662 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004663 }
4664
4665 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004666 * Get the user enabled state of Mobile Data.
4667 *
4668 * TODO: remove and use isUserDataEnabled.
4669 * This can't be removed now because some vendor codes
4670 * calls through ITelephony directly while they should
4671 * use TelephonyManager.
4672 *
4673 * @return true on enabled
4674 */
4675 @Override
4676 public boolean getDataEnabled(int subId) {
4677 return isUserDataEnabled(subId);
4678 }
4679
4680 /**
4681 * Get whether mobile data is enabled per user setting.
4682 *
4683 * There are other factors deciding whether mobile data is actually enabled, but they are
4684 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004685 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004686 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004687 *
4688 * @return {@code true} if data is enabled else {@code false}
4689 */
4690 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004691 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004692 try {
4693 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4694 null);
4695 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4697 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004698 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004699
4700 final long identity = Binder.clearCallingIdentity();
4701 try {
4702 int phoneId = mSubscriptionController.getPhoneId(subId);
4703 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4704 Phone phone = PhoneFactory.getPhone(phoneId);
4705 if (phone != null) {
4706 boolean retVal = phone.isUserDataEnabled();
4707 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4708 return retVal;
4709 } else {
4710 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4711 return false;
4712 }
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004715 }
4716 }
4717
4718 /**
4719 * Get whether mobile data is enabled.
4720 *
4721 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4722 * whether mobile data is actually enabled.
4723 *
4724 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4725 *
4726 * @return {@code true} if data is enabled else {@code false}
4727 */
4728 @Override
4729 public boolean isDataEnabled(int subId) {
4730 try {
4731 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4732 null);
4733 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4735 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004736 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 int phoneId = mSubscriptionController.getPhoneId(subId);
4741 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4742 Phone phone = PhoneFactory.getPhone(phoneId);
4743 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004744 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004745 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4746 return retVal;
4747 } else {
4748 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4749 return false;
4750 }
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004753 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004754 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004755
4756 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004757 public int getCarrierPrivilegeStatus(int subId) {
4758 final Phone phone = getPhone(subId);
4759 if (phone == null) {
4760 loge("getCarrierPrivilegeStatus: Invalid subId");
4761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4762 }
4763 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004764 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004765 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4767 }
4768 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004769 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004770 }
Junda Liu29340342014-07-10 15:23:27 -07004771
4772 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004773 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4774 final Phone phone = getPhone(subId);
4775 if (phone == null) {
4776 loge("getCarrierPrivilegeStatus: Invalid subId");
4777 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4778 }
4779 UiccProfile profile =
4780 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4781 if (profile == null) {
4782 loge("getCarrierPrivilegeStatus: No UICC");
4783 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4784 }
4785 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4786 }
4787
4788 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004789 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004790 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004791 if (TextUtils.isEmpty(pkgName))
4792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004793 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004794 if (card == null) {
4795 loge("checkCarrierPrivilegesForPackage: No UICC");
4796 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4797 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004798 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4799 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004800 }
4801
4802 @Override
4803 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004804 if (TextUtils.isEmpty(pkgName))
4805 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004806 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4807 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4808 UiccCard card = UiccController.getInstance().getUiccCard(i);
4809 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004810 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004811 continue;
4812 }
4813
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004814 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004815 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4816 break;
4817 }
4818 }
4819
4820 return result;
Junda Liu29340342014-07-10 15:23:27 -07004821 }
Derek Tan89e89d42014-07-08 17:00:10 -07004822
4823 @Override
Junda Liue64de782015-04-16 17:19:16 -07004824 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4825 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4826 loge("phoneId " + phoneId + " is not valid.");
4827 return null;
4828 }
4829 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004830 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004831 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004832 return null ;
4833 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004834 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004835 }
4836
Amith Yamasani6e118872016-02-19 12:53:51 -08004837 @Override
4838 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004839 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004840 List<String> privilegedPackages = new ArrayList<>();
4841 List<PackageInfo> packages = null;
4842 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4843 UiccCard card = UiccController.getInstance().getUiccCard(i);
4844 if (card == null) {
4845 // No UICC in that slot.
4846 continue;
4847 }
4848 if (card.hasCarrierPrivilegeRules()) {
4849 if (packages == null) {
4850 // Only check packages in user 0 for now
4851 packages = pm.getInstalledPackagesAsUser(
4852 PackageManager.MATCH_DISABLED_COMPONENTS
4853 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4854 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4855 }
4856 for (int p = packages.size() - 1; p >= 0; p--) {
4857 PackageInfo pkgInfo = packages.get(p);
4858 if (pkgInfo != null && pkgInfo.packageName != null
4859 && card.getCarrierPrivilegeStatus(pkgInfo)
4860 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4861 privilegedPackages.add(pkgInfo.packageName);
4862 }
4863 }
4864 }
4865 }
4866 return privilegedPackages;
4867 }
4868
Wink Savilleb564aae2014-10-23 10:18:09 -07004869 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004870 final Phone phone = getPhone(subId);
4871 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004872 if (card == null) {
4873 loge("getIccId: No UICC");
4874 return null;
4875 }
4876 String iccId = card.getIccId();
4877 if (TextUtils.isEmpty(iccId)) {
4878 loge("getIccId: ICC ID is null or empty.");
4879 return null;
4880 }
4881 return iccId;
4882 }
4883
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004884 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004885 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4886 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004887 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4888 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004889
Malcolm Chend965c8b2018-02-28 15:00:40 -08004890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 final String iccId = getIccId(subId);
4893 final Phone phone = getPhone(subId);
4894 if (phone == null) {
4895 return false;
4896 }
4897 final String subscriberId = phone.getSubscriberId();
4898
4899 if (DBG_MERGE) {
4900 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4901 + subscriberId + " to " + number);
4902 }
4903
4904 if (TextUtils.isEmpty(iccId)) {
4905 return false;
4906 }
4907
4908 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4909
4910 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4911 if (alphaTag == null) {
4912 editor.remove(alphaTagPrefKey);
4913 } else {
4914 editor.putString(alphaTagPrefKey, alphaTag);
4915 }
4916
4917 // Record both the line number and IMSI for this ICCID, since we need to
4918 // track all merged IMSIs based on line number
4919 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4920 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4921 if (number == null) {
4922 editor.remove(numberPrefKey);
4923 editor.remove(subscriberPrefKey);
4924 } else {
4925 editor.putString(numberPrefKey, number);
4926 editor.putString(subscriberPrefKey, subscriberId);
4927 }
4928
4929 editor.commit();
4930 return true;
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004933 }
Derek Tan7226c842014-07-02 17:42:23 -07004934 }
4935
4936 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004937 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004938 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004940 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004941 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004942 return null;
4943 }
Derek Tan97ebb422014-09-05 16:55:38 -07004944
Malcolm Chend965c8b2018-02-28 15:00:40 -08004945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 String iccId = getIccId(subId);
4948 if (iccId != null) {
4949 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4950 if (DBG_MERGE) {
4951 log("getLine1NumberForDisplay returning "
4952 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4953 }
4954 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004955 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004956 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4957 return null;
4958 } finally {
4959 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004960 }
Derek Tan7226c842014-07-02 17:42:23 -07004961 }
4962
4963 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004964 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004966 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004967 return null;
4968 }
Derek Tan97ebb422014-09-05 16:55:38 -07004969
Malcolm Chend965c8b2018-02-28 15:00:40 -08004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 String iccId = getIccId(subId);
4973 if (iccId != null) {
4974 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4975 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4976 }
4977 return null;
4978 } finally {
4979 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004980 }
Derek Tan7226c842014-07-02 17:42:23 -07004981 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004982
4983 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004984 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004985 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4986 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004988 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4989 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004990 return null;
4991 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004992
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004993 final long identity = Binder.clearCallingIdentity();
4994 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004995 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004996 final TelephonyManager tele = TelephonyManager.from(context);
4997 final SubscriptionManager sub = SubscriptionManager.from(context);
4998
4999 // Figure out what subscribers are currently active
5000 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
5001 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5002 // the process, where TelephonyManager was instantiated.
5003 // Otherwise AppOps check will fail.
5004
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005005 final int[] subIds = sub.getActiveSubscriptionIdList();
5006 for (int subId : subIds) {
5007 activeSubscriberIds.add(tele.getSubscriberId(subId));
5008 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005009
5010 // First pass, find a number override for an active subscriber
5011 String mergeNumber = null;
5012 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5013 for (String key : prefs.keySet()) {
5014 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5015 final String subscriberId = (String) prefs.get(key);
5016 if (activeSubscriberIds.contains(subscriberId)) {
5017 final String iccId = key.substring(
5018 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5019 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5020 mergeNumber = (String) prefs.get(numberKey);
5021 if (DBG_MERGE) {
5022 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5023 + " for active subscriber " + subscriberId);
5024 }
5025 if (!TextUtils.isEmpty(mergeNumber)) {
5026 break;
5027 }
5028 }
5029 }
5030 }
5031
5032 // Shortcut when no active merged subscribers
5033 if (TextUtils.isEmpty(mergeNumber)) {
5034 return null;
5035 }
5036
5037 // Second pass, find all subscribers under that line override
5038 final ArraySet<String> result = new ArraySet<>();
5039 for (String key : prefs.keySet()) {
5040 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5041 final String number = (String) prefs.get(key);
5042 if (mergeNumber.equals(number)) {
5043 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5044 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5045 final String subscriberId = (String) prefs.get(subscriberKey);
5046 if (!TextUtils.isEmpty(subscriberId)) {
5047 result.add(subscriberId);
5048 }
5049 }
5050 }
5051 }
5052
5053 final String[] resultArray = result.toArray(new String[result.size()]);
5054 Arrays.sort(resultArray);
5055 if (DBG_MERGE) {
5056 Slog.d(LOG_TAG,
5057 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5058 }
5059 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005060 } finally {
5061 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005062 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005063 }
5064
5065 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005066 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005067 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5068 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005069
5070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 final Phone phone = getPhone(subId);
5073 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5074 } finally {
5075 Binder.restoreCallingIdentity(identity);
5076 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005077 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005078
5079 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005080 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005081 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5082 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005083 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005084
5085 final long identity = Binder.clearCallingIdentity();
5086 try {
5087 final Phone phone = getPhone(subId);
5088 if (phone == null) {
5089 return false;
5090 }
5091 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5092 cdmaNonRoamingList);
5093 } finally {
5094 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005095 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005096 }
5097
5098 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005099 @Deprecated
5100 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5101 enforceModifyPermission();
5102
5103 int returnValue = 0;
5104 try {
vagdevie435a3e2018-08-15 16:01:53 -07005105 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005106 if(result.exception == null) {
5107 if (result.result != null) {
5108 byte[] responseData = (byte[])(result.result);
5109 if(responseData.length > oemResp.length) {
5110 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5111 responseData.length + "bytes. Buffer Size is " +
5112 oemResp.length + "bytes.");
5113 }
5114 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5115 returnValue = responseData.length;
5116 }
5117 } else {
5118 CommandException ex = (CommandException) result.exception;
5119 returnValue = ex.getCommandError().ordinal();
5120 if(returnValue > 0) returnValue *= -1;
5121 }
5122 } catch (RuntimeException e) {
5123 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5124 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5125 if(returnValue > 0) returnValue *= -1;
5126 }
5127
5128 return returnValue;
5129 }
5130
5131 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005132 public void setRadioCapability(RadioAccessFamily[] rafs) {
5133 try {
5134 ProxyController.getInstance().setRadioCapability(rafs);
5135 } catch (RuntimeException e) {
5136 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5137 }
5138 }
5139
5140 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005141 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005142 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005143 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005144 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005145 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005146 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005147 final long identity = Binder.clearCallingIdentity();
5148 try {
chen xufeeed752018-10-26 14:17:57 -07005149 TelephonyPermissions
5150 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5151 mApp, phone.getSubId(), "getRadioAccessFamily");
5152 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
chen xufeeed752018-10-26 14:17:57 -07005156 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005157 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005158
5159 @Override
5160 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005161 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005162 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005163
5164 final long identity = Binder.clearCallingIdentity();
5165 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005166 ImsManager.getInstance(defaultPhone.getContext(),
5167 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005168 } finally {
5169 Binder.restoreCallingIdentity(identity);
5170 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005171 }
5172
5173 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005174 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005175 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005177 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005178 return false;
5179 }
Svet Ganovb320e182015-04-16 12:30:10 -07005180
Malcolm Chend965c8b2018-02-28 15:00:40 -08005181 final long identity = Binder.clearCallingIdentity();
5182 try {
5183 // Check the user preference and the system-level IMS setting. Even if the user has
5184 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5185 // In the long run, we may instead need to check if there exists a connection service
5186 // which can support video calling.
5187 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005188 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005189 return imsManager.isVtEnabledByPlatform()
5190 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5191 && imsManager.isVtEnabledByUser();
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005195 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005196
Andrew Leea1239f22015-03-02 17:44:07 -08005197 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005198 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5199 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5200 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5201 return false;
5202 }
5203
5204 final long identity = Binder.clearCallingIdentity();
5205 try {
5206 CarrierConfigManager configManager =
5207 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005208 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005209 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
Andrew Leea1239f22015-03-02 17:44:07 -08005213 }
5214
5215 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005216 public boolean isWorldPhone(int subId, String callingPackage) {
5217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5218 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5219 return false;
5220 }
5221
5222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 CarrierConfigManager configManager =
5225 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005226 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005227 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Andrew Leea1239f22015-03-02 17:44:07 -08005231 }
5232
Andrew Lee9431b832015-03-09 18:46:45 -07005233 @Override
5234 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005235 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005236 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005237 }
5238
5239 @Override
5240 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
5242 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005243 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Andrew Lee9431b832015-03-09 18:46:45 -07005247 }
5248
Hall Liuf6668912018-10-31 17:05:23 -07005249 /**
5250 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5251 * support for the feature and device firmware support.
5252 *
5253 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5254 */
5255 @Override
5256 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005257 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005258 final Phone phone = getPhone(subscriptionId);
5259 if (phone == null) {
5260 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5261 return false;
5262 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005263 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005264 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005265 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5266 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005267 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005268 return isCarrierSupported && isDeviceSupported;
5269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
Hall Liu98187582018-01-22 19:15:32 -08005272 }
5273
Hall Liuf6668912018-10-31 17:05:23 -07005274 /**
5275 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5276 * both also support RTT.
5277 */
5278 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005279 final long identity = Binder.clearCallingIdentity();
5280 try {
Hall Liuf6668912018-10-31 17:05:23 -07005281 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005282 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005286 }
5287
Sanket Padawe7310cc72015-01-14 09:53:20 -08005288 /**
5289 * Returns the unique device ID of phone, for example, the IMEI for
5290 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5291 *
5292 * <p>Requires Permission:
5293 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5294 */
5295 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005296 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005297 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005298 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005299 return null;
5300 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005301 int subId = phone.getSubId();
5302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5303 mApp, subId, callingPackage, "getDeviceId")) {
5304 return null;
5305 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005306
5307 final long identity = Binder.clearCallingIdentity();
5308 try {
5309 return phone.getDeviceId();
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
5312 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005313 }
5314
Ping Sunc67b7c22016-03-02 19:16:45 +08005315 /**
5316 * {@hide}
5317 * Returns the IMS Registration Status on a particular subid
5318 *
5319 * @param subId
5320 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005321 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005322 Phone phone = getPhone(subId);
5323 if (phone != null) {
5324 return phone.isImsRegistered();
5325 } else {
5326 return false;
5327 }
5328 }
5329
Santos Cordon7a1885b2015-02-03 11:15:19 -08005330 @Override
5331 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005338 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005339
Tyler Gunn327a9722019-04-03 15:28:53 -07005340 @Override
5341 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5342 final long identity = Binder.clearCallingIdentity();
5343 try {
5344 Phone phone = getPhone(subscriptionId);
5345 if (phone == null) {
5346 return null;
5347 }
5348 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
5352 }
5353
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005354 /**
5355 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005356 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005357 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005358 final long identity = Binder.clearCallingIdentity();
5359 try {
5360 Phone phone = getPhone(subId);
5361 if (phone != null) {
5362 return phone.isWifiCallingEnabled();
5363 } else {
5364 return false;
5365 }
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005368 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005369 }
5370
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005371 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005372 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005373 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005374 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 Phone phone = getPhone(subId);
5378 if (phone != null) {
5379 return phone.isVideoEnabled();
5380 } else {
5381 return false;
5382 }
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005385 }
5386 }
5387
5388 /**
5389 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5390 * defined in {@link ImsRegistrationImplBase}.
5391 */
5392 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
5395 Phone phone = getPhone(subId);
5396 if (phone != null) {
5397 return phone.getImsRegistrationTech();
5398 } else {
5399 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5400 }
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005403 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005404 }
5405
Stuart Scott8eef64f2015-04-08 15:13:54 -07005406 @Override
5407 public void factoryReset(int subId) {
5408 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005409 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5410 return;
5411 }
5412
Svet Ganovcc087f82015-05-12 20:35:54 -07005413 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005414
Svet Ganovcc087f82015-05-12 20:35:54 -07005415 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005416 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5417 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005418 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005419 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005420 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005421 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5422 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005423 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005424 // There has been issues when Sms raw table somehow stores orphan
5425 // fragments. They lead to garbled message when new fragments come
5426 // in and combined with those stale ones. In case this happens again,
5427 // user can reset all network settings which will clean up this table.
5428 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005431 }
5432 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005433
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005434 private void cleanUpSmsRawTable(Context context) {
5435 ContentResolver resolver = context.getContentResolver();
5436 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5437 resolver.delete(uri, null, null);
5438 }
5439
Narayan Kamath1c496c22015-04-16 14:40:19 +01005440 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005441 public String getSimLocaleForSubscriber(int subId) {
5442 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5443 final Phone phone = getPhone(subId);
5444 if (phone == null) {
5445 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005446 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005447 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005450 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5451 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005452 // Try and fetch the locale from the carrier properties or from the SIM language
5453 // preferences (EF-PL and EF-LI)...
5454 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005455 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005456 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5457 if (localeFromDefaultSim != null) {
5458 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5459 if (DBG) log("Using locale from subId: " + subId + " locale: "
5460 + localeFromDefaultSim);
5461 return localeFromDefaultSim.toLanguageTag();
5462 } else {
5463 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005464 }
5465 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005466
Malcolm Chend965c8b2018-02-28 15:00:40 -08005467 // The SIM language preferences only store a language (e.g. fr = French), not an
5468 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5469 // the SIM and carrier preferences does not include a country we add the country
5470 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005471 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005472 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005473 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005474 return mccLocale.toLanguageTag();
5475 }
5476
5477 if (DBG) log("No locale found - returning null");
5478 return null;
5479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005482 }
5483
5484 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005485 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005486 }
5487
Malcolm Chend965c8b2018-02-28 15:00:40 -08005488 /**
5489 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5490 */
5491 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005492 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005493 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005494
Chenjie Yu1ba97252018-01-11 18:16:20 -08005495 private final ModemActivityInfo mLastModemActivityInfo =
5496 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5497
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005498 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005499 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5500 * representing the state of the modem.
5501 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005502 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5503 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005504 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005505 */
5506 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005507 public void requestModemActivityInfo(ResultReceiver result) {
5508 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005510
5511 final long identity = Binder.clearCallingIdentity();
5512 try {
5513 ModemActivityInfo ret = null;
5514 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005515 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5516 CMD_GET_MODEM_ACTIVITY_INFO,
5517 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005518 if (isModemActivityInfoValid(info)) {
5519 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5520 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5521 mergedTxTimeMs[i] =
5522 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5523 }
5524 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5525 mLastModemActivityInfo.setSleepTimeMillis(
5526 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5527 mLastModemActivityInfo.setIdleTimeMillis(
5528 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5529 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5530 mLastModemActivityInfo.setRxTimeMillis(
5531 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5532 mLastModemActivityInfo.setEnergyUsed(
5533 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005534 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005535 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5536 mLastModemActivityInfo.getSleepTimeMillis(),
5537 mLastModemActivityInfo.getIdleTimeMillis(),
5538 mLastModemActivityInfo.getTxTimeMillis(),
5539 mLastModemActivityInfo.getRxTimeMillis(),
5540 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005541 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005542 Bundle bundle = new Bundle();
5543 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5544 result.send(0, bundle);
5545 } finally {
5546 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005547 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005548 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005549
Siddharth Rayf5d29552018-06-17 15:02:38 -07005550 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5551 // less than total activity duration.
5552 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5553 if (info == null) {
5554 return false;
5555 }
5556 int activityDurationMs =
5557 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5558 int totalTxTimeMs = 0;
5559 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5560 totalTxTimeMs += info.getTxTimeMillis()[i];
5561 }
5562 return (info.isValid()
5563 && (info.getSleepTimeMillis() <= activityDurationMs)
5564 && (info.getIdleTimeMillis() <= activityDurationMs)
5565 && (info.getRxTimeMillis() <= activityDurationMs)
5566 && (totalTxTimeMs <= activityDurationMs));
5567 }
5568
Jack Yu85bd38a2015-11-09 11:34:32 -08005569 /**
5570 * {@hide}
5571 * Returns the service state information on specified subscription.
5572 */
5573 @Override
5574 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005576 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005577 return null;
5578 }
5579
Hall Liuf19c44f2018-11-27 14:38:17 -08005580 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5581 LocationAccessPolicy.checkLocationPermission(mApp,
5582 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5583 .setCallingPackage(callingPackage)
5584 .setCallingPid(Binder.getCallingPid())
5585 .setCallingUid(Binder.getCallingUid())
5586 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005587 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005588 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5589 .build());
5590
5591 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5592 LocationAccessPolicy.checkLocationPermission(mApp,
5593 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5594 .setCallingPackage(callingPackage)
5595 .setCallingPid(Binder.getCallingPid())
5596 .setCallingUid(Binder.getCallingUid())
5597 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005598 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005599 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5600 .build());
5601 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5602 boolean hasFinePermission =
5603 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5604 boolean hasCoarsePermission =
5605 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5606
Malcolm Chend965c8b2018-02-28 15:00:40 -08005607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 final Phone phone = getPhone(subId);
5610 if (phone == null) {
5611 return null;
5612 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005613
Hall Liuf19c44f2018-11-27 14:38:17 -08005614 ServiceState ss = phone.getServiceState();
5615
5616 // Scrub out the location info in ServiceState depending on what level of access
5617 // the caller has.
5618 if (hasFinePermission) return ss;
5619 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5620 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005624 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005625
5626 /**
5627 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5628 *
5629 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5630 * voicemail ringtone.
5631 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5632 * PhoneAccount.
5633 */
5634 @Override
5635 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5639 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005640 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005641 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005642
Malcolm Chend965c8b2018-02-28 15:00:40 -08005643 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005647 }
5648
5649 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005650 * Sets the per-account voicemail ringtone.
5651 *
5652 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5653 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5654 *
5655 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5656 * voicemail ringtone.
5657 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5658 * PhoneAccount.
5659 */
5660 @Override
5661 public void setVoicemailRingtoneUri(String callingPackage,
5662 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005663 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005664 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5665 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005666 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5668 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5669 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005670 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005671
5672 final long identity = Binder.clearCallingIdentity();
5673 try {
5674 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5675 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005676 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005677 }
5678 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5679 } finally {
5680 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005681 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005682 }
5683
5684 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005685 * Returns whether vibration is set for voicemail notification in Phone settings.
5686 *
5687 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5688 * voicemail vibration setting.
5689 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5690 */
5691 @Override
5692 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5696 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005697 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005698 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005699
Malcolm Chend965c8b2018-02-28 15:00:40 -08005700 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005704 }
5705
Youhan Wange64578a2016-05-02 15:32:42 -07005706 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005707 * Sets the per-account voicemail vibration.
5708 *
5709 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5710 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5711 *
5712 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5713 * voicemail vibration setting.
5714 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5715 * specific PhoneAccount.
5716 */
5717 @Override
5718 public void setVoicemailVibrationEnabled(String callingPackage,
5719 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005720 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5722 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005723 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5725 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5726 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005727 }
5728
Malcolm Chend965c8b2018-02-28 15:00:40 -08005729 final long identity = Binder.clearCallingIdentity();
5730 try {
5731 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5732 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005733 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005734 }
5735 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005738 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005739 }
5740
5741 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005742 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5743 *
5744 * @throws SecurityException if the caller does not have the required permission
5745 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005746 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005747 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005748 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005749 }
5750
5751 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005752 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5753 * permission.
5754 *
5755 * @throws SecurityException if the caller does not have the required permission
5756 */
5757 private void enforceSendSmsPermission() {
5758 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5759 }
5760
5761 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005762 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005763 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005764 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005765 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005766 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005770 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005771 if (componentName == null) {
5772 throw new SecurityException(
5773 "Caller not current active visual voicemail package[null]");
5774 }
5775 String vvmPackage = componentName.getPackageName();
5776 if (!callingPackage.equals(vvmPackage)) {
5777 throw new SecurityException("Caller not current active visual voicemail package["
5778 + vvmPackage + "]");
5779 }
5780 } finally {
5781 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005782 }
5783 }
5784
5785 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005786 * Return the application ID for the app type.
5787 *
5788 * @param subId the subscription ID that this request applies to.
5789 * @param appType the uicc app type.
5790 * @return Application ID for specificied app type, or null if no uicc.
5791 */
5792 @Override
5793 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005794 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005795 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005796
5797 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005798 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005799 if (phone == null) {
5800 return null;
5801 }
5802 String aid = null;
5803 try {
5804 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5805 .getApplicationByType(appType).getAid();
5806 } catch (Exception e) {
5807 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5808 }
5809 return aid;
5810 } finally {
5811 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005812 }
Youhan Wange64578a2016-05-02 15:32:42 -07005813 }
5814
Youhan Wang4001d252016-05-11 10:29:41 -07005815 /**
5816 * Return the Electronic Serial Number.
5817 *
5818 * @param subId the subscription ID that this request applies to.
5819 * @return ESN or null if error.
5820 */
5821 @Override
5822 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005823 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005824 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005825
5826 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005827 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005828 if (phone == null) {
5829 return null;
5830 }
5831 String esn = null;
5832 try {
5833 esn = phone.getEsn();
5834 } catch (Exception e) {
5835 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5836 }
5837 return esn;
5838 } finally {
5839 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005840 }
Youhan Wang4001d252016-05-11 10:29:41 -07005841 }
5842
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005843 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005844 * Return the Preferred Roaming List Version.
5845 *
5846 * @param subId the subscription ID that this request applies to.
5847 * @return PRLVersion or null if error.
5848 */
5849 @Override
5850 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005851 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005852 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005853
5854 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005855 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005856 if (phone == null) {
5857 return null;
5858 }
5859 String cdmaPrlVersion = null;
5860 try {
5861 cdmaPrlVersion = phone.getCdmaPrlVersion();
5862 } catch (Exception e) {
5863 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5864 }
5865 return cdmaPrlVersion;
5866 } finally {
5867 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005868 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005869 }
5870
5871 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005872 * Get snapshot of Telephony histograms
5873 * @return List of Telephony histograms
5874 * @hide
5875 */
5876 @Override
5877 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5879 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005880
5881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 return RIL.getTelephonyRILTimingHistograms();
5884 } finally {
5885 Binder.restoreCallingIdentity(identity);
5886 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005887 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005888
5889 /**
5890 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005891 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5892 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005893 * Require system privileges. In the future we may add this to carrier APIs.
5894 *
Michele Berionne0963c862018-11-27 18:57:59 -08005895 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005896 */
5897 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005898 @TelephonyManager.SetCarrierRestrictionResult
5899 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005900 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005901 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005902
Michele Berionne0963c862018-11-27 18:57:59 -08005903 if (carrierRestrictionRules == null) {
5904 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005905 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005906
Malcolm Chend965c8b2018-02-28 15:00:40 -08005907 final long identity = Binder.clearCallingIdentity();
5908 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005909 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005910 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005914 }
5915
5916 /**
5917 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005918 * Get the allowed carrier list and the excluded carrier list, including the priority between
5919 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005920 * Require system privileges. In the future we may add this to carrier APIs.
5921 *
Michele Berionne0963c862018-11-27 18:57:59 -08005922 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005923 */
5924 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005925 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005926 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005927 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005928
5929 final long identity = Binder.clearCallingIdentity();
5930 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005931 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5932 if (response instanceof CarrierRestrictionRules) {
5933 return (CarrierRestrictionRules) response;
5934 }
5935 // Response is an Exception of some kind,
5936 // which is signalled to the user as a NULL retval
5937 return null;
5938 } catch (Exception e) {
5939 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5940 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005944 }
5945
fionaxu59545b42016-05-25 15:53:37 -07005946 /**
5947 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5948 * @param subId the subscription ID that this action applies to.
5949 * @param enabled control enable or disable metered apns.
5950 * {@hide}
5951 */
5952 @Override
5953 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5954 enforceModifyPermission();
5955 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005956
5957 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005958 if (phone == null) {
5959 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5960 return;
5961 }
5962 try {
5963 phone.carrierActionSetMeteredApnsEnabled(enabled);
5964 } catch (Exception e) {
5965 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005966 } finally {
5967 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005968 }
5969 }
5970
5971 /**
5972 * Action set from carrier signalling broadcast receivers to enable/disable radio
5973 * @param subId the subscription ID that this action applies to.
5974 * @param enabled control enable or disable radio.
5975 * {@hide}
5976 */
5977 @Override
5978 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5979 enforceModifyPermission();
5980 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005981
5982 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005983 if (phone == null) {
5984 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5985 return;
5986 }
5987 try {
5988 phone.carrierActionSetRadioEnabled(enabled);
5989 } catch (Exception e) {
5990 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005991 } finally {
5992 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005993 }
5994 }
5995
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005996 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005997 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5998 * network status based on which carrier apps could apply actions accordingly,
5999 * enable/disable default url handler for example.
6000 *
6001 * @param subId the subscription ID that this action applies to.
6002 * @param report control start/stop reporting the default network status.
6003 * {@hide}
6004 */
6005 @Override
6006 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6007 enforceModifyPermission();
6008 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006009
6010 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006011 if (phone == null) {
6012 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6013 return;
6014 }
6015 try {
6016 phone.carrierActionReportDefaultNetworkStatus(report);
6017 } catch (Exception e) {
6018 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006019 } finally {
6020 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006021 }
6022 }
6023
6024 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006025 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6026 * bug report is being generated.
6027 */
6028 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006029 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006030 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6031 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006032 writer.println("Permission Denial: can't dump Phone from pid="
6033 + Binder.getCallingPid()
6034 + ", uid=" + Binder.getCallingUid()
6035 + "without permission "
6036 + android.Manifest.permission.DUMP);
6037 return;
6038 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006039 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006040 }
Jack Yueb89b242016-06-22 13:27:47 -07006041
Brad Ebingerdac2f002018-04-03 15:17:52 -07006042 @Override
6043 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6044 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6045 throws RemoteException {
6046 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6047 }
6048
Jack Yueb89b242016-06-22 13:27:47 -07006049 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006050 * Get aggregated video call data usage since boot.
6051 *
6052 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6053 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006054 * {@hide}
6055 */
6056 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006057 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006058 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6059 null);
6060
Malcolm Chend965c8b2018-02-28 15:00:40 -08006061 final long identity = Binder.clearCallingIdentity();
6062 try {
6063 // NetworkStatsService keeps tracking the active network interface and identity. It
6064 // records the delta with the corresponding network identity.
6065 // We just return the total video call data usage snapshot since boot.
6066 Phone phone = getPhone(subId);
6067 if (phone != null) {
6068 return phone.getVtDataUsage(perUidStats);
6069 }
6070 return null;
6071 } finally {
6072 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006073 }
Jack Yueb89b242016-06-22 13:27:47 -07006074 }
Jack Yu75ab2952016-07-08 14:29:33 -07006075
6076 /**
6077 * Policy control of data connection. Usually used when data limit is passed.
6078 * @param enabled True if enabling the data, otherwise disabling.
6079 * @param subId Subscription index
6080 * {@hide}
6081 */
6082 @Override
6083 public void setPolicyDataEnabled(boolean enabled, int subId) {
6084 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 Phone phone = getPhone(subId);
6089 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006090 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006091 }
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006094 }
6095 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006096
6097 /**
6098 * Get Client request stats
6099 * @return List of Client Request Stats
6100 * @hide
6101 */
6102 @Override
6103 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006104 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006105 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006106 return null;
6107 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006108 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006109
Malcolm Chend965c8b2018-02-28 15:00:40 -08006110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 if (phone != null) {
6113 return phone.getClientRequestStats();
6114 }
6115
6116 return null;
6117 } finally {
6118 Binder.restoreCallingIdentity(identity);
6119 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006120 }
6121
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006122 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006123 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006124 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006125 }
Jack Yueb4124c2017-02-16 15:32:43 -08006126
6127 /**
Grace Chen70990072017-03-24 17:21:30 -07006128 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006129 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006130 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006131 * @param state State of SIM (power down, power up, pass through)
6132 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6133 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6134 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006135 *
6136 **/
6137 @Override
Grace Chen70990072017-03-24 17:21:30 -07006138 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006139 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006140 Phone phone = PhoneFactory.getPhone(slotIndex);
6141
vagdevie435a3e2018-08-15 16:01:53 -07006142 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6143
Malcolm Chend965c8b2018-02-28 15:00:40 -08006144 final long identity = Binder.clearCallingIdentity();
6145 try {
6146 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006147 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006148 }
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006151 }
6152 }
Shuo Qiandd210312017-04-12 22:11:33 +00006153
Tyler Gunn65d45c22017-06-05 11:22:26 -07006154 private boolean isUssdApiAllowed(int subId) {
6155 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006156 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006157 if (configManager == null) {
6158 return false;
6159 }
6160 PersistableBundle pb = configManager.getConfigForSubId(subId);
6161 if (pb == null) {
6162 return false;
6163 }
6164 return pb.getBoolean(
6165 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6166 }
6167
Shuo Qiandd210312017-04-12 22:11:33 +00006168 /**
6169 * Check if phone is in emergency callback mode
6170 * @return true if phone is in emergency callback mode
6171 * @param subId sub id
6172 */
goneil9c5f4872017-12-05 14:07:56 -08006173 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006174 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006175 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006176 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006177
6178 final long identity = Binder.clearCallingIdentity();
6179 try {
6180 if (phone != null) {
6181 return phone.isInEcm();
6182 } else {
6183 return false;
6184 }
6185 } finally {
6186 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006187 }
6188 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006189
6190 /**
6191 * Get the current signal strength information for the given subscription.
6192 * Because this information is not updated when the device is in a low power state
6193 * it should not be relied-upon to be current.
6194 * @param subId Subscription index
6195 * @return the most recent cached signal strength info from the modem
6196 */
6197 @Override
6198 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006199 final long identity = Binder.clearCallingIdentity();
6200 try {
6201 Phone p = getPhone(subId);
6202 if (p == null) {
6203 return null;
6204 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006205
Malcolm Chend965c8b2018-02-28 15:00:40 -08006206 return p.getSignalStrength();
6207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006210 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006211
Pengquan Meng9140aec2018-08-22 14:49:57 -07006212 /**
chen xu907e5a22018-10-11 13:21:04 -07006213 * Get the current modem radio state for the given slot.
6214 * @param slotIndex slot index.
6215 * @param callingPackage the name of the package making the call.
6216 * @return the current radio power state from the modem
6217 */
6218 @Override
6219 public int getRadioPowerState(int slotIndex, String callingPackage) {
6220 Phone phone = PhoneFactory.getPhone(slotIndex);
6221 if (phone != null) {
6222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6223 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6224 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6225 }
6226
6227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 return phone.getRadioPowerState();
6230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
6233 }
6234 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6235 }
6236
6237 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006238 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6239 *
6240 * <p>Requires one of the following permissions:
6241 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6242 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6243 * privileges.
6244 *
6245 * @param subId subscription id
6246 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6247 * {@code false}.
6248 */
6249 @Override
6250 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006251 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6252 null /* message */);
6253
Pengquan Meng0c05b502018-09-06 09:59:22 -07006254 boolean isEnabled = false;
6255 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006256 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006257 Phone phone = getPhone(subId);
6258 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006259 } catch (Exception e) {
6260 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6261 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006262 } finally {
6263 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006264 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006265 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006266 }
6267
6268
6269 /**
6270 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6271 *
6272 * <p> Requires permission:
6273 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6274 * privileges.
6275 *
6276 * @param subId subscription id
6277 * @param isEnabled {@code true} means enable, {@code false} means disable.
6278 */
6279 @Override
6280 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6282 mApp, subId, "setDataRoamingEnabled");
6283
Pengquan Meng0c05b502018-09-06 09:59:22 -07006284 final long identity = Binder.clearCallingIdentity();
6285 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006286 Phone phone = getPhone(subId);
6287 if (phone != null) {
6288 phone.setDataRoamingEnabled(isEnabled);
6289 }
6290 } finally {
6291 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006292 }
6293 }
6294
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006295 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006296 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006297 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6298 mApp, subId, "isManualNetworkSelectionAllowed");
6299
Pengquan Meng312de0c2018-10-03 12:19:13 -07006300 boolean isAllowed = true;
6301 final long identity = Binder.clearCallingIdentity();
6302 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006303 Phone phone = getPhone(subId);
6304 if (phone != null) {
6305 isAllowed = phone.isCspPlmnEnabled();
6306 }
6307 } finally {
6308 Binder.restoreCallingIdentity(identity);
6309 }
6310 return isAllowed;
6311 }
6312
6313 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006314 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006315 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006316 try {
6317 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006318 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006319 } catch (SecurityException e) {
6320 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6321 // has carrier privileges on an active UICC
6322 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6323 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006324 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006325 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006326 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006327
6328 final long identity = Binder.clearCallingIdentity();
6329 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006330 UiccController uiccController = UiccController.getInstance();
6331 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006332 if (hasReadPermission) {
6333 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006334 }
Jordan Liu67997952019-04-22 15:10:43 -07006335
6336 // Remove private info if the caller doesn't have access
6337 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6338 for (UiccCardInfo cardInfo : cardInfos) {
6339 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6340 // is available
6341 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6342 if (card == null || card.getUiccProfile() == null) {
6343 // assume no access if the card or profile is unavailable
6344 filteredInfos.add(cardInfo.getUnprivileged());
6345 continue;
6346 }
6347 UiccProfile profile = card.getUiccProfile();
6348 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6349 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6350 filteredInfos.add(cardInfo);
6351 } else {
6352 filteredInfos.add(cardInfo.getUnprivileged());
6353 }
6354 }
6355 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
6359 }
6360
6361 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006362 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006363 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006364
Malcolm Chend965c8b2018-02-28 15:00:40 -08006365 final long identity = Binder.clearCallingIdentity();
6366 try {
6367 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6368 if (slots == null) {
6369 Rlog.i(LOG_TAG, "slots is null.");
6370 return null;
6371 }
6372
6373 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6374 for (int i = 0; i < slots.length; i++) {
6375 UiccSlot slot = slots[i];
6376 if (slot == null) {
6377 continue;
6378 }
6379
6380 String cardId;
6381 UiccCard card = slot.getUiccCard();
6382 if (card != null) {
6383 cardId = card.getCardId();
6384 } else {
6385 cardId = slot.getIccId();
6386 }
6387
6388 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
7013 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chen29739692019-04-18 13:51:02 -07007014 apnType), phone);
7015 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7016 } finally {
7017 Binder.restoreCallingIdentity(identity);
7018 }
7019 }
7020
7021 @Override
7022 public boolean isApnMetered(int apnType, int subId) {
7023 enforceReadPrivilegedPermission("isApnMetered");
7024
7025 // Now that all security checks passes, perform the operation as ourselves.
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 Phone phone = getPhone(subId);
7029 if (phone == null) return true; // By default return true.
7030
7031 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
7032 apnType), phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07007033 } finally {
7034 Binder.restoreCallingIdentity(identity);
7035 }
7036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007037}