blob: bdf66dfa1024a8ebeaeffdf6aee0984c98b6bb6a [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
2142 final Phone phone = getPhone(subId);
2143 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2144
2145 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2146 }
2147
2148 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002150 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002155 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002156 } finally {
2157 Binder.restoreCallingIdentity(identity);
2158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
Shishir Agrawala9f32182016-04-12 12:00:16 -07002161 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002162 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002163 Phone phone = PhoneFactory.getPhone(slotIndex);
2164 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002165 return null;
2166 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002167 int subId = phone.getSubId();
2168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2169 mApp, subId, callingPackage, "getImeiForSlot")) {
2170 return null;
2171 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 return phone.getImei();
2176 } finally {
2177 Binder.restoreCallingIdentity(identity);
2178 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002179 }
2180
2181 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002182 public String getTypeAllocationCodeForSlot(int slotIndex) {
2183 Phone phone = PhoneFactory.getPhone(slotIndex);
2184 String tac = null;
2185 if (phone != null) {
2186 String imei = phone.getImei();
2187 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2188 }
2189 return tac;
2190 }
2191
2192 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002193 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002194 Phone phone = PhoneFactory.getPhone(slotIndex);
2195 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002196 return null;
2197 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002198
Jeff Davidson913390f2018-02-23 17:11:49 -08002199 int subId = phone.getSubId();
2200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2201 mApp, subId, callingPackage, "getMeidForSlot")) {
2202 return null;
2203 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002204
2205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 return phone.getMeid();
2208 } finally {
2209 Binder.restoreCallingIdentity(identity);
2210 }
Jack Yu2af8d712017-03-15 17:14:14 -07002211 }
2212
2213 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002214 public String getManufacturerCodeForSlot(int slotIndex) {
2215 Phone phone = PhoneFactory.getPhone(slotIndex);
2216 String manufacturerCode = null;
2217 if (phone != null) {
2218 String meid = phone.getMeid();
2219 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2220 }
2221 return manufacturerCode;
2222 }
2223
2224 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002225 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002226 Phone phone = PhoneFactory.getPhone(slotIndex);
2227 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002228 return null;
2229 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002230 int subId = phone.getSubId();
2231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2232 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2233 return null;
2234 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002235
2236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 return phone.getDeviceSvn();
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
2241 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002242 }
2243
fionaxu43304da2017-11-27 22:51:16 -08002244 @Override
2245 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002246 final long identity = Binder.clearCallingIdentity();
2247 try {
2248 final Phone phone = getPhone(subId);
2249 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
2252 }
fionaxu43304da2017-11-27 22:51:16 -08002253 }
2254
2255 @Override
2256 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 final Phone phone = getPhone(subId);
2260 return phone == null ? null : phone.getCarrierName();
2261 } finally {
2262 Binder.restoreCallingIdentity(identity);
2263 }
fionaxu43304da2017-11-27 22:51:16 -08002264 }
2265
calvinpaneed9ae82018-11-01 19:43:06 +08002266 @Override
chen xua31f22b2019-03-06 15:28:50 -08002267 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002268 final long identity = Binder.clearCallingIdentity();
2269 try {
2270 final Phone phone = getPhone(subId);
2271 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002272 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002273 } finally {
2274 Binder.restoreCallingIdentity(identity);
2275 }
2276 }
2277
2278 @Override
chen xua31f22b2019-03-06 15:28:50 -08002279 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002280 final long identity = Binder.clearCallingIdentity();
2281 try {
2282 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002283 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002284 } finally {
2285 Binder.restoreCallingIdentity(identity);
2286 }
2287 }
2288
chen xu02581692018-11-11 19:03:44 -08002289 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002290 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2291 if (!isSubscriptionMccMnc) {
2292 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2293 }
chen xu02581692018-11-11 19:03:44 -08002294 final Phone phone = PhoneFactory.getPhone(slotIndex);
2295 if (phone == null) {
2296 return TelephonyManager.UNKNOWN_CARRIER_ID;
2297 }
2298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2301 } finally {
2302 Binder.restoreCallingIdentity(identity);
2303 }
2304 }
2305
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 //
2307 // Internal helper methods.
2308 //
2309
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002310 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2312 *
2313 * @throws SecurityException if the caller does not have the required permission
2314 */
2315 private void enforceModifyPermission() {
2316 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2317 }
2318
2319 /**
2320 * Make sure the caller has the CALL_PHONE permission.
2321 *
2322 * @throws SecurityException if the caller does not have the required permission
2323 */
2324 private void enforceCallPermission() {
2325 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2326 }
2327
Stuart Scott8eef64f2015-04-08 15:13:54 -07002328 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002329 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002330 "ConnectivityService");
2331 }
2332
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 private String createTelUrl(String number) {
2334 if (TextUtils.isEmpty(number)) {
2335 return null;
2336 }
2337
Jake Hambye994d462014-02-03 13:10:13 -08002338 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
Ihab Awadf9e92732013-12-05 18:02:52 -08002341 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2343 }
2344
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002345 private static void logv(String msg) {
2346 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2347 }
2348
Ihab Awadf9e92732013-12-05 18:02:52 -08002349 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2351 }
2352
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002353 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002355 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002356 }
2357
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002359 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 final Phone phone = PhoneFactory.getPhone(slotIndex);
2363 if (phone == null) {
2364 return PhoneConstants.PHONE_TYPE_NONE;
2365 } else {
2366 return phone.getPhoneType();
2367 }
2368 } finally {
2369 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
2373 /**
2374 * Returns the CDMA ERI icon index to display
2375 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002376 @Override
2377 public int getCdmaEriIconIndex(String callingPackage) {
2378 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002379 }
2380
Sanket Padawe356d7632015-06-22 14:03:32 -07002381 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002382 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002384 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002385 return -1;
2386 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 if (phone != null) {
2392 return phone.getCdmaEriIconIndex();
2393 } else {
2394 return -1;
2395 }
2396 } finally {
2397 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 }
2400
2401 /**
2402 * Returns the CDMA ERI icon mode,
2403 * 0 - ON
2404 * 1 - FLASHING
2405 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002406 @Override
2407 public int getCdmaEriIconMode(String callingPackage) {
2408 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002409 }
2410
Sanket Padawe356d7632015-06-22 14:03:32 -07002411 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002412 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002414 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002415 return -1;
2416 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002417
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 final Phone phone = getPhone(subId);
2421 if (phone != null) {
2422 return phone.getCdmaEriIconMode();
2423 } else {
2424 return -1;
2425 }
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
2431 /**
2432 * Returns the CDMA ERI text,
2433 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002434 @Override
2435 public String getCdmaEriText(String callingPackage) {
2436 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002437 }
2438
Sanket Padawe356d7632015-06-22 14:03:32 -07002439 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002440 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002442 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002443 return null;
2444 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002445
2446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 final Phone phone = getPhone(subId);
2449 if (phone != null) {
2450 return phone.getCdmaEriText();
2451 } else {
2452 return null;
2453 }
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
2459 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002460 * Returns the CDMA MDN.
2461 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002463 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2465 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002466
2467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002470 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002471 return phone.getLine1Number();
2472 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002473 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002474 return null;
2475 }
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002478 }
2479 }
2480
2481 /**
2482 * Returns the CDMA MIN.
2483 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002485 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2487 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = getPhone(subId);
2492 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2493 return phone.getCdmaMin();
2494 } else {
2495 return null;
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002499 }
2500 }
2501
Hall Liud892bec2018-11-30 14:51:45 -08002502 @Override
2503 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2504 INumberVerificationCallback callback, String callingPackage) {
2505 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2506 != PERMISSION_GRANTED) {
2507 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2508 }
2509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2510
2511 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2512 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2513 throw new SecurityException("Calling package must be configured in the device config");
2514 }
2515
2516 if (range == null) {
2517 throw new NullPointerException("Range must be non-null");
2518 }
2519
2520 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002521 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002522
2523 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2524 }
2525
Junda Liuca05d5d2014-08-14 22:36:34 -07002526 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 * Returns true if CDMA provisioning needs to run.
2528 */
2529 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002530 final long identity = Binder.clearCallingIdentity();
2531 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002532 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002533 } finally {
2534 Binder.restoreCallingIdentity(identity);
2535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536 }
2537
2538 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002539 * Sets the voice mail number of a given subId.
2540 */
2541 @Override
2542 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002543 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2548 new Pair<String, String>(alphaTag, number), new Integer(subId));
2549 return success;
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
2552 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002553 }
2554
Ta-wei Yen87c49842016-05-13 21:19:52 -07002555 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002556 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2557 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002558 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002559 if (!TextUtils.equals(callingPackage, systemDialer)) {
2560 throw new SecurityException("caller must be system dialer");
2561 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2566 if (phoneAccountHandle == null) {
2567 return null;
2568 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002569 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002570 } finally {
2571 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002572 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002573 }
2574
2575 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002576 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002579 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002580 return null;
2581 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002582
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002583 final long identity = Binder.clearCallingIdentity();
2584 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002585 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002586 } finally {
2587 Binder.restoreCallingIdentity(identity);
2588 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002589 }
2590
2591 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002592 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2593 VisualVoicemailSmsFilterSettings settings) {
2594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002599 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002600 } finally {
2601 Binder.restoreCallingIdentity(identity);
2602 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002603 }
2604
2605 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002606 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002608
2609 final long identity = Binder.clearCallingIdentity();
2610 try {
2611 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002612 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002613 } finally {
2614 Binder.restoreCallingIdentity(identity);
2615 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002616 }
2617
2618 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002619 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2620 String callingPackage, int subId) {
2621 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002626 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002627 } finally {
2628 Binder.restoreCallingIdentity(identity);
2629 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002630 }
2631
2632 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002633 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002634 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002639 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002640 } finally {
2641 Binder.restoreCallingIdentity(identity);
2642 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002643 }
2644
2645 @Override
2646 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2647 String number, int port, String text, PendingIntent sentIntent) {
2648 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002649 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002650 enforceSendSmsPermission();
2651 // Make the calls as the phone process.
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2655 if (port == 0) {
2656 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2657 sentIntent, null, false);
2658 } else {
2659 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2660 smsManager.sendDataMessageWithSelfPermissions(number, null,
2661 (short) port, data, sentIntent, null);
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002666 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002667 /**
fionaxu0152e512016-11-14 13:36:14 -08002668 * Sets the voice activation state of a given subId.
2669 */
2670 @Override
2671 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2673 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002674
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 final Phone phone = getPhone(subId);
2678 if (phone != null) {
2679 phone.setVoiceActivationState(activationState);
2680 } else {
2681 loge("setVoiceActivationState fails with invalid subId: " + subId);
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002685 }
2686 }
2687
2688 /**
2689 * Sets the data activation state of a given subId.
2690 */
2691 @Override
2692 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2694 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002695
2696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 final Phone phone = getPhone(subId);
2699 if (phone != null) {
2700 phone.setDataActivationState(activationState);
2701 } else {
2702 loge("setVoiceActivationState fails with invalid subId: " + subId);
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002706 }
2707 }
2708
2709 /**
2710 * Returns the voice activation state of a given subId.
2711 */
2712 @Override
2713 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002714 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002715
fionaxu0152e512016-11-14 13:36:14 -08002716 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 if (phone != null) {
2720 return phone.getVoiceActivationState();
2721 } else {
2722 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002726 }
2727 }
2728
2729 /**
2730 * Returns the data activation state of a given subId.
2731 */
2732 @Override
2733 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002734 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002735
fionaxu0152e512016-11-14 13:36:14 -08002736 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002737 final long identity = Binder.clearCallingIdentity();
2738 try {
2739 if (phone != null) {
2740 return phone.getDataActivationState();
2741 } else {
2742 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002746 }
2747 }
2748
2749 /**
Wink Saville36469e72014-06-11 15:17:00 -07002750 * Returns the unread count of voicemails for a subId
2751 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002752 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002753 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2755 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2756 return 0;
2757 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 final Phone phone = getPhone(subId);
2761 if (phone != null) {
2762 return phone.getVoiceMessageCount();
2763 } else {
2764 return 0;
2765 }
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
2771 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002772 * returns true, if the device is in a state where both voice and data
2773 * are supported simultaneously. This can change based on location or network condition.
2774 */
2775 @Override
2776 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 final Phone phone = getPhone(subId);
2780 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2781 } finally {
2782 Binder.restoreCallingIdentity(identity);
2783 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002784 }
2785
2786 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002787 * Send the dialer code if called from the current default dialer or the caller has
2788 * carrier privilege.
2789 * @param inputCode The dialer code to send
2790 */
2791 @Override
2792 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002793 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002795 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2796 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002797 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002798 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2799 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002800 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002804 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002805 } finally {
2806 Binder.restoreCallingIdentity(identity);
2807 }
fionaxu235cc5e2017-03-06 22:25:57 -08002808 }
2809
2810 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002811 * Returns the data network type.
2812 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 *
2814 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2815 */
2816 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002817 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 final Phone phone = getPhone(getDefaultSubscription());
2821 if (phone != null) {
2822 return phone.getServiceState().getDataNetworkType();
2823 } else {
2824 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2825 }
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002828 }
Wink Saville36469e72014-06-11 15:17:00 -07002829 }
2830
Pengquan Meng0c05b502018-09-06 09:59:22 -07002831 @Override
2832 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002833 if (!isActiveSubscription(subId)) {
2834 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2835 }
2836
Pengquan Meng0c05b502018-09-06 09:59:22 -07002837 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2838 }
2839
Brad Ebinger4c460712018-10-01 10:40:55 -07002840 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002841 public boolean isInEmergencySmsMode() {
2842 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 for (Phone phone : PhoneFactory.getPhones()) {
2846 if (phone.isInEmergencySmsMode()) {
2847 return true;
2848 }
2849 }
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
2852 }
2853 return false;
2854 }
2855
2856 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002857 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2858 throws RemoteException {
2859 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002860 final long token = Binder.clearCallingIdentity();
2861 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002863 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002864 .addRegistrationCallbackForSubscription(c, subId);
2865 } finally {
2866 Binder.restoreCallingIdentity(token);
2867 }
2868 }
2869
2870 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002871 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2872 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2875 }
2876 Binder.withCleanCallingIdentity(() -> {
2877 try {
2878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002879 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002880 .removeRegistrationCallbackForSubscription(c, subId);
2881 } catch (IllegalArgumentException e) {
2882 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2883 + "is inactive, ignoring unregister.");
2884 // If the subscription is no longer active, just return, since the callback
2885 // will already have been removed internally.
2886 }
2887 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002888 }
2889
2890 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002891 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2892 throws RemoteException {
2893 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2895 final long token = Binder.clearCallingIdentity();
2896 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002897 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002898 .addCapabilitiesCallbackForSubscription(c, subId);
2899 } finally {
2900 Binder.restoreCallingIdentity(token);
2901 }
2902 }
2903
2904 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002905 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2906 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002907
2908 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2909 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2910 }
2911 Binder.withCleanCallingIdentity(() -> {
2912 try {
2913 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002914 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002915 .removeCapabilitiesCallbackForSubscription(c, subId);
2916 } catch (IllegalArgumentException e) {
2917 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2918 + "is inactive, ignoring unregister.");
2919 // If the subscription is no longer active, just return, since the callback
2920 // will already have been removed internally.
2921 }
2922 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002923 }
2924
2925 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002926 public boolean isCapable(int subId, int capability, int regTech) {
2927 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002928 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2929 final long token = Binder.clearCallingIdentity();
2930 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002931 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002932 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2933 } catch (ImsException e) {
2934 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2935 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002936 } catch (IllegalArgumentException e) {
2937 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2938 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002939 } finally {
2940 Binder.restoreCallingIdentity(token);
2941 }
2942 }
2943
2944 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002945 public boolean isAvailable(int subId, int capability, int regTech) {
2946 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002947 final long token = Binder.clearCallingIdentity();
2948 try {
2949 Phone phone = getPhone(subId);
2950 if (phone == null) return false;
2951 return phone.isImsCapabilityAvailable(capability, regTech);
2952 } finally {
2953 Binder.restoreCallingIdentity(token);
2954 }
2955 }
2956
2957 @Override
2958 public boolean isAdvancedCallingSettingEnabled(int subId) {
2959 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2961 final long token = Binder.clearCallingIdentity();
2962 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002963 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002964 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2965 } finally {
2966 Binder.restoreCallingIdentity(token);
2967 }
2968 }
2969
2970 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002971 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002973 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002977 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002978 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002985 public boolean isVtSettingEnabled(int subId) {
2986 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002990 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002991 getSlotIndexOrException(subId)).isVtEnabledByUser();
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
2997 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002998 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003000 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003004 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 }
3009
3010 @Override
3011 public boolean isVoWiFiSettingEnabled(int subId) {
3012 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003016 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003017 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
3021 }
3022
3023 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003024 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003026 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003030 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07003031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
3034 }
3035
3036 @Override
3037 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3038 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003042 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003043 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
3047 }
3048
3049 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003050 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003052 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003056 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003057 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
3060 }
3061 }
3062
3063 @Override
3064 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3066 "setVoWiFiNonPersistent");
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003070 boolean isRoaming = TelephonyManager.from(
3071 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003072 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003073 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003074 } finally {
3075 Binder.restoreCallingIdentity(identity);
3076 }
3077 }
3078
3079 @Override
3080 public int getVoWiFiModeSetting(int subId) {
3081 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003085 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003086 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
3090 }
3091
3092 @Override
3093 public void setVoWiFiModeSetting(int subId, int mode) {
3094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3095 "setVoWiFiModeSetting");
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003099 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003100 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
3104 }
3105
3106 @Override
3107 public int getVoWiFiRoamingModeSetting(int subId) {
3108 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003112 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003113 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
3117 }
3118
3119 @Override
3120 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3122 "setVoWiFiRoamingModeSetting");
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003126 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003127 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
3131 }
3132
3133 @Override
3134 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3136 "setRttCapabilityEnabled");
3137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003140 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003141 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
3144 }
3145 }
3146
3147 @Override
3148 public boolean isTtyOverVolteEnabled(int subId) {
3149 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003153 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003154 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
3157 }
3158 }
3159
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003160 @Override
3161 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3162 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003166 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003167 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
3171 }
3172
3173 @Override
3174 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3175 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3176 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003177 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3178 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3179 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003180 try {
3181 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003182 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003183 .removeProvisioningCallbackForSubscription(callback, subId);
3184 } catch (IllegalArgumentException e) {
3185 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3186 + "is inactive, ignoring unregister.");
3187 // If the subscription is no longer active, just return, since the callback will already
3188 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
3192 }
3193
3194 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003195 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3196 boolean isProvisioned) {
3197 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3198 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3199 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3200 }
3201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3202 "setProvisioningStatusForCapability");
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3206 Phone phone = getPhone(subId);
3207 if (phone == null) {
3208 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3209 + subId);
3210 return;
3211 }
3212 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3213 return;
3214 }
3215
3216 // this capability requires provisioning, route to the correct API.
3217 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3218 switch (capability) {
3219 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3220 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3221 ims.setVolteProvisioned(isProvisioned);
3222 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3223 ims.setWfcProvisioned(isProvisioned);
3224 }
3225 break;
3226 }
3227 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3228 // There is currently no difference in VT provisioning type.
3229 ims.setVtProvisioned(isProvisioned);
3230 break;
3231 }
3232 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3233 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3234 // change the capability of the feature instead if needed.
3235 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3236 == isProvisioned) {
3237 // No change in provisioning.
3238 return;
3239 }
3240 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3241 try {
3242 ims.changeMmTelCapability(capability, tech, isProvisioned);
3243 } catch (ImsException e) {
3244 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3245 + ", Exception" + e.getMessage());
3246 }
3247 break;
3248 }
3249 default: {
3250 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3251 + capability + "', which does not require provisioning.");
3252 }
3253 }
3254
3255 } finally {
3256 Binder.restoreCallingIdentity(identity);
3257 }
3258 }
3259
3260 @Override
3261 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3262 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3263 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3264 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3265 }
3266 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3267 final long identity = Binder.clearCallingIdentity();
3268 try {
3269 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3270 Phone phone = getPhone(subId);
3271 if (phone == null) {
3272 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3273 + subId);
3274 // We will fail with "true" as the provisioning status because this is the default
3275 // if we do not require provisioning.
3276 return true;
3277 }
3278
3279 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3280 return true;
3281 }
3282
3283 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3284 switch (capability) {
3285 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3286 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3287 return ims.isVolteProvisionedOnDevice();
3288 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3289 return ims.isWfcProvisionedOnDevice();
3290 }
3291 // This should never happen, since we are checking tech above to make sure it
3292 // is either LTE or IWLAN.
3293 throw new IllegalArgumentException("Invalid radio technology for voice "
3294 + "capability.");
3295 }
3296 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3297 // There is currently no difference in VT provisioning type.
3298 return ims.isVtProvisionedOnDevice();
3299 }
3300 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3301 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3302 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3303 }
3304 default: {
3305 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3306 + capability + "', which does not require provisioning.");
3307 }
3308 }
3309
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
3312 }
3313 }
3314
3315 @Override
3316 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3317 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3318 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3319 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3320 }
3321 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3322 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3323 return (provisionedBits & capability) > 0;
3324 }
3325
3326 @Override
3327 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3328 boolean isProvisioned) {
3329 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3330 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3331 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3332 }
3333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3334 "setProvisioningStatusForCapability");
3335 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3336 // If the current provisioning status for capability already matches isProvisioned,
3337 // do nothing.
3338 if (((provisionedBits & capability) > 0) == isProvisioned) {
3339 return;
3340 }
3341 if (isProvisioned) {
3342 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3343 } else {
3344 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3345 }
3346 }
3347
3348 /**
3349 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3350 * technology. The bitfield should mirror the bitfield defined by
3351 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3352 */
3353 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3354 String key = getMmTelProvisioningKey(subId, tech);
3355 // Default is no capabilities are provisioned.
3356 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3357 }
3358
3359 /**
3360 * Sets the MmTel capability provisioning bitfield (defined by
3361 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3362 * technology specified.
3363 *
3364 * Note: This is a synchronous command and should not be called on UI thread.
3365 */
3366 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3367 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3368 String key = getMmTelProvisioningKey(subId, tech);
3369 editor.putInt(key, newField);
3370 editor.commit();
3371 }
3372
3373 private static String getMmTelProvisioningKey(int subId, int tech) {
3374 // resulting key is provision_ims_mmtel_{subId}_{tech}
3375 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3376 }
3377
3378 /**
3379 * Query CarrierConfig to see if the specified capability requires provisioning for the
3380 * carrier associated with the subscription id.
3381 */
3382 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3383 int capability) {
3384 CarrierConfigManager configManager = new CarrierConfigManager(context);
3385 PersistableBundle c = configManager.getConfigForSubId(subId);
3386 boolean requireUtProvisioning = c.getBoolean(
3387 // By default, this config is true (even if there is no SIM). We also check to make
3388 // sure the subscription needs provisioning here, so we do not need to check for
3389 // the no-SIM case, where we would normally shortcut this to false.
3390 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3391 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3392 false);
3393 boolean requireVoiceVtProvisioning = c.getBoolean(
3394 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3395
3396 // First check to make sure that the capability requires provisioning.
3397 switch (capability) {
3398 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3399 // intentional fallthrough
3400 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3401 if (requireVoiceVtProvisioning) {
3402 // Voice and Video requires provisioning
3403 return true;
3404 }
3405 break;
3406 }
3407 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3408 if (requireUtProvisioning) {
3409 // UT requires provisioning
3410 return true;
3411 }
3412 break;
3413 }
3414 }
3415 return false;
3416 }
3417
3418 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003419 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003420 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3421 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3422 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003423 enforceReadPrivilegedPermission("getImsProvisioningInt");
3424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003427 int slotId = getSlotIndex(subId);
3428 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3429 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3430 + subId + "' for key:" + key);
3431 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3432 }
3433 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003434 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003435 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3436 + subId + "' for key:" + key);
3437 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003438 } finally {
3439 Binder.restoreCallingIdentity(identity);
3440 }
3441 }
3442
3443 @Override
3444 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003445 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3446 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3447 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003448 enforceReadPrivilegedPermission("getImsProvisioningString");
3449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003452 int slotId = getSlotIndex(subId);
3453 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3454 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3455 + subId + "' for key:" + key);
3456 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3457 }
3458 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003459 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003460 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3461 + subId + "' for key:" + key);
3462 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003463 } finally {
3464 Binder.restoreCallingIdentity(identity);
3465 }
3466 }
3467
3468 @Override
3469 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003470 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3471 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3472 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3474 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003475 final long identity = Binder.clearCallingIdentity();
3476 try {
3477 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003478 int slotId = getSlotIndex(subId);
3479 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3480 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3481 + subId + "' for key:" + key);
3482 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3483 }
3484 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003485 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003486 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3487 + "' for key:" + key);
3488 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003489 } finally {
3490 Binder.restoreCallingIdentity(identity);
3491 }
3492 }
3493
3494 @Override
3495 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003496 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3497 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3498 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3500 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003501 final long identity = Binder.clearCallingIdentity();
3502 try {
3503 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003504 int slotId = getSlotIndex(subId);
3505 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3506 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3507 + subId + "' for key:" + key);
3508 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3509 }
3510 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003511 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003512 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3513 + "' for key:" + key);
3514 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003515 } finally {
3516 Binder.restoreCallingIdentity(identity);
3517 }
3518 }
3519
Brad Ebinger4c460712018-10-01 10:40:55 -07003520 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3521 int slotId = SubscriptionManager.getSlotIndex(subId);
3522 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003523 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003524 }
3525 return slotId;
3526 }
3527
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003528 private int getSlotIndex(int subId) {
3529 int slotId = SubscriptionManager.getSlotIndex(subId);
3530 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3531 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3532 }
3533 return slotId;
3534 }
3535
Wink Saville36469e72014-06-11 15:17:00 -07003536 /**
3537 * Returns the network type for a subId
3538 */
3539 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003540 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003542 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003543 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3544 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003545
Malcolm Chend965c8b2018-02-28 15:00:40 -08003546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 final Phone phone = getPhone(subId);
3549 if (phone != null) {
3550 return phone.getServiceState().getDataNetworkType();
3551 } else {
3552 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3553 }
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003557 }
3558
3559 /**
3560 * Returns the data network type
3561 */
3562 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 public int getDataNetworkType(String callingPackage) {
3564 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003565 }
3566
3567 /**
3568 * Returns the data network type for a subId
3569 */
3570 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003571 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003573 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003574 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3575 }
3576
Malcolm Chend965c8b2018-02-28 15:00:40 -08003577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 final Phone phone = getPhone(subId);
3580 if (phone != null) {
3581 return phone.getServiceState().getDataNetworkType();
3582 } else {
3583 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3584 }
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003588 }
3589
3590 /**
Wink Saville36469e72014-06-11 15:17:00 -07003591 * Returns the Voice network type for a subId
3592 */
3593 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003594 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003596 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003597 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3598 }
3599
Malcolm Chend965c8b2018-02-28 15:00:40 -08003600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 final Phone phone = getPhone(subId);
3603 if (phone != null) {
3604 return phone.getServiceState().getVoiceNetworkType();
3605 } else {
3606 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3607 }
3608 } finally {
3609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003611 }
3612
3613 /**
3614 * @return true if a ICC card is present
3615 */
3616 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003617 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003618 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3619 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003620 }
3621
3622 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003623 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003624 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003625 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003626 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 final Phone phone = PhoneFactory.getPhone(slotIndex);
3630 if (phone != null) {
3631 return phone.getIccCard().hasIccCard();
3632 } else {
3633 return false;
3634 }
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003638 }
3639
3640 /**
3641 * Return if the current radio is LTE on CDMA. This
3642 * is a tri-state return value as for a period of time
3643 * the mode may be unknown.
3644 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003645 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003646 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003647 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003649 @Override
3650 public int getLteOnCdmaMode(String callingPackage) {
3651 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003652 }
3653
Sanket Padawe356d7632015-06-22 14:03:32 -07003654 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003655 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003657 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003658 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3659 }
3660
Malcolm Chend965c8b2018-02-28 15:00:40 -08003661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 final Phone phone = getPhone(subId);
3664 if (phone == null) {
3665 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3666 } else {
3667 return phone.getLteOnCdmaMode();
3668 }
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003671 }
Wink Saville36469e72014-06-11 15:17:00 -07003672 }
3673
Wink Saville36469e72014-06-11 15:17:00 -07003674 /**
3675 * {@hide}
3676 * Returns Default subId, 0 in the case of single standby.
3677 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003678 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003679 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003680 }
3681
Shishir Agrawala9f32182016-04-12 12:00:16 -07003682 private int getSlotForDefaultSubscription() {
3683 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3684 }
3685
Wink Savilleb564aae2014-10-23 10:18:09 -07003686 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003687 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003688 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003689
Pengquan Meng466e2482018-09-21 15:54:48 -07003690 private boolean isActiveSubscription(int subId) {
3691 return mSubscriptionController.isActiveSubId(subId);
3692 }
3693
Ihab Awadf2177b72013-11-25 13:33:23 -08003694 /**
3695 * @see android.telephony.TelephonyManager.WifiCallingChoices
3696 */
3697 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003698 final long identity = Binder.clearCallingIdentity();
3699 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003700 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003701 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3702 getWhenToMakeWifiCallsDefaultPreference());
3703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003706 }
3707
3708 /**
3709 * @see android.telephony.TelephonyManager.WifiCallingChoices
3710 */
3711 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003715 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003716 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3717 } finally {
3718 Binder.restoreCallingIdentity(identity);
3719 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003720 }
3721
Sailesh Nepald1e68152013-12-12 19:08:02 -08003722 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003723 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003724 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003725 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003726
Jordan Liu73b078d2019-02-28 12:03:40 -08003727 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3728 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3729 if (phoneId == -1) {
3730 throw new IllegalArgumentException("Given slot index: " + slotIndex
3731 + " does not correspond to an active phone");
3732 }
3733 return PhoneFactory.getPhone(phoneId);
3734 }
3735
Shishir Agrawal566b7612013-10-28 14:41:00 -07003736 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003737 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3738 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3740 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003741 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003742 if (DBG) {
3743 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3744 }
3745 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3746 p2);
3747 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003748
Jordan Liu73b078d2019-02-28 12:03:40 -08003749
3750 @Override
3751 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3752 int slotIndex, String callingPackage, String aid, int p2) {
3753 enforceModifyPermission();
3754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3755 if (DBG) {
3756 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3757 }
3758 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3759 callingPackage, aid, p2);
3760 }
3761
3762 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3763 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003764 final long identity = Binder.clearCallingIdentity();
3765 try {
3766 if (TextUtils.equals(ISDR_AID, aid)) {
3767 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003768 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3769 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003770 if (bestComponent == null
3771 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3772 loge("The calling package is not allowed to access ISD-R.");
3773 throw new SecurityException(
3774 "The calling package is not allowed to access ISD-R.");
3775 }
Derek Tan740e1672017-06-27 14:56:27 -07003776 }
Derek Tan740e1672017-06-27 14:56:27 -07003777
Malcolm Chend965c8b2018-02-28 15:00:40 -08003778 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003779 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3780 null /* workSource */);
3781 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003782 return response;
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
3785 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003786 }
3787
3788 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003789 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3791 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003792 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3793 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3794 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003795
Jordan Liu73b078d2019-02-28 12:03:40 -08003796 @Override
3797 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3798 enforceModifyPermission();
3799 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3800 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3801 channel);
3802 }
3803
3804 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003805 final long identity = Binder.clearCallingIdentity();
3806 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003807 if (channel < 0) {
3808 return false;
3809 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003810 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3811 null /* workSource */);
3812 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003813 return success;
3814 } finally {
3815 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003816 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003817 }
3818
3819 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003820 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003821 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3823 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003824 if (DBG) {
3825 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3826 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3827 + p3 + " data=" + data);
3828 }
3829 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3830 command, p1, p2, p3, data);
3831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003832
Jordan Liu73b078d2019-02-28 12:03:40 -08003833 @Override
3834 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3835 int command, int p1, int p2, int p3, String data) {
3836 enforceModifyPermission();
3837 if (DBG) {
3838 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3839 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3840 + p3 + " data=" + data);
3841 }
3842 return iccTransmitApduLogicalChannelWithPermission(
3843 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3844 data);
3845 }
3846
3847 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3848 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003849 final long identity = Binder.clearCallingIdentity();
3850 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003851 if (channel < 0) {
3852 return "";
3853 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003854
Malcolm Chend965c8b2018-02-28 15:00:40 -08003855 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003856 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3857 null /* workSource */);
3858 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003859
Malcolm Chend965c8b2018-02-28 15:00:40 -08003860 // Append the returned status code to the end of the response payload.
3861 String s = Integer.toHexString(
3862 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3863 if (response.payload != null) {
3864 s = IccUtils.bytesToHexString(response.payload) + s;
3865 }
3866 return s;
3867 } finally {
3868 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003870 }
Jake Hambye994d462014-02-03 13:10:13 -08003871
Evan Charltonc66da362014-05-16 14:06:40 -07003872 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003873 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3874 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3876 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003877 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003878 if (DBG) {
3879 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3880 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3881 }
3882 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3883 cla, command, p1, p2, p3, data);
3884 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003885
Jordan Liu73b078d2019-02-28 12:03:40 -08003886 @Override
3887 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3888 int command, int p1, int p2, int p3, String data) {
3889 enforceModifyPermission();
3890 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3891 if (DBG) {
3892 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3893 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3894 + " data=" + data);
3895 }
3896
3897 return iccTransmitApduBasicChannelWithPermission(
3898 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3899 p2, p3, data);
3900 }
3901
3902 // open APDU basic channel assuming the caller has sufficient permissions
3903 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3904 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3908 && TextUtils.equals(ISDR_AID, data)) {
3909 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003910 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3911 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003912 if (bestComponent == null
3913 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3914 loge("The calling package is not allowed to select ISD-R.");
3915 throw new SecurityException(
3916 "The calling package is not allowed to select ISD-R.");
3917 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003918 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003919
Malcolm Chend965c8b2018-02-28 15:00:40 -08003920 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003921 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3922 null /* workSource */);
3923 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003924
Malcolm Chend965c8b2018-02-28 15:00:40 -08003925 // Append the returned status code to the end of the response payload.
3926 String s = Integer.toHexString(
3927 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3928 if (response.payload != null) {
3929 s = IccUtils.bytesToHexString(response.payload) + s;
3930 }
3931 return s;
3932 } finally {
3933 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003934 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003935 }
3936
3937 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003938 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003939 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3941 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003942
Malcolm Chend965c8b2018-02-28 15:00:40 -08003943 final long identity = Binder.clearCallingIdentity();
3944 try {
3945 if (DBG) {
3946 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3947 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3948 }
3949
3950 IccIoResult response =
3951 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3952 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3953 subId);
3954
3955 if (DBG) {
3956 log("Exchange SIM_IO [R]" + response);
3957 }
3958
3959 byte[] result = null;
3960 int length = 2;
3961 if (response.payload != null) {
3962 length = 2 + response.payload.length;
3963 result = new byte[length];
3964 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3965 } else {
3966 result = new byte[length];
3967 }
3968
3969 result[length - 1] = (byte) response.sw2;
3970 result[length - 2] = (byte) response.sw1;
3971 return result;
3972 } finally {
3973 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003974 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003975 }
3976
Nathan Haroldb3014052017-01-25 15:57:32 -08003977 /**
3978 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3979 * on a particular subscription
3980 */
sqianb6e41952018-03-12 14:54:01 -07003981 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3983 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3984 return null;
3985 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003986
3987 final long identity = Binder.clearCallingIdentity();
3988 try {
3989 if (appType != TelephonyManager.APPTYPE_USIM
3990 && appType != TelephonyManager.APPTYPE_SIM) {
3991 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3992 return null;
3993 }
3994 Object response = sendRequest(
3995 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3996 if (response instanceof String[]) {
3997 return (String[]) response;
3998 }
3999 // Response is an Exception of some kind,
4000 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004001 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004002 } finally {
4003 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004004 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004005 }
4006
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004007 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004008 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4010 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004011
Malcolm Chend965c8b2018-02-28 15:00:40 -08004012 final long identity = Binder.clearCallingIdentity();
4013 try {
4014 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4015 if (response.payload == null) {
4016 return "";
4017 }
Evan Charltonc66da362014-05-16 14:06:40 -07004018
Malcolm Chend965c8b2018-02-28 15:00:40 -08004019 // Append the returned status code to the end of the response payload.
4020 String s = Integer.toHexString(
4021 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4022 s = IccUtils.bytesToHexString(response.payload) + s;
4023 return s;
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
4026 }
Evan Charltonc66da362014-05-16 14:06:40 -07004027 }
4028
Jake Hambye994d462014-02-03 13:10:13 -08004029 /**
4030 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4031 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4032 *
4033 * @param itemID the ID of the item to read
4034 * @return the NV item as a String, or null on error.
4035 */
4036 @Override
4037 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4040 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004041
4042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004045 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004046 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4047 return value;
4048 } finally {
4049 Binder.restoreCallingIdentity(identity);
4050 }
Jake Hambye994d462014-02-03 13:10:13 -08004051 }
4052
4053 /**
4054 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4055 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4056 *
4057 * @param itemID the ID of the item to read
4058 * @param itemValue the value to write, as a String
4059 * @return true on success; false on any failure
4060 */
4061 @Override
4062 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004063 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4065 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004066
4067 final long identity = Binder.clearCallingIdentity();
4068 try {
4069 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4070 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004071 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004072 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4073 return success;
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Jake Hambye994d462014-02-03 13:10:13 -08004077 }
4078
4079 /**
4080 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4081 * Used for device configuration by some CDMA operators.
4082 *
4083 * @param preferredRoamingList byte array containing the new PRL
4084 * @return true on success; false on any failure
4085 */
4086 @Override
4087 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4089 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004090
4091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4094 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4095 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4096 return success;
4097 } finally {
4098 Binder.restoreCallingIdentity(identity);
4099 }
Jake Hambye994d462014-02-03 13:10:13 -08004100 }
4101
4102 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004103 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004104 * Used for device configuration by some CDMA operators.
4105 *
chen xu1cc0abe2018-10-26 17:39:23 -07004106 * @param slotIndex - device slot.
4107 *
Jake Hambye994d462014-02-03 13:10:13 -08004108 * @return true on success; false on any failure
4109 */
4110 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004111 public boolean resetModemConfig(int slotIndex) {
4112 Phone phone = PhoneFactory.getPhone(slotIndex);
4113 if (phone != null) {
4114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4115 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004116
chen xu1cc0abe2018-10-26 17:39:23 -07004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4120 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4121 return success;
4122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004125 }
chen xu1cc0abe2018-10-26 17:39:23 -07004126 return false;
4127 }
4128
4129 /**
4130 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4131 *
4132 * @param slotIndex - device slot.
4133 *
4134 * @return true on success; false on any failure
4135 */
4136 @Override
4137 public boolean rebootModem(int slotIndex) {
4138 Phone phone = PhoneFactory.getPhone(slotIndex);
4139 if (phone != null) {
4140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4141 mApp, phone.getSubId(), "rebootModem");
4142
4143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4146 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4147 return success;
4148 } finally {
4149 Binder.restoreCallingIdentity(identity);
4150 }
4151 }
4152 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004153 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004154
Svet Ganovb320e182015-04-16 12:30:10 -07004155 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004156 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004158 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004159 return new String[0];
4160 }
4161
Malcolm Chend965c8b2018-02-28 15:00:40 -08004162 final long identity = Binder.clearCallingIdentity();
4163 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004164 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
Wink Saville36469e72014-06-11 15:17:00 -07004168 }
4169
Brad Ebinger51f743a2017-01-23 13:50:20 -08004170 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004171 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4172 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004173 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004174 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004175 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004176
4177 final long identity = Binder.clearCallingIdentity();
4178 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004179 ImsResolver resolver = PhoneFactory.getImsResolver();
4180 if (resolver == null) {
4181 // may happen if the device does not support IMS.
4182 return;
4183 }
4184 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004188 }
4189
4190 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004191 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4192 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004193 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004194 public void disableIms(int slotId) {
4195 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004196
4197 final long identity = Binder.clearCallingIdentity();
4198 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004199 ImsResolver resolver = PhoneFactory.getImsResolver();
4200 if (resolver == null) {
4201 // may happen if the device does not support IMS.
4202 return;
4203 }
4204 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004208 }
4209
4210 /**
4211 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4212 * feature or {@link null} if the service is not available. If the feature is available, the
4213 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4214 */
4215 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004216 IImsServiceFeatureCallback callback) {
4217 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004218
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004221 ImsResolver resolver = PhoneFactory.getImsResolver();
4222 if (resolver == null) {
4223 // may happen if the device does not support IMS.
4224 return null;
4225 }
4226 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004230 }
4231
4232 /**
4233 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4234 * feature during emergency calling or {@link null} if the service is not available. If the
4235 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4236 * listener for feature updates.
4237 */
4238 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4239 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004240
4241 final long identity = Binder.clearCallingIdentity();
4242 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004243 ImsResolver resolver = PhoneFactory.getImsResolver();
4244 if (resolver == null) {
4245 // may happen if the device does not support IMS.
4246 return null;
4247 }
4248 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
4251 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004252 }
4253
Brad Ebinger5f64b052017-12-14 14:26:15 -08004254 /**
4255 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004256 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004257 */
4258 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4259 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004260
4261 final long identity = Binder.clearCallingIdentity();
4262 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004263 ImsResolver resolver = PhoneFactory.getImsResolver();
4264 if (resolver == null) {
4265 // may happen if the device does not support IMS.
4266 return null;
4267 }
4268 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004272 }
4273
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004274 /**
4275 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004276 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004277 */
4278 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4279 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004280
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004283 ImsResolver resolver = PhoneFactory.getImsResolver();
4284 if (resolver == null) {
4285 // may happen if the device does not support IMS.
4286 return null;
4287 }
4288 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004289 } finally {
4290 Binder.restoreCallingIdentity(identity);
4291 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004292 }
4293
Brad Ebinger884c07b2018-02-15 16:17:40 -08004294 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004295 * Sets the ImsService Package Name that Telephony will bind to.
4296 *
4297 * @param slotId the slot ID that the ImsService should bind for.
4298 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4299 * ImsService is the device default ImsService.
4300 * @param packageName The package name of the application that contains the ImsService to bind
4301 * to.
4302 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4303 * @hide
4304 */
4305 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004306 int[] subIds = SubscriptionManager.getSubId(slotId);
4307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4308 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4309 "setImsService");
4310
Malcolm Chend965c8b2018-02-28 15:00:40 -08004311 final long identity = Binder.clearCallingIdentity();
4312 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004313 ImsResolver resolver = PhoneFactory.getImsResolver();
4314 if (resolver == null) {
4315 // may happen if the device does not support IMS.
4316 return false;
4317 }
4318 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4319 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004323 }
4324
4325 /**
4326 * Return the ImsService configuration.
4327 *
4328 * @param slotId The slot that the ImsService is associated with.
4329 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4330 * the device default.
4331 * @return the package name of the ImsService configuration.
4332 */
4333 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004334 int[] subIds = SubscriptionManager.getSubId(slotId);
4335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4336 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4337 "getImsService");
4338
Malcolm Chend965c8b2018-02-28 15:00:40 -08004339 final long identity = Binder.clearCallingIdentity();
4340 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004341 ImsResolver resolver = PhoneFactory.getImsResolver();
4342 if (resolver == null) {
4343 // may happen if the device does not support IMS.
4344 return "";
4345 }
4346 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004347 } finally {
4348 Binder.restoreCallingIdentity(identity);
4349 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004350 }
4351
Wink Saville36469e72014-06-11 15:17:00 -07004352 public void setImsRegistrationState(boolean registered) {
4353 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004354
4355 final long identity = Binder.clearCallingIdentity();
4356 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004357 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Wink Saville36469e72014-06-11 15:17:00 -07004361 }
4362
4363 /**
Stuart Scott54788802015-03-30 13:18:01 -07004364 * Set the network selection mode to automatic.
4365 *
4366 */
4367 @Override
4368 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4370 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004371
Pengquan Meng466e2482018-09-21 15:54:48 -07004372 if (!isActiveSubscription(subId)) {
4373 return;
4374 }
4375
Malcolm Chend965c8b2018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4379 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
Stuart Scott54788802015-03-30 13:18:01 -07004383 }
4384
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004385 /**
4386 * Ask the radio to connect to the input network and change selection mode to manual.
4387 *
4388 * @param subId the id of the subscription.
4389 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4390 * the operator to attach to.
4391 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4392 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4393 * normal network selection next time.
4394 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004395 */
4396 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004397 public boolean setNetworkSelectionModeManual(
4398 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4400 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004401
4402 if (!isActiveSubscription(subId)) {
4403 return false;
4404 }
4405
Malcolm Chend965c8b2018-02-28 15:00:40 -08004406 final long identity = Binder.clearCallingIdentity();
4407 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004408 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004409 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004410 if (DBG) {
4411 log("setNetworkSelectionModeManual: subId: " + subId
4412 + " operator: " + operatorInfo);
4413 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004414 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004418 }
4419
4420 /**
4421 * Scans for available networks.
4422 */
4423 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004424 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4426 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004427 LocationAccessPolicy.LocationPermissionResult locationResult =
4428 LocationAccessPolicy.checkLocationPermission(mApp,
4429 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4430 .setCallingPackage(callingPackage)
4431 .setCallingPid(Binder.getCallingPid())
4432 .setCallingUid(Binder.getCallingUid())
4433 .setMethod("getCellNetworkScanResults")
4434 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4435 .build());
4436 switch (locationResult) {
4437 case DENIED_HARD:
4438 throw new SecurityException("Not allowed to access scan results -- location");
4439 case DENIED_SOFT:
4440 return null;
4441 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004442
Pengquan Meng0c05b502018-09-06 09:59:22 -07004443 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004444 try {
4445 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004446 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004447 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004451 }
4452
4453 /**
yinxub1bed742017-04-17 11:45:04 -07004454 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004455 *
yinxub1bed742017-04-17 11:45:04 -07004456 * @param subId id of the subscription
4457 * @param request contains the radio access networks with bands/channels to scan
4458 * @param messenger callback messenger for scan results or errors
4459 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004460 * @return the id of the requested scan which can be used to stop the scan.
4461 */
4462 @Override
4463 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004464 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4466 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004467 LocationAccessPolicy.LocationPermissionResult locationResult =
4468 LocationAccessPolicy.checkLocationPermission(mApp,
4469 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4470 .setCallingPackage(callingPackage)
4471 .setCallingPid(Binder.getCallingPid())
4472 .setCallingUid(Binder.getCallingUid())
4473 .setMethod("requestNetworkScan")
4474 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4475 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004476 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4477 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4478 if (e != null) {
4479 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4480 throw e;
4481 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004482 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004483 return TelephonyScanManager.INVALID_SCAN_ID;
4484 }
4485 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004486 }
Hall Liubac7d482019-04-25 14:02:26 -07004487 int callingUid = Binder.getCallingUid();
4488 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004489 final long identity = Binder.clearCallingIdentity();
4490 try {
4491 return mNetworkScanRequestTracker.startNetworkScan(
4492 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004493 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004494 } finally {
4495 Binder.restoreCallingIdentity(identity);
4496 }
yinxu504e1392017-04-12 16:03:22 -07004497 }
4498
Hall Liub2ac8ef2019-02-28 15:56:23 -08004499 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4500 NetworkScanRequest request) {
4501 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4502 != PERMISSION_GRANTED) {
4503 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4504 + " without location access.");
4505 }
4506
4507 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4508 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004509 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4510 return new SecurityException("Specific channels must not be"
4511 + " scanned without location access.");
4512 }
4513 }
4514 }
4515
Hall Liub2ac8ef2019-02-28 15:56:23 -08004516 return null;
4517 }
4518
yinxu504e1392017-04-12 16:03:22 -07004519 /**
4520 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004521 *
4522 * @param subId id of the subscription
4523 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004524 */
4525 @Override
4526 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4528 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004529
Hall Liubac7d482019-04-25 14:02:26 -07004530 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004531 final long identity = Binder.clearCallingIdentity();
4532 try {
Hall Liubac7d482019-04-25 14:02:26 -07004533 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004534 } finally {
4535 Binder.restoreCallingIdentity(identity);
4536 }
yinxu504e1392017-04-12 16:03:22 -07004537 }
4538
4539 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004540 * Get the calculated preferred network type.
4541 * Used for debugging incorrect network type.
4542 *
4543 * @return the preferred network type, defined in RILConstants.java.
4544 */
4545 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004546 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004547 final Phone defaultPhone = getDefaultPhone();
4548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4549 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004550 return RILConstants.PREFERRED_NETWORK_MODE;
4551 }
4552
Malcolm Chend965c8b2018-02-28 15:00:40 -08004553 final long identity = Binder.clearCallingIdentity();
4554 try {
4555 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004556 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
Junda Liu84d15a22014-07-02 11:21:04 -07004560 }
4561
4562 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004563 * Get the preferred network type.
4564 * Used for device configuration by some CDMA operators.
4565 *
4566 * @return the preferred network type, defined in RILConstants.java.
4567 */
4568 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004569 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004570 TelephonyPermissions
4571 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4572 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004573
4574 final long identity = Binder.clearCallingIdentity();
4575 try {
4576 if (DBG) log("getPreferredNetworkType");
4577 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4578 int networkType = (result != null ? result[0] : -1);
4579 if (DBG) log("getPreferredNetworkType: " + networkType);
4580 return networkType;
4581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004584 }
4585
4586 /**
4587 * Set the preferred network type.
4588 * Used for device configuration by some CDMA operators.
4589 *
4590 * @param networkType the preferred network type, defined in RILConstants.java.
4591 * @return true on success; false on any failure.
4592 */
4593 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004594 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4596 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004597
4598 final long identity = Binder.clearCallingIdentity();
4599 try {
4600 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4601 Boolean success = (Boolean) sendRequest(
4602 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4603 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4604 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004605 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004606 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4607 }
4608 return success;
4609 } finally {
4610 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004611 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004612 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004613
4614 /**
Miaoa84611c2019-03-15 09:21:10 +08004615 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004616 *
Miaoa84611c2019-03-15 09:21:10 +08004617 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004618 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004619 * @hide
4620 */
4621 @Override
Miaoa84611c2019-03-15 09:21:10 +08004622 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004623 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004624 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004625 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004626 try {
Miaoa84611c2019-03-15 09:21:10 +08004627 if (phone != null) {
4628 return phone.hasMatchedTetherApnSetting();
4629 } else {
4630 return false;
4631 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004632 } finally {
4633 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004634 }
Junda Liu475951f2014-11-07 16:45:03 -08004635 }
4636
4637 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004638 * Set mobile data enabled
4639 * Used by the user through settings etc to turn on/off mobile data
4640 *
4641 * @param enable {@code true} turn turn data on, else {@code false}
4642 */
4643 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004644 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4646 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004647
4648 final long identity = Binder.clearCallingIdentity();
4649 try {
4650 int phoneId = mSubscriptionController.getPhoneId(subId);
4651 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4652 Phone phone = PhoneFactory.getPhone(phoneId);
4653 if (phone != null) {
4654 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004655 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004656 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004657 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004658 }
4659 } finally {
4660 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004661 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004662 }
4663
4664 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004665 * Get the user enabled state of Mobile Data.
4666 *
4667 * TODO: remove and use isUserDataEnabled.
4668 * This can't be removed now because some vendor codes
4669 * calls through ITelephony directly while they should
4670 * use TelephonyManager.
4671 *
4672 * @return true on enabled
4673 */
4674 @Override
4675 public boolean getDataEnabled(int subId) {
4676 return isUserDataEnabled(subId);
4677 }
4678
4679 /**
4680 * Get whether mobile data is enabled per user setting.
4681 *
4682 * There are other factors deciding whether mobile data is actually enabled, but they are
4683 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004684 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004685 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004686 *
4687 * @return {@code true} if data is enabled else {@code false}
4688 */
4689 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004690 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004691 try {
4692 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4693 null);
4694 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4696 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004697 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004698
4699 final long identity = Binder.clearCallingIdentity();
4700 try {
4701 int phoneId = mSubscriptionController.getPhoneId(subId);
4702 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4703 Phone phone = PhoneFactory.getPhone(phoneId);
4704 if (phone != null) {
4705 boolean retVal = phone.isUserDataEnabled();
4706 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4707 return retVal;
4708 } else {
4709 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4710 return false;
4711 }
4712 } finally {
4713 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004714 }
4715 }
4716
4717 /**
4718 * Get whether mobile data is enabled.
4719 *
4720 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4721 * whether mobile data is actually enabled.
4722 *
4723 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4724 *
4725 * @return {@code true} if data is enabled else {@code false}
4726 */
4727 @Override
4728 public boolean isDataEnabled(int subId) {
4729 try {
4730 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4731 null);
4732 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4734 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004735 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004736
4737 final long identity = Binder.clearCallingIdentity();
4738 try {
4739 int phoneId = mSubscriptionController.getPhoneId(subId);
4740 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4741 Phone phone = PhoneFactory.getPhone(phoneId);
4742 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004743 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004744 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4745 return retVal;
4746 } else {
4747 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4748 return false;
4749 }
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004752 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004753 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004754
4755 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004756 public int getCarrierPrivilegeStatus(int subId) {
4757 final Phone phone = getPhone(subId);
4758 if (phone == null) {
4759 loge("getCarrierPrivilegeStatus: Invalid subId");
4760 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4761 }
4762 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004763 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004764 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004765 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4766 }
4767 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004768 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004769 }
Junda Liu29340342014-07-10 15:23:27 -07004770
4771 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004772 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4773 final Phone phone = getPhone(subId);
4774 if (phone == null) {
4775 loge("getCarrierPrivilegeStatus: Invalid subId");
4776 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4777 }
4778 UiccProfile profile =
4779 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4780 if (profile == null) {
4781 loge("getCarrierPrivilegeStatus: No UICC");
4782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4783 }
4784 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4785 }
4786
4787 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004788 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004789 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004790 if (TextUtils.isEmpty(pkgName))
4791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004792 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004793 if (card == null) {
4794 loge("checkCarrierPrivilegesForPackage: No UICC");
4795 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4796 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004797 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4798 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004799 }
4800
4801 @Override
4802 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004803 if (TextUtils.isEmpty(pkgName))
4804 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004805 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4806 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4807 UiccCard card = UiccController.getInstance().getUiccCard(i);
4808 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004809 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004810 continue;
4811 }
4812
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004813 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004814 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4815 break;
4816 }
4817 }
4818
4819 return result;
Junda Liu29340342014-07-10 15:23:27 -07004820 }
Derek Tan89e89d42014-07-08 17:00:10 -07004821
4822 @Override
Junda Liue64de782015-04-16 17:19:16 -07004823 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4824 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4825 loge("phoneId " + phoneId + " is not valid.");
4826 return null;
4827 }
4828 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004829 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004830 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004831 return null ;
4832 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004833 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004834 }
4835
Amith Yamasani6e118872016-02-19 12:53:51 -08004836 @Override
4837 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004838 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004839 List<String> privilegedPackages = new ArrayList<>();
4840 List<PackageInfo> packages = null;
4841 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4842 UiccCard card = UiccController.getInstance().getUiccCard(i);
4843 if (card == null) {
4844 // No UICC in that slot.
4845 continue;
4846 }
4847 if (card.hasCarrierPrivilegeRules()) {
4848 if (packages == null) {
4849 // Only check packages in user 0 for now
4850 packages = pm.getInstalledPackagesAsUser(
4851 PackageManager.MATCH_DISABLED_COMPONENTS
4852 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4853 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4854 }
4855 for (int p = packages.size() - 1; p >= 0; p--) {
4856 PackageInfo pkgInfo = packages.get(p);
4857 if (pkgInfo != null && pkgInfo.packageName != null
4858 && card.getCarrierPrivilegeStatus(pkgInfo)
4859 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4860 privilegedPackages.add(pkgInfo.packageName);
4861 }
4862 }
4863 }
4864 }
4865 return privilegedPackages;
4866 }
4867
Wink Savilleb564aae2014-10-23 10:18:09 -07004868 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004869 final Phone phone = getPhone(subId);
4870 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004871 if (card == null) {
4872 loge("getIccId: No UICC");
4873 return null;
4874 }
4875 String iccId = card.getIccId();
4876 if (TextUtils.isEmpty(iccId)) {
4877 loge("getIccId: ICC ID is null or empty.");
4878 return null;
4879 }
4880 return iccId;
4881 }
4882
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004883 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004884 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4885 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004886 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4887 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004888
Malcolm Chend965c8b2018-02-28 15:00:40 -08004889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 final String iccId = getIccId(subId);
4892 final Phone phone = getPhone(subId);
4893 if (phone == null) {
4894 return false;
4895 }
4896 final String subscriberId = phone.getSubscriberId();
4897
4898 if (DBG_MERGE) {
4899 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4900 + subscriberId + " to " + number);
4901 }
4902
4903 if (TextUtils.isEmpty(iccId)) {
4904 return false;
4905 }
4906
4907 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4908
4909 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4910 if (alphaTag == null) {
4911 editor.remove(alphaTagPrefKey);
4912 } else {
4913 editor.putString(alphaTagPrefKey, alphaTag);
4914 }
4915
4916 // Record both the line number and IMSI for this ICCID, since we need to
4917 // track all merged IMSIs based on line number
4918 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4919 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4920 if (number == null) {
4921 editor.remove(numberPrefKey);
4922 editor.remove(subscriberPrefKey);
4923 } else {
4924 editor.putString(numberPrefKey, number);
4925 editor.putString(subscriberPrefKey, subscriberId);
4926 }
4927
4928 editor.commit();
4929 return true;
4930 } finally {
4931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004932 }
Derek Tan7226c842014-07-02 17:42:23 -07004933 }
4934
4935 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004936 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004937 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004939 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004940 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004941 return null;
4942 }
Derek Tan97ebb422014-09-05 16:55:38 -07004943
Malcolm Chend965c8b2018-02-28 15:00:40 -08004944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 String iccId = getIccId(subId);
4947 if (iccId != null) {
4948 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4949 if (DBG_MERGE) {
4950 log("getLine1NumberForDisplay returning "
4951 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4952 }
4953 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004954 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004955 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4956 return null;
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004959 }
Derek Tan7226c842014-07-02 17:42:23 -07004960 }
4961
4962 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004963 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004965 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004966 return null;
4967 }
Derek Tan97ebb422014-09-05 16:55:38 -07004968
Malcolm Chend965c8b2018-02-28 15:00:40 -08004969 final long identity = Binder.clearCallingIdentity();
4970 try {
4971 String iccId = getIccId(subId);
4972 if (iccId != null) {
4973 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4974 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4975 }
4976 return null;
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004979 }
Derek Tan7226c842014-07-02 17:42:23 -07004980 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004981
4982 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004983 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004984 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4985 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004987 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4988 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004989 return null;
4990 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004991
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004992 final long identity = Binder.clearCallingIdentity();
4993 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004994 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004995 final TelephonyManager tele = TelephonyManager.from(context);
4996 final SubscriptionManager sub = SubscriptionManager.from(context);
4997
4998 // Figure out what subscribers are currently active
4999 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
5000 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5001 // the process, where TelephonyManager was instantiated.
5002 // Otherwise AppOps check will fail.
5003
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005004 final int[] subIds = sub.getActiveSubscriptionIdList();
5005 for (int subId : subIds) {
5006 activeSubscriberIds.add(tele.getSubscriberId(subId));
5007 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005008
5009 // First pass, find a number override for an active subscriber
5010 String mergeNumber = null;
5011 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5012 for (String key : prefs.keySet()) {
5013 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5014 final String subscriberId = (String) prefs.get(key);
5015 if (activeSubscriberIds.contains(subscriberId)) {
5016 final String iccId = key.substring(
5017 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5018 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5019 mergeNumber = (String) prefs.get(numberKey);
5020 if (DBG_MERGE) {
5021 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5022 + " for active subscriber " + subscriberId);
5023 }
5024 if (!TextUtils.isEmpty(mergeNumber)) {
5025 break;
5026 }
5027 }
5028 }
5029 }
5030
5031 // Shortcut when no active merged subscribers
5032 if (TextUtils.isEmpty(mergeNumber)) {
5033 return null;
5034 }
5035
5036 // Second pass, find all subscribers under that line override
5037 final ArraySet<String> result = new ArraySet<>();
5038 for (String key : prefs.keySet()) {
5039 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5040 final String number = (String) prefs.get(key);
5041 if (mergeNumber.equals(number)) {
5042 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5043 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5044 final String subscriberId = (String) prefs.get(subscriberKey);
5045 if (!TextUtils.isEmpty(subscriberId)) {
5046 result.add(subscriberId);
5047 }
5048 }
5049 }
5050 }
5051
5052 final String[] resultArray = result.toArray(new String[result.size()]);
5053 Arrays.sort(resultArray);
5054 if (DBG_MERGE) {
5055 Slog.d(LOG_TAG,
5056 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5057 }
5058 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005061 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005062 }
5063
5064 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005065 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005066 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5067 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005068
5069 final long identity = Binder.clearCallingIdentity();
5070 try {
5071 final Phone phone = getPhone(subId);
5072 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
5075 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005076 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005077
5078 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005079 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005080 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5081 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005082 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005083
5084 final long identity = Binder.clearCallingIdentity();
5085 try {
5086 final Phone phone = getPhone(subId);
5087 if (phone == null) {
5088 return false;
5089 }
5090 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5091 cdmaNonRoamingList);
5092 } finally {
5093 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005094 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005095 }
5096
5097 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005098 @Deprecated
5099 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5100 enforceModifyPermission();
5101
5102 int returnValue = 0;
5103 try {
vagdevie435a3e2018-08-15 16:01:53 -07005104 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005105 if(result.exception == null) {
5106 if (result.result != null) {
5107 byte[] responseData = (byte[])(result.result);
5108 if(responseData.length > oemResp.length) {
5109 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5110 responseData.length + "bytes. Buffer Size is " +
5111 oemResp.length + "bytes.");
5112 }
5113 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5114 returnValue = responseData.length;
5115 }
5116 } else {
5117 CommandException ex = (CommandException) result.exception;
5118 returnValue = ex.getCommandError().ordinal();
5119 if(returnValue > 0) returnValue *= -1;
5120 }
5121 } catch (RuntimeException e) {
5122 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5123 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5124 if(returnValue > 0) returnValue *= -1;
5125 }
5126
5127 return returnValue;
5128 }
5129
5130 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005131 public void setRadioCapability(RadioAccessFamily[] rafs) {
5132 try {
5133 ProxyController.getInstance().setRadioCapability(rafs);
5134 } catch (RuntimeException e) {
5135 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5136 }
5137 }
5138
5139 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005140 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005141 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005142 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005143 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005144 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005145 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005146 final long identity = Binder.clearCallingIdentity();
5147 try {
chen xufeeed752018-10-26 14:17:57 -07005148 TelephonyPermissions
5149 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5150 mApp, phone.getSubId(), "getRadioAccessFamily");
5151 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
chen xufeeed752018-10-26 14:17:57 -07005155 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005156 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005157
5158 @Override
5159 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005160 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005161 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005162
5163 final long identity = Binder.clearCallingIdentity();
5164 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005165 ImsManager.getInstance(defaultPhone.getContext(),
5166 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005167 } finally {
5168 Binder.restoreCallingIdentity(identity);
5169 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005170 }
5171
5172 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005173 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005174 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005176 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005177 return false;
5178 }
Svet Ganovb320e182015-04-16 12:30:10 -07005179
Malcolm Chend965c8b2018-02-28 15:00:40 -08005180 final long identity = Binder.clearCallingIdentity();
5181 try {
5182 // Check the user preference and the system-level IMS setting. Even if the user has
5183 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5184 // In the long run, we may instead need to check if there exists a connection service
5185 // which can support video calling.
5186 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005187 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005188 return imsManager.isVtEnabledByPlatform()
5189 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5190 && imsManager.isVtEnabledByUser();
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005194 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005195
Andrew Leea1239f22015-03-02 17:44:07 -08005196 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005197 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5199 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5200 return false;
5201 }
5202
5203 final long identity = Binder.clearCallingIdentity();
5204 try {
5205 CarrierConfigManager configManager =
5206 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005207 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005208 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
Andrew Leea1239f22015-03-02 17:44:07 -08005212 }
5213
5214 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005215 public boolean isWorldPhone(int subId, String callingPackage) {
5216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5217 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5218 return false;
5219 }
5220
5221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 CarrierConfigManager configManager =
5224 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005225 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005226 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
Andrew Leea1239f22015-03-02 17:44:07 -08005230 }
5231
Andrew Lee9431b832015-03-09 18:46:45 -07005232 @Override
5233 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005234 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005235 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005236 }
5237
5238 @Override
5239 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005240 final long identity = Binder.clearCallingIdentity();
5241 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005242 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005243 } finally {
5244 Binder.restoreCallingIdentity(identity);
5245 }
Andrew Lee9431b832015-03-09 18:46:45 -07005246 }
5247
Hall Liuf6668912018-10-31 17:05:23 -07005248 /**
5249 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5250 * support for the feature and device firmware support.
5251 *
5252 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5253 */
5254 @Override
5255 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005256 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005257 final Phone phone = getPhone(subscriptionId);
5258 if (phone == null) {
5259 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5260 return false;
5261 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005262 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005263 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005264 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5265 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005266 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005267 return isCarrierSupported && isDeviceSupported;
5268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
Hall Liu98187582018-01-22 19:15:32 -08005271 }
5272
Hall Liuf6668912018-10-31 17:05:23 -07005273 /**
5274 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5275 * both also support RTT.
5276 */
5277 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005278 final long identity = Binder.clearCallingIdentity();
5279 try {
Hall Liuf6668912018-10-31 17:05:23 -07005280 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005281 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005282 } finally {
5283 Binder.restoreCallingIdentity(identity);
5284 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005285 }
5286
Sanket Padawe7310cc72015-01-14 09:53:20 -08005287 /**
5288 * Returns the unique device ID of phone, for example, the IMEI for
5289 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5290 *
5291 * <p>Requires Permission:
5292 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5293 */
5294 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005295 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005296 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005297 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005298 return null;
5299 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005300 int subId = phone.getSubId();
5301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5302 mApp, subId, callingPackage, "getDeviceId")) {
5303 return null;
5304 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005305
5306 final long identity = Binder.clearCallingIdentity();
5307 try {
5308 return phone.getDeviceId();
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005312 }
5313
Ping Sunc67b7c22016-03-02 19:16:45 +08005314 /**
5315 * {@hide}
5316 * Returns the IMS Registration Status on a particular subid
5317 *
5318 * @param subId
5319 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005320 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005321 Phone phone = getPhone(subId);
5322 if (phone != null) {
5323 return phone.isImsRegistered();
5324 } else {
5325 return false;
5326 }
5327 }
5328
Santos Cordon7a1885b2015-02-03 11:15:19 -08005329 @Override
5330 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005331 final long identity = Binder.clearCallingIdentity();
5332 try {
5333 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
5336 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005337 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005338
Tyler Gunn327a9722019-04-03 15:28:53 -07005339 @Override
5340 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5341 final long identity = Binder.clearCallingIdentity();
5342 try {
5343 Phone phone = getPhone(subscriptionId);
5344 if (phone == null) {
5345 return null;
5346 }
5347 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
5350 }
5351 }
5352
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005353 /**
5354 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005355 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005356 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 Phone phone = getPhone(subId);
5360 if (phone != null) {
5361 return phone.isWifiCallingEnabled();
5362 } else {
5363 return false;
5364 }
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005367 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005368 }
5369
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005370 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005371 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005372 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005373 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005374 final long identity = Binder.clearCallingIdentity();
5375 try {
5376 Phone phone = getPhone(subId);
5377 if (phone != null) {
5378 return phone.isVideoEnabled();
5379 } else {
5380 return false;
5381 }
5382 } finally {
5383 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005384 }
5385 }
5386
5387 /**
5388 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5389 * defined in {@link ImsRegistrationImplBase}.
5390 */
5391 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005392 final long identity = Binder.clearCallingIdentity();
5393 try {
5394 Phone phone = getPhone(subId);
5395 if (phone != null) {
5396 return phone.getImsRegistrationTech();
5397 } else {
5398 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5399 }
5400 } finally {
5401 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005402 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005403 }
5404
Stuart Scott8eef64f2015-04-08 15:13:54 -07005405 @Override
5406 public void factoryReset(int subId) {
5407 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005408 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5409 return;
5410 }
5411
Svet Ganovcc087f82015-05-12 20:35:54 -07005412 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005413
Svet Ganovcc087f82015-05-12 20:35:54 -07005414 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005415 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5416 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005417 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005418 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005419 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005420 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5421 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005422 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005423 // There has been issues when Sms raw table somehow stores orphan
5424 // fragments. They lead to garbled message when new fragments come
5425 // in and combined with those stale ones. In case this happens again,
5426 // user can reset all network settings which will clean up this table.
5427 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005428 } finally {
5429 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005430 }
5431 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005432
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005433 private void cleanUpSmsRawTable(Context context) {
5434 ContentResolver resolver = context.getContentResolver();
5435 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5436 resolver.delete(uri, null, null);
5437 }
5438
Narayan Kamath1c496c22015-04-16 14:40:19 +01005439 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005440 public String getSimLocaleForSubscriber(int subId) {
5441 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5442 final Phone phone = getPhone(subId);
5443 if (phone == null) {
5444 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005445 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005446 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005447 final long identity = Binder.clearCallingIdentity();
5448 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005449 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5450 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005451 // Try and fetch the locale from the carrier properties or from the SIM language
5452 // preferences (EF-PL and EF-LI)...
5453 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005454 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005455 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5456 if (localeFromDefaultSim != null) {
5457 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5458 if (DBG) log("Using locale from subId: " + subId + " locale: "
5459 + localeFromDefaultSim);
5460 return localeFromDefaultSim.toLanguageTag();
5461 } else {
5462 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005463 }
5464 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005465
Malcolm Chend965c8b2018-02-28 15:00:40 -08005466 // The SIM language preferences only store a language (e.g. fr = French), not an
5467 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5468 // the SIM and carrier preferences does not include a country we add the country
5469 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005470 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005471 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005472 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005473 return mccLocale.toLanguageTag();
5474 }
5475
5476 if (DBG) log("No locale found - returning null");
5477 return null;
5478 } finally {
5479 Binder.restoreCallingIdentity(identity);
5480 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005481 }
5482
5483 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005484 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005485 }
5486
Malcolm Chend965c8b2018-02-28 15:00:40 -08005487 /**
5488 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5489 */
5490 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005491 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005492 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005493
Chenjie Yu1ba97252018-01-11 18:16:20 -08005494 private final ModemActivityInfo mLastModemActivityInfo =
5495 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5496
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005497 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005498 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5499 * representing the state of the modem.
5500 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005501 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5502 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005503 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005504 */
5505 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005506 public void requestModemActivityInfo(ResultReceiver result) {
5507 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005508 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005509
5510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 ModemActivityInfo ret = null;
5513 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005514 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5515 CMD_GET_MODEM_ACTIVITY_INFO,
5516 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005517 if (isModemActivityInfoValid(info)) {
5518 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5519 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5520 mergedTxTimeMs[i] =
5521 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5522 }
5523 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5524 mLastModemActivityInfo.setSleepTimeMillis(
5525 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5526 mLastModemActivityInfo.setIdleTimeMillis(
5527 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5528 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5529 mLastModemActivityInfo.setRxTimeMillis(
5530 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5531 mLastModemActivityInfo.setEnergyUsed(
5532 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005533 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005534 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5535 mLastModemActivityInfo.getSleepTimeMillis(),
5536 mLastModemActivityInfo.getIdleTimeMillis(),
5537 mLastModemActivityInfo.getTxTimeMillis(),
5538 mLastModemActivityInfo.getRxTimeMillis(),
5539 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005540 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005541 Bundle bundle = new Bundle();
5542 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5543 result.send(0, bundle);
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005546 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005547 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005548
Siddharth Rayf5d29552018-06-17 15:02:38 -07005549 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5550 // less than total activity duration.
5551 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5552 if (info == null) {
5553 return false;
5554 }
5555 int activityDurationMs =
5556 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5557 int totalTxTimeMs = 0;
5558 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5559 totalTxTimeMs += info.getTxTimeMillis()[i];
5560 }
5561 return (info.isValid()
5562 && (info.getSleepTimeMillis() <= activityDurationMs)
5563 && (info.getIdleTimeMillis() <= activityDurationMs)
5564 && (info.getRxTimeMillis() <= activityDurationMs)
5565 && (totalTxTimeMs <= activityDurationMs));
5566 }
5567
Jack Yu85bd38a2015-11-09 11:34:32 -08005568 /**
5569 * {@hide}
5570 * Returns the service state information on specified subscription.
5571 */
5572 @Override
5573 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005575 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005576 return null;
5577 }
5578
Hall Liuf19c44f2018-11-27 14:38:17 -08005579 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5580 LocationAccessPolicy.checkLocationPermission(mApp,
5581 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5582 .setCallingPackage(callingPackage)
5583 .setCallingPid(Binder.getCallingPid())
5584 .setCallingUid(Binder.getCallingUid())
5585 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005586 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005587 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5588 .build());
5589
5590 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5591 LocationAccessPolicy.checkLocationPermission(mApp,
5592 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5593 .setCallingPackage(callingPackage)
5594 .setCallingPid(Binder.getCallingPid())
5595 .setCallingUid(Binder.getCallingUid())
5596 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005597 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005598 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5599 .build());
5600 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5601 boolean hasFinePermission =
5602 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5603 boolean hasCoarsePermission =
5604 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5605
Malcolm Chend965c8b2018-02-28 15:00:40 -08005606 final long identity = Binder.clearCallingIdentity();
5607 try {
5608 final Phone phone = getPhone(subId);
5609 if (phone == null) {
5610 return null;
5611 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005612
Hall Liuf19c44f2018-11-27 14:38:17 -08005613 ServiceState ss = phone.getServiceState();
5614
5615 // Scrub out the location info in ServiceState depending on what level of access
5616 // the caller has.
5617 if (hasFinePermission) return ss;
5618 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5619 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005623 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005624
5625 /**
5626 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5627 *
5628 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5629 * voicemail ringtone.
5630 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5631 * PhoneAccount.
5632 */
5633 @Override
5634 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5638 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005639 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005640 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005641
Malcolm Chend965c8b2018-02-28 15:00:40 -08005642 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005646 }
5647
5648 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005649 * Sets the per-account voicemail ringtone.
5650 *
5651 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5652 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5653 *
5654 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5655 * voicemail ringtone.
5656 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5657 * PhoneAccount.
5658 */
5659 @Override
5660 public void setVoicemailRingtoneUri(String callingPackage,
5661 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005662 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5664 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005665 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5667 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5668 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005669 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005670
5671 final long identity = Binder.clearCallingIdentity();
5672 try {
5673 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5674 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005675 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005676 }
5677 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5678 } finally {
5679 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005680 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005681 }
5682
5683 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005684 * Returns whether vibration is set for voicemail notification in Phone settings.
5685 *
5686 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5687 * voicemail vibration setting.
5688 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5689 */
5690 @Override
5691 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5695 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005696 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005697 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005698
Malcolm Chend965c8b2018-02-28 15:00:40 -08005699 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005703 }
5704
Youhan Wange64578a2016-05-02 15:32:42 -07005705 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005706 * Sets the per-account voicemail vibration.
5707 *
5708 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5709 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5710 *
5711 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5712 * voicemail vibration setting.
5713 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5714 * specific PhoneAccount.
5715 */
5716 @Override
5717 public void setVoicemailVibrationEnabled(String callingPackage,
5718 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005719 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5721 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005722 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5724 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5725 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005726 }
5727
Malcolm Chend965c8b2018-02-28 15:00:40 -08005728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5731 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005732 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005733 }
5734 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5735 } finally {
5736 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005737 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005738 }
5739
5740 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005741 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5742 *
5743 * @throws SecurityException if the caller does not have the required permission
5744 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005745 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005746 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005747 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005748 }
5749
5750 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005751 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5752 * permission.
5753 *
5754 * @throws SecurityException if the caller does not have the required permission
5755 */
5756 private void enforceSendSmsPermission() {
5757 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5758 }
5759
5760 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005761 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005762 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005763 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005764 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005765 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005769 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005770 if (componentName == null) {
5771 throw new SecurityException(
5772 "Caller not current active visual voicemail package[null]");
5773 }
5774 String vvmPackage = componentName.getPackageName();
5775 if (!callingPackage.equals(vvmPackage)) {
5776 throw new SecurityException("Caller not current active visual voicemail package["
5777 + vvmPackage + "]");
5778 }
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005781 }
5782 }
5783
5784 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005785 * Return the application ID for the app type.
5786 *
5787 * @param subId the subscription ID that this request applies to.
5788 * @param appType the uicc app type.
5789 * @return Application ID for specificied app type, or null if no uicc.
5790 */
5791 @Override
5792 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005793 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005794 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005795
5796 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005797 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005798 if (phone == null) {
5799 return null;
5800 }
5801 String aid = null;
5802 try {
5803 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5804 .getApplicationByType(appType).getAid();
5805 } catch (Exception e) {
5806 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5807 }
5808 return aid;
5809 } finally {
5810 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005811 }
Youhan Wange64578a2016-05-02 15:32:42 -07005812 }
5813
Youhan Wang4001d252016-05-11 10:29:41 -07005814 /**
5815 * Return the Electronic Serial Number.
5816 *
5817 * @param subId the subscription ID that this request applies to.
5818 * @return ESN or null if error.
5819 */
5820 @Override
5821 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005822 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005823 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005824
5825 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005826 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005827 if (phone == null) {
5828 return null;
5829 }
5830 String esn = null;
5831 try {
5832 esn = phone.getEsn();
5833 } catch (Exception e) {
5834 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5835 }
5836 return esn;
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005839 }
Youhan Wang4001d252016-05-11 10:29:41 -07005840 }
5841
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005842 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005843 * Return the Preferred Roaming List Version.
5844 *
5845 * @param subId the subscription ID that this request applies to.
5846 * @return PRLVersion or null if error.
5847 */
5848 @Override
5849 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005850 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005851 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005852
5853 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005854 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005855 if (phone == null) {
5856 return null;
5857 }
5858 String cdmaPrlVersion = null;
5859 try {
5860 cdmaPrlVersion = phone.getCdmaPrlVersion();
5861 } catch (Exception e) {
5862 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5863 }
5864 return cdmaPrlVersion;
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005867 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005868 }
5869
5870 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005871 * Get snapshot of Telephony histograms
5872 * @return List of Telephony histograms
5873 * @hide
5874 */
5875 @Override
5876 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5878 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005879
5880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 return RIL.getTelephonyRILTimingHistograms();
5883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005886 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005887
5888 /**
5889 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005890 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5891 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005892 * Require system privileges. In the future we may add this to carrier APIs.
5893 *
Michele Berionne0963c862018-11-27 18:57:59 -08005894 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005895 */
5896 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005897 @TelephonyManager.SetCarrierRestrictionResult
5898 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005899 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005900 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005901
Michele Berionne0963c862018-11-27 18:57:59 -08005902 if (carrierRestrictionRules == null) {
5903 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005904 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005905
Malcolm Chend965c8b2018-02-28 15:00:40 -08005906 final long identity = Binder.clearCallingIdentity();
5907 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005908 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005909 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005913 }
5914
5915 /**
5916 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005917 * Get the allowed carrier list and the excluded carrier list, including the priority between
5918 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005919 * Require system privileges. In the future we may add this to carrier APIs.
5920 *
Michele Berionne0963c862018-11-27 18:57:59 -08005921 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005922 */
5923 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005924 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005925 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005927
5928 final long identity = Binder.clearCallingIdentity();
5929 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005930 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5931 if (response instanceof CarrierRestrictionRules) {
5932 return (CarrierRestrictionRules) response;
5933 }
5934 // Response is an Exception of some kind,
5935 // which is signalled to the user as a NULL retval
5936 return null;
5937 } catch (Exception e) {
5938 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5939 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005940 } finally {
5941 Binder.restoreCallingIdentity(identity);
5942 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005943 }
5944
fionaxu59545b42016-05-25 15:53:37 -07005945 /**
5946 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5947 * @param subId the subscription ID that this action applies to.
5948 * @param enabled control enable or disable metered apns.
5949 * {@hide}
5950 */
5951 @Override
5952 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5953 enforceModifyPermission();
5954 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005955
5956 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005957 if (phone == null) {
5958 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5959 return;
5960 }
5961 try {
5962 phone.carrierActionSetMeteredApnsEnabled(enabled);
5963 } catch (Exception e) {
5964 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005967 }
5968 }
5969
5970 /**
5971 * Action set from carrier signalling broadcast receivers to enable/disable radio
5972 * @param subId the subscription ID that this action applies to.
5973 * @param enabled control enable or disable radio.
5974 * {@hide}
5975 */
5976 @Override
5977 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5978 enforceModifyPermission();
5979 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005980
5981 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005982 if (phone == null) {
5983 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5984 return;
5985 }
5986 try {
5987 phone.carrierActionSetRadioEnabled(enabled);
5988 } catch (Exception e) {
5989 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005990 } finally {
5991 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005992 }
5993 }
5994
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005995 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005996 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5997 * network status based on which carrier apps could apply actions accordingly,
5998 * enable/disable default url handler for example.
5999 *
6000 * @param subId the subscription ID that this action applies to.
6001 * @param report control start/stop reporting the default network status.
6002 * {@hide}
6003 */
6004 @Override
6005 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6006 enforceModifyPermission();
6007 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006008
6009 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006010 if (phone == null) {
6011 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6012 return;
6013 }
6014 try {
6015 phone.carrierActionReportDefaultNetworkStatus(report);
6016 } catch (Exception e) {
6017 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006018 } finally {
6019 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006020 }
6021 }
6022
6023 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006024 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6025 * bug report is being generated.
6026 */
6027 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006028 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006029 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6030 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006031 writer.println("Permission Denial: can't dump Phone from pid="
6032 + Binder.getCallingPid()
6033 + ", uid=" + Binder.getCallingUid()
6034 + "without permission "
6035 + android.Manifest.permission.DUMP);
6036 return;
6037 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006038 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006039 }
Jack Yueb89b242016-06-22 13:27:47 -07006040
Brad Ebingerdac2f002018-04-03 15:17:52 -07006041 @Override
6042 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6043 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6044 throws RemoteException {
6045 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6046 }
6047
Jack Yueb89b242016-06-22 13:27:47 -07006048 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006049 * Get aggregated video call data usage since boot.
6050 *
6051 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6052 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006053 * {@hide}
6054 */
6055 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006056 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006057 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6058 null);
6059
Malcolm Chend965c8b2018-02-28 15:00:40 -08006060 final long identity = Binder.clearCallingIdentity();
6061 try {
6062 // NetworkStatsService keeps tracking the active network interface and identity. It
6063 // records the delta with the corresponding network identity.
6064 // We just return the total video call data usage snapshot since boot.
6065 Phone phone = getPhone(subId);
6066 if (phone != null) {
6067 return phone.getVtDataUsage(perUidStats);
6068 }
6069 return null;
6070 } finally {
6071 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006072 }
Jack Yueb89b242016-06-22 13:27:47 -07006073 }
Jack Yu75ab2952016-07-08 14:29:33 -07006074
6075 /**
6076 * Policy control of data connection. Usually used when data limit is passed.
6077 * @param enabled True if enabling the data, otherwise disabling.
6078 * @param subId Subscription index
6079 * {@hide}
6080 */
6081 @Override
6082 public void setPolicyDataEnabled(boolean enabled, int subId) {
6083 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006084
6085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 Phone phone = getPhone(subId);
6088 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006089 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006090 }
6091 } finally {
6092 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006093 }
6094 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006095
6096 /**
6097 * Get Client request stats
6098 * @return List of Client Request Stats
6099 * @hide
6100 */
6101 @Override
6102 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006104 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006105 return null;
6106 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006107 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006108
Malcolm Chend965c8b2018-02-28 15:00:40 -08006109 final long identity = Binder.clearCallingIdentity();
6110 try {
6111 if (phone != null) {
6112 return phone.getClientRequestStats();
6113 }
6114
6115 return null;
6116 } finally {
6117 Binder.restoreCallingIdentity(identity);
6118 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006119 }
6120
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006121 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006122 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006123 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006124 }
Jack Yueb4124c2017-02-16 15:32:43 -08006125
6126 /**
Grace Chen70990072017-03-24 17:21:30 -07006127 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006128 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006129 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006130 * @param state State of SIM (power down, power up, pass through)
6131 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6132 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6133 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006134 *
6135 **/
6136 @Override
Grace Chen70990072017-03-24 17:21:30 -07006137 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006138 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006139 Phone phone = PhoneFactory.getPhone(slotIndex);
6140
vagdevie435a3e2018-08-15 16:01:53 -07006141 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6142
Malcolm Chend965c8b2018-02-28 15:00:40 -08006143 final long identity = Binder.clearCallingIdentity();
6144 try {
6145 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006146 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006147 }
6148 } finally {
6149 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006150 }
6151 }
Shuo Qiandd210312017-04-12 22:11:33 +00006152
Tyler Gunn65d45c22017-06-05 11:22:26 -07006153 private boolean isUssdApiAllowed(int subId) {
6154 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006155 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006156 if (configManager == null) {
6157 return false;
6158 }
6159 PersistableBundle pb = configManager.getConfigForSubId(subId);
6160 if (pb == null) {
6161 return false;
6162 }
6163 return pb.getBoolean(
6164 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6165 }
6166
Shuo Qiandd210312017-04-12 22:11:33 +00006167 /**
6168 * Check if phone is in emergency callback mode
6169 * @return true if phone is in emergency callback mode
6170 * @param subId sub id
6171 */
goneil9c5f4872017-12-05 14:07:56 -08006172 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006173 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006174 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006175 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006176
6177 final long identity = Binder.clearCallingIdentity();
6178 try {
6179 if (phone != null) {
6180 return phone.isInEcm();
6181 } else {
6182 return false;
6183 }
6184 } finally {
6185 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006186 }
6187 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006188
6189 /**
6190 * Get the current signal strength information for the given subscription.
6191 * Because this information is not updated when the device is in a low power state
6192 * it should not be relied-upon to be current.
6193 * @param subId Subscription index
6194 * @return the most recent cached signal strength info from the modem
6195 */
6196 @Override
6197 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006198 final long identity = Binder.clearCallingIdentity();
6199 try {
6200 Phone p = getPhone(subId);
6201 if (p == null) {
6202 return null;
6203 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006204
Malcolm Chend965c8b2018-02-28 15:00:40 -08006205 return p.getSignalStrength();
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
6208 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006209 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006210
Pengquan Meng9140aec2018-08-22 14:49:57 -07006211 /**
chen xu907e5a22018-10-11 13:21:04 -07006212 * Get the current modem radio state for the given slot.
6213 * @param slotIndex slot index.
6214 * @param callingPackage the name of the package making the call.
6215 * @return the current radio power state from the modem
6216 */
6217 @Override
6218 public int getRadioPowerState(int slotIndex, String callingPackage) {
6219 Phone phone = PhoneFactory.getPhone(slotIndex);
6220 if (phone != null) {
6221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6222 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6223 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6224 }
6225
6226 final long identity = Binder.clearCallingIdentity();
6227 try {
6228 return phone.getRadioPowerState();
6229 } finally {
6230 Binder.restoreCallingIdentity(identity);
6231 }
6232 }
6233 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6234 }
6235
6236 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006237 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6238 *
6239 * <p>Requires one of the following permissions:
6240 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6241 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6242 * privileges.
6243 *
6244 * @param subId subscription id
6245 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6246 * {@code false}.
6247 */
6248 @Override
6249 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006250 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6251 null /* message */);
6252
Pengquan Meng0c05b502018-09-06 09:59:22 -07006253 boolean isEnabled = false;
6254 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006255 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006256 Phone phone = getPhone(subId);
6257 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006258 } catch (Exception e) {
6259 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6260 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006261 } finally {
6262 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006263 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006264 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006265 }
6266
6267
6268 /**
6269 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6270 *
6271 * <p> Requires permission:
6272 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6273 * privileges.
6274 *
6275 * @param subId subscription id
6276 * @param isEnabled {@code true} means enable, {@code false} means disable.
6277 */
6278 @Override
6279 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6281 mApp, subId, "setDataRoamingEnabled");
6282
Pengquan Meng0c05b502018-09-06 09:59:22 -07006283 final long identity = Binder.clearCallingIdentity();
6284 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006285 Phone phone = getPhone(subId);
6286 if (phone != null) {
6287 phone.setDataRoamingEnabled(isEnabled);
6288 }
6289 } finally {
6290 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006291 }
6292 }
6293
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006294 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006295 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006296 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6297 mApp, subId, "isManualNetworkSelectionAllowed");
6298
Pengquan Meng312de0c2018-10-03 12:19:13 -07006299 boolean isAllowed = true;
6300 final long identity = Binder.clearCallingIdentity();
6301 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006302 Phone phone = getPhone(subId);
6303 if (phone != null) {
6304 isAllowed = phone.isCspPlmnEnabled();
6305 }
6306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
6309 return isAllowed;
6310 }
6311
6312 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006313 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006314 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006315 try {
6316 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006317 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006318 } catch (SecurityException e) {
6319 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6320 // has carrier privileges on an active UICC
6321 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6322 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006323 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006324 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006325 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006326
6327 final long identity = Binder.clearCallingIdentity();
6328 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006329 UiccController uiccController = UiccController.getInstance();
6330 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006331 if (hasReadPermission) {
6332 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006333 }
Jordan Liu67997952019-04-22 15:10:43 -07006334
6335 // Remove private info if the caller doesn't have access
6336 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6337 for (UiccCardInfo cardInfo : cardInfos) {
6338 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6339 // is available
6340 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6341 if (card == null || card.getUiccProfile() == null) {
6342 // assume no access if the card or profile is unavailable
6343 filteredInfos.add(cardInfo.getUnprivileged());
6344 continue;
6345 }
6346 UiccProfile profile = card.getUiccProfile();
6347 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6348 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6349 filteredInfos.add(cardInfo);
6350 } else {
6351 filteredInfos.add(cardInfo.getUnprivileged());
6352 }
6353 }
6354 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006355 } finally {
6356 Binder.restoreCallingIdentity(identity);
6357 }
6358 }
6359
6360 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006361 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006362 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006363
Malcolm Chend965c8b2018-02-28 15:00:40 -08006364 final long identity = Binder.clearCallingIdentity();
6365 try {
6366 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6367 if (slots == null) {
6368 Rlog.i(LOG_TAG, "slots is null.");
6369 return null;
6370 }
6371
6372 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6373 for (int i = 0; i < slots.length; i++) {
6374 UiccSlot slot = slots[i];
6375 if (slot == null) {
6376 continue;
6377 }
6378
6379 String cardId;
6380 UiccCard card = slot.getUiccCard();
6381 if (card != null) {
6382 cardId = card.getCardId();
6383 } else {
6384 cardId = slot.getIccId();
6385 }
6386
6387 int cardState = 0;
6388 switch (slot.getCardState()) {
6389 case CARDSTATE_ABSENT:
6390 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6391 break;
6392 case CARDSTATE_PRESENT:
6393 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6394 break;
6395 case CARDSTATE_ERROR:
6396 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6397 break;
6398 case CARDSTATE_RESTRICTED:
6399 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6400 break;
6401 default:
6402 break;
6403
6404 }
6405
6406 infos[i] = new UiccSlotInfo(
6407 slot.isActive(),
6408 slot.isEuicc(),
6409 cardId,
6410 cardState,
6411 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006412 slot.isExtendedApduSupported(),
6413 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006414 }
6415 return infos;
6416 } finally {
6417 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006418 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006419 }
6420
6421 @Override
6422 public boolean switchSlots(int[] physicalSlots) {
6423 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006424
6425 final long identity = Binder.clearCallingIdentity();
6426 try {
6427 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006431 }
Jack Yu4c988042018-02-27 15:30:01 -08006432
6433 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006434 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006435 final long identity = Binder.clearCallingIdentity();
6436 try {
6437 return UiccController.getInstance().getCardIdForDefaultEuicc();
6438 } finally {
6439 Binder.restoreCallingIdentity(identity);
6440 }
6441 }
6442
6443 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006444 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6445 enforceModifyPermission();
6446 final Phone phone = getPhone(subId);
6447 if (phone == null) {
6448 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6449 return;
6450 }
6451
Malcolm Chend965c8b2018-02-28 15:00:40 -08006452 final long identity = Binder.clearCallingIdentity();
6453 try {
6454 phone.setRadioIndicationUpdateMode(filters, mode);
6455 } finally {
6456 Binder.restoreCallingIdentity(identity);
6457 }
Jack Yu4c988042018-02-27 15:30:01 -08006458 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006459
6460 /**
goneil47ffb6e2018-04-06 15:40:58 -07006461 * A test API to reload the UICC profile.
6462 *
6463 * <p>Requires that the calling app has permission
6464 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6465 * @hide
6466 */
6467 @Override
6468 public void refreshUiccProfile(int subId) {
6469 enforceModifyPermission();
6470
6471 final long identity = Binder.clearCallingIdentity();
6472 try {
6473 Phone phone = getPhone(subId);
6474 if (phone == null) {
6475 return;
6476 }
6477 UiccCard uiccCard = phone.getUiccCard();
6478 if (uiccCard == null) {
6479 return;
6480 }
6481 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6482 if (uiccProfile == null) {
6483 return;
6484 }
6485 uiccProfile.refresh();
6486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
6491 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006492 * Returns false if the mobile data is disabled by default, otherwise return true.
6493 */
6494 private boolean getDefaultDataEnabled() {
6495 return "true".equalsIgnoreCase(
6496 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6497 }
6498
6499 /**
6500 * Returns true if the data roaming is enabled by default, i.e the system property
6501 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6502 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6503 */
6504 private boolean getDefaultDataRoamingEnabled(int subId) {
6505 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006506 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006507 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6508 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6509 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6510 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6511 return isDataRoamingEnabled;
6512 }
6513
6514 /**
6515 * Returns the default network type for the given {@code subId}, if the default network type is
6516 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6517 */
6518 private int getDefaultNetworkType(int subId) {
6519 return Integer.parseInt(
6520 TelephonyManager.getTelephonyProperty(
6521 mSubscriptionController.getPhoneId(subId),
6522 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6523 String.valueOf(Phone.PREFERRED_NT_MODE)));
6524 }
fionaxua13278b2018-03-21 00:08:13 -07006525
6526 @Override
6527 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6528 gid1, String gid2, String plmn, String spn) {
6529 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006530
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
6533 final Phone phone = getPhone(subId);
6534 if (phone == null) {
6535 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6536 return;
6537 }
6538 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6539 } finally {
6540 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006541 }
fionaxua13278b2018-03-21 00:08:13 -07006542 }
6543
6544 @Override
6545 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006546 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006547
6548 final long identity = Binder.clearCallingIdentity();
6549 try {
6550 final Phone phone = getPhone(subId);
6551 if (phone == null) {
6552 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6553 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6554 }
6555 return phone.getCarrierIdListVersion();
6556 } finally {
6557 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006558 }
fionaxua13278b2018-03-21 00:08:13 -07006559 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006560
6561 @Override
6562 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6564 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6565 return -1;
6566 }
6567
6568 final long identity = Binder.clearCallingIdentity();
6569 try {
6570 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6571 } finally {
6572 Binder.restoreCallingIdentity(identity);
6573 }
6574 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006575
6576 @Override
6577 public int getCdmaRoamingMode(int subId) {
6578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6579 mApp, subId, "getCdmaRoamingMode");
6580
6581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6584 } finally {
6585 Binder.restoreCallingIdentity(identity);
6586 }
6587 }
6588
6589 @Override
6590 public boolean setCdmaRoamingMode(int subId, int mode) {
6591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6592 mApp, subId, "setCdmaRoamingMode");
6593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6597 } finally {
6598 Binder.restoreCallingIdentity(identity);
6599 }
6600 }
6601
6602 @Override
6603 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6605 mApp, subId, "setCdmaSubscriptionMode");
6606
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
6613 }
chen xu7ee67862018-10-30 22:27:10 -07006614
sqian2fff4a32018-11-05 14:18:37 -08006615 private void ensureUserRunning(int userId) {
6616 if (!mUserManager.isUserRunning(userId)) {
6617 throw new IllegalStateException("User " + userId + " does not exist or not running");
6618 }
6619 }
6620
6621 /**
6622 * Returns a list of SMS apps on a given user.
6623 *
6624 * Only the shell user (UID 2000 or 0) can call it.
6625 * Target user must be running.
6626 */
6627 @Override
6628 public String[] getSmsApps(int userId) {
6629 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6630 ensureUserRunning(userId);
6631
6632 final Collection<SmsApplicationData> apps =
6633 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6634
6635 String[] ret = new String[apps.size()];
6636 int i = 0;
6637 for (SmsApplicationData app : apps) {
6638 ret[i++] = app.mPackageName;
6639 }
6640 return ret;
6641 }
6642
6643 /**
6644 * Returns the default SMS app package name on a given user.
6645 *
6646 * Only the shell user (UID 2000 or 0) can call it.
6647 * Target user must be running.
6648 */
6649 @Override
6650 public String getDefaultSmsApp(int userId) {
6651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6652 ensureUserRunning(userId);
6653
6654 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6655 /* updateIfNeeded= */ true, userId);
6656 return cn == null ? null : cn.getPackageName();
6657 }
6658
6659 /**
6660 * Set a package as the default SMS app on a given user.
6661 *
6662 * Only the shell user (UID 2000 or 0) can call it.
6663 * Target user must be running.
6664 */
6665 @Override
6666 public void setDefaultSmsApp(int userId, String packageName) {
6667 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6668 ensureUserRunning(userId);
6669
6670 boolean found = false;
6671 for (String pkg : getSmsApps(userId)) {
6672 if (TextUtils.equals(packageName, pkg)) {
6673 found = true;
6674 break;
6675 }
6676 }
6677 if (!found) {
6678 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6679 }
6680
6681 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6682 }
6683
chen xu7ee67862018-10-30 22:27:10 -07006684 @Override
sqian65eefe12019-02-22 15:55:18 -08006685 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006686 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006688 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006689 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6690 }
6691 final long identity = Binder.clearCallingIdentity();
6692 try {
sqian991b35e2018-12-12 16:48:18 -08006693 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6694 for (Phone phone: PhoneFactory.getPhones()) {
6695 if (phone.getEmergencyNumberTracker() != null
6696 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6697 emergencyNumberListInternal.put(
6698 phone.getSubId(),
6699 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6700 }
sqian03bca152018-12-05 18:48:28 -08006701 }
sqian991b35e2018-12-12 16:48:18 -08006702 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006703 } finally {
6704 Binder.restoreCallingIdentity(identity);
6705 }
sqian04b86072018-11-07 14:02:21 -08006706 }
6707
6708 @Override
sqian65eefe12019-02-22 15:55:18 -08006709 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006710 final Phone defaultPhone = getDefaultPhone();
6711 if (!exactMatch) {
6712 TelephonyPermissions
6713 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006714 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006715 }
6716 final long identity = Binder.clearCallingIdentity();
6717 try {
sqian991b35e2018-12-12 16:48:18 -08006718 for (Phone phone: PhoneFactory.getPhones()) {
6719 if (phone.getEmergencyNumberTracker() != null
6720 && phone.getEmergencyNumberTracker() != null) {
6721 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6722 number, exactMatch)) {
6723 return true;
sqian03bca152018-12-05 18:48:28 -08006724 }
6725 }
sqian03bca152018-12-05 18:48:28 -08006726 }
6727 return false;
6728 } finally {
6729 Binder.restoreCallingIdentity(identity);
6730 }
6731 }
6732
sqian9d4df8b2019-01-15 18:32:07 -08006733 /**
6734 * Update emergency number list for test mode.
6735 */
6736 @Override
6737 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6739 "updateEmergencyNumberListTestMode");
6740
6741 final long identity = Binder.clearCallingIdentity();
6742 try {
6743 for (Phone phone: PhoneFactory.getPhones()) {
6744 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6745 if (tracker != null) {
6746 tracker.executeEmergencyNumberTestModeCommand(action, num);
6747 }
6748 }
6749 } finally {
6750 Binder.restoreCallingIdentity(identity);
6751 }
6752 }
6753
6754 /**
6755 * Get the full emergency number list for test mode.
6756 */
6757 @Override
6758 public List<String> getEmergencyNumberListTestMode() {
6759 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6760 "getEmergencyNumberListTestMode");
6761
6762 final long identity = Binder.clearCallingIdentity();
6763 try {
6764 Set<String> emergencyNumbers = new HashSet<>();
6765 for (Phone phone: PhoneFactory.getPhones()) {
6766 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6767 if (tracker != null) {
6768 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6769 emergencyNumbers.add(num.getNumber());
6770 }
6771 }
6772 }
6773 return new ArrayList<>(emergencyNumbers);
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
6776 }
6777 }
6778
sqian04b86072018-11-07 14:02:21 -08006779 @Override
chen xu7ee67862018-10-30 22:27:10 -07006780 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6781 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6782 Phone phone = getPhone(subId);
6783 if (phone == null) {
6784 return null;
6785 }
6786 final long identity = Binder.clearCallingIdentity();
6787 try {
6788 UiccProfile profile = UiccController.getInstance()
6789 .getUiccProfileForPhone(phone.getPhoneId());
6790 if (profile != null) {
6791 return profile.getCertsFromCarrierPrivilegeAccessRules();
6792 }
6793 } finally {
6794 Binder.restoreCallingIdentity(identity);
6795 }
6796 return null;
6797 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006798
6799 /**
6800 * Enable or disable a modem stack.
6801 */
6802 @Override
6803 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6804 enforceModifyPermission();
6805
6806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 Phone phone = PhoneFactory.getPhone(slotIndex);
6809 if (phone == null) {
6810 return false;
6811 } else {
6812 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6813 }
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
6816 }
6817 }
Micheled3107c52018-12-21 15:00:11 -08006818
Malcolm Chen33f55e12019-03-27 18:34:05 -07006819 /**
6820 * Whether a modem stack is enabled or not.
6821 */
6822 @Override
6823 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6824 Phone phone = PhoneFactory.getPhone(slotIndex);
6825 if (phone == null) return false;
6826
6827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6828 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6829 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6830 }
6831
6832 final long identity = Binder.clearCallingIdentity();
6833 try {
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07006834 try {
6835 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6836 } catch (NoSuchElementException ex) {
6837 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6838 }
Malcolm Chen33f55e12019-03-27 18:34:05 -07006839 } finally {
6840 Binder.restoreCallingIdentity(identity);
6841 }
6842 }
6843
Micheled3107c52018-12-21 15:00:11 -08006844 @Override
Michele2fb0f222019-03-19 14:58:42 -07006845 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006846 enforceModifyPermission();
6847
6848 final long identity = Binder.clearCallingIdentity();
6849 try {
6850 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006851 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006852 .commit();
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
6855 }
6856 }
6857
6858 @Override
Michele2fb0f222019-03-19 14:58:42 -07006859 @TelephonyManager.IsMultiSimSupportedResult
6860 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006862 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6863 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006864 }
Micheled3107c52018-12-21 15:00:11 -08006865
6866 final long identity = Binder.clearCallingIdentity();
6867 try {
Michele2fb0f222019-03-19 14:58:42 -07006868 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
6872 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006873
Michele2fb0f222019-03-19 14:58:42 -07006874 @TelephonyManager.IsMultiSimSupportedResult
6875 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006876 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6877 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6878 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006879 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6880 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006881 }
6882 // Check if the hardware supports multisim functionality. If usage of multisim is not
6883 // supported by the modem, indicate that it is restricted.
6884 PhoneCapability staticCapability =
6885 mPhoneConfigurationManager.getStaticPhoneCapability();
6886 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006887 loge("isMultiSimSupportedInternal: no static configuration available");
6888 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006889 }
6890 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006891 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6892 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006893 }
6894 // Check if support of multiple SIMs is restricted by carrier
6895 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006896 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006897 }
6898
Michele2fb0f222019-03-19 14:58:42 -07006899 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006900 }
6901
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006902 /**
6903 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006904 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6905 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6906 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006907 * @param numOfSims number of active sims we want to switch to
6908 */
6909 @Override
6910 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006911 if (numOfSims == 1) {
6912 enforceModifyPermission();
6913 } else {
6914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6915 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6916 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006917 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006918
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006919 try {
Michele30b57b22019-03-01 12:01:14 -08006920 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006921 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006922 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6923 return;
6924 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006925 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6926 } finally {
6927 Binder.restoreCallingIdentity(identity);
6928 }
6929 }
6930
6931 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006932 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006933 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006934 */
6935 @Override
6936 public boolean isRebootRequiredForModemConfigChange() {
6937 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6938 final long identity = Binder.clearCallingIdentity();
6939 try {
6940 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6941 } finally {
6942 Binder.restoreCallingIdentity(identity);
6943 }
6944 }
6945
Pengquan Meng92d253b2019-02-06 11:12:53 -08006946 private void updateModemStateMetrics() {
6947 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6948 // TODO: check the state for each modem if the api is ready.
6949 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6950 }
6951
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006952 @Override
6953 public int[] getSlotsMapping() {
6954 enforceReadPrivilegedPermission("getSlotsMapping");
6955
6956 final long identity = Binder.clearCallingIdentity();
6957 try {
6958 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6959 // All logical slots should have a mapping to a physical slot.
6960 int[] logicalSlotsMapping = new int[phoneCount];
6961 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6962 for (int i = 0; i < slotInfos.length; i++) {
6963 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6964 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6965 }
6966 }
6967 return logicalSlotsMapping;
6968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
6971 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006972
6973 /**
6974 * Get the IRadio HAL Version
6975 */
6976 @Override
6977 public int getRadioHalVersion() {
6978 Phone phone = getDefaultPhone();
6979 if (phone == null) return -1;
6980 HalVersion hv = phone.getHalVersion();
6981 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6982 return hv.major * 100 + hv.minor;
6983 }
Malcolm Chen460810d2019-04-10 18:25:07 -07006984
6985 /**
Malcolm Chen29739692019-04-18 13:51:02 -07006986 * Return whether data is enabled for certain APN type. This will tell if framework will accept
6987 * corresponding network requests on a subId.
6988 *
6989 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07006990 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07006991 * 2) APN is un-metered for this subscription, or
6992 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
6993 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
6994 *
6995 * @return whether data is allowed for a apn type.
6996 *
6997 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07006998 */
6999 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07007000 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07007001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07007002 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7003 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07007004 }
7005
7006 // Now that all security checks passes, perform the operation as ourselves.
7007 final long identity = Binder.clearCallingIdentity();
7008 try {
7009 Phone phone = getPhone(subId);
7010 if (phone == null) return false;
7011
7012 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chen29739692019-04-18 13:51:02 -07007013 apnType), phone);
7014 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7015 } finally {
7016 Binder.restoreCallingIdentity(identity);
7017 }
7018 }
7019
7020 @Override
7021 public boolean isApnMetered(int apnType, int subId) {
7022 enforceReadPrivilegedPermission("isApnMetered");
7023
7024 // Now that all security checks passes, perform the operation as ourselves.
7025 final long identity = Binder.clearCallingIdentity();
7026 try {
7027 Phone phone = getPhone(subId);
7028 if (phone == null) return true; // By default return true.
7029
7030 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
7031 apnType), phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07007032 } finally {
7033 Binder.restoreCallingIdentity(identity);
7034 }
7035 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007036}