blob: bb903a5d255d82e7a9e4d3e351862249814879ee [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(
Brad Ebinger076903f2019-05-13 10:00:22 -07003387 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003388 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3389 false);
3390 boolean requireVoiceVtProvisioning = c.getBoolean(
3391 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3392
3393 // First check to make sure that the capability requires provisioning.
3394 switch (capability) {
3395 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3396 // intentional fallthrough
3397 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3398 if (requireVoiceVtProvisioning) {
3399 // Voice and Video requires provisioning
3400 return true;
3401 }
3402 break;
3403 }
3404 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3405 if (requireUtProvisioning) {
3406 // UT requires provisioning
3407 return true;
3408 }
3409 break;
3410 }
3411 }
3412 return false;
3413 }
3414
3415 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003416 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003417 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3418 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3419 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003420 enforceReadPrivilegedPermission("getImsProvisioningInt");
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003424 int slotId = getSlotIndex(subId);
3425 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3426 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3427 + subId + "' for key:" + key);
3428 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3429 }
3430 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003431 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003432 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3433 + subId + "' for key:" + key);
3434 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003435 } finally {
3436 Binder.restoreCallingIdentity(identity);
3437 }
3438 }
3439
3440 @Override
3441 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003442 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3443 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3444 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003445 enforceReadPrivilegedPermission("getImsProvisioningString");
3446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003449 int slotId = getSlotIndex(subId);
3450 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3451 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3452 + subId + "' for key:" + key);
3453 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3454 }
3455 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003456 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003457 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3458 + subId + "' for key:" + key);
3459 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003460 } finally {
3461 Binder.restoreCallingIdentity(identity);
3462 }
3463 }
3464
3465 @Override
3466 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003467 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3468 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3469 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3471 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003472 final long identity = Binder.clearCallingIdentity();
3473 try {
3474 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003475 int slotId = getSlotIndex(subId);
3476 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3477 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3478 + subId + "' for key:" + key);
3479 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3480 }
3481 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003482 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003483 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3484 + "' for key:" + key);
3485 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003486 } finally {
3487 Binder.restoreCallingIdentity(identity);
3488 }
3489 }
3490
3491 @Override
3492 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003493 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3494 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3495 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3497 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003498 final long identity = Binder.clearCallingIdentity();
3499 try {
3500 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003501 int slotId = getSlotIndex(subId);
3502 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3503 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3504 + subId + "' for key:" + key);
3505 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3506 }
3507 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003508 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003509 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3510 + "' for key:" + key);
3511 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
3515 }
3516
Brad Ebinger4c460712018-10-01 10:40:55 -07003517 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3518 int slotId = SubscriptionManager.getSlotIndex(subId);
3519 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003520 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003521 }
3522 return slotId;
3523 }
3524
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003525 private int getSlotIndex(int subId) {
3526 int slotId = SubscriptionManager.getSlotIndex(subId);
3527 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3528 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3529 }
3530 return slotId;
3531 }
3532
Wink Saville36469e72014-06-11 15:17:00 -07003533 /**
3534 * Returns the network type for a subId
3535 */
3536 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003537 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003539 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003540 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3541 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003542
Malcolm Chend965c8b2018-02-28 15:00:40 -08003543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 final Phone phone = getPhone(subId);
3546 if (phone != null) {
3547 return phone.getServiceState().getDataNetworkType();
3548 } else {
3549 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3550 }
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003554 }
3555
3556 /**
3557 * Returns the data network type
3558 */
3559 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003560 public int getDataNetworkType(String callingPackage) {
3561 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003562 }
3563
3564 /**
3565 * Returns the data network type for a subId
3566 */
3567 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003568 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003570 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003571 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3572 }
3573
Malcolm Chend965c8b2018-02-28 15:00:40 -08003574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 final Phone phone = getPhone(subId);
3577 if (phone != null) {
3578 return phone.getServiceState().getDataNetworkType();
3579 } else {
3580 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3581 }
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003585 }
3586
3587 /**
Wink Saville36469e72014-06-11 15:17:00 -07003588 * Returns the Voice network type for a subId
3589 */
3590 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003591 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003593 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003594 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3595 }
3596
Malcolm Chend965c8b2018-02-28 15:00:40 -08003597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 final Phone phone = getPhone(subId);
3600 if (phone != null) {
3601 return phone.getServiceState().getVoiceNetworkType();
3602 } else {
3603 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3604 }
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003608 }
3609
3610 /**
3611 * @return true if a ICC card is present
3612 */
3613 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003614 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003615 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3616 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003617 }
3618
3619 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003620 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003621 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003622 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003623 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 final Phone phone = PhoneFactory.getPhone(slotIndex);
3627 if (phone != null) {
3628 return phone.getIccCard().hasIccCard();
3629 } else {
3630 return false;
3631 }
3632 } finally {
3633 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003635 }
3636
3637 /**
3638 * Return if the current radio is LTE on CDMA. This
3639 * is a tri-state return value as for a period of time
3640 * the mode may be unknown.
3641 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003642 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003643 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003644 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003645 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003646 @Override
3647 public int getLteOnCdmaMode(String callingPackage) {
3648 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003649 }
3650
Sanket Padawe356d7632015-06-22 14:03:32 -07003651 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003652 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003654 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003655 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3656 }
3657
Malcolm Chend965c8b2018-02-28 15:00:40 -08003658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 final Phone phone = getPhone(subId);
3661 if (phone == null) {
3662 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3663 } else {
3664 return phone.getLteOnCdmaMode();
3665 }
3666 } finally {
3667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003668 }
Wink Saville36469e72014-06-11 15:17:00 -07003669 }
3670
Wink Saville36469e72014-06-11 15:17:00 -07003671 /**
3672 * {@hide}
3673 * Returns Default subId, 0 in the case of single standby.
3674 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003675 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003676 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003677 }
3678
Shishir Agrawala9f32182016-04-12 12:00:16 -07003679 private int getSlotForDefaultSubscription() {
3680 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3681 }
3682
Wink Savilleb564aae2014-10-23 10:18:09 -07003683 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003684 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003685 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003686
Pengquan Meng466e2482018-09-21 15:54:48 -07003687 private boolean isActiveSubscription(int subId) {
3688 return mSubscriptionController.isActiveSubId(subId);
3689 }
3690
Ihab Awadf2177b72013-11-25 13:33:23 -08003691 /**
3692 * @see android.telephony.TelephonyManager.WifiCallingChoices
3693 */
3694 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003695 final long identity = Binder.clearCallingIdentity();
3696 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003697 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003698 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3699 getWhenToMakeWifiCallsDefaultPreference());
3700 } finally {
3701 Binder.restoreCallingIdentity(identity);
3702 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003703 }
3704
3705 /**
3706 * @see android.telephony.TelephonyManager.WifiCallingChoices
3707 */
3708 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003709 final long identity = Binder.clearCallingIdentity();
3710 try {
3711 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003712 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003713 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003717 }
3718
Sailesh Nepald1e68152013-12-12 19:08:02 -08003719 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003720 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003721 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003722 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003723
Jordan Liu73b078d2019-02-28 12:03:40 -08003724 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3725 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3726 if (phoneId == -1) {
3727 throw new IllegalArgumentException("Given slot index: " + slotIndex
3728 + " does not correspond to an active phone");
3729 }
3730 return PhoneFactory.getPhone(phoneId);
3731 }
3732
Shishir Agrawal566b7612013-10-28 14:41:00 -07003733 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003734 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3735 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3737 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003739 if (DBG) {
3740 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3741 }
3742 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3743 p2);
3744 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003745
Jordan Liu73b078d2019-02-28 12:03:40 -08003746
3747 @Override
3748 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3749 int slotIndex, String callingPackage, String aid, int p2) {
3750 enforceModifyPermission();
3751 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3752 if (DBG) {
3753 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3754 }
3755 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3756 callingPackage, aid, p2);
3757 }
3758
3759 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3760 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003761 final long identity = Binder.clearCallingIdentity();
3762 try {
3763 if (TextUtils.equals(ISDR_AID, aid)) {
3764 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003765 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3766 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003767 if (bestComponent == null
3768 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3769 loge("The calling package is not allowed to access ISD-R.");
3770 throw new SecurityException(
3771 "The calling package is not allowed to access ISD-R.");
3772 }
Derek Tan740e1672017-06-27 14:56:27 -07003773 }
Derek Tan740e1672017-06-27 14:56:27 -07003774
Malcolm Chend965c8b2018-02-28 15:00:40 -08003775 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003776 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3777 null /* workSource */);
3778 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003779 return response;
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003783 }
3784
3785 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003786 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3788 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003789 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3790 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3791 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003792
Jordan Liu73b078d2019-02-28 12:03:40 -08003793 @Override
3794 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3795 enforceModifyPermission();
3796 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3797 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3798 channel);
3799 }
3800
3801 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003802 final long identity = Binder.clearCallingIdentity();
3803 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003804 if (channel < 0) {
3805 return false;
3806 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003807 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3808 null /* workSource */);
3809 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003810 return success;
3811 } finally {
3812 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003813 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003814 }
3815
3816 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003817 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003818 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3820 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003821 if (DBG) {
3822 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3823 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3824 + p3 + " data=" + data);
3825 }
3826 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3827 command, p1, p2, p3, data);
3828 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003829
Jordan Liu73b078d2019-02-28 12:03:40 -08003830 @Override
3831 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3832 int command, int p1, int p2, int p3, String data) {
3833 enforceModifyPermission();
3834 if (DBG) {
3835 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3836 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3837 + p3 + " data=" + data);
3838 }
3839 return iccTransmitApduLogicalChannelWithPermission(
3840 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3841 data);
3842 }
3843
3844 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3845 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003846 final long identity = Binder.clearCallingIdentity();
3847 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003848 if (channel < 0) {
3849 return "";
3850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003851
Malcolm Chend965c8b2018-02-28 15:00:40 -08003852 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003853 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3854 null /* workSource */);
3855 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003856
Malcolm Chend965c8b2018-02-28 15:00:40 -08003857 // Append the returned status code to the end of the response payload.
3858 String s = Integer.toHexString(
3859 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3860 if (response.payload != null) {
3861 s = IccUtils.bytesToHexString(response.payload) + s;
3862 }
3863 return s;
3864 } finally {
3865 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003866 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003867 }
Jake Hambye994d462014-02-03 13:10:13 -08003868
Evan Charltonc66da362014-05-16 14:06:40 -07003869 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003870 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3871 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3873 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003874 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003875 if (DBG) {
3876 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3877 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3878 }
3879 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3880 cla, command, p1, p2, p3, data);
3881 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003882
Jordan Liu73b078d2019-02-28 12:03:40 -08003883 @Override
3884 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3885 int command, int p1, int p2, int p3, String data) {
3886 enforceModifyPermission();
3887 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3888 if (DBG) {
3889 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3890 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3891 + " data=" + data);
3892 }
3893
3894 return iccTransmitApduBasicChannelWithPermission(
3895 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3896 p2, p3, data);
3897 }
3898
3899 // open APDU basic channel assuming the caller has sufficient permissions
3900 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3901 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003902 final long identity = Binder.clearCallingIdentity();
3903 try {
3904 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3905 && TextUtils.equals(ISDR_AID, data)) {
3906 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003907 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3908 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003909 if (bestComponent == null
3910 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3911 loge("The calling package is not allowed to select ISD-R.");
3912 throw new SecurityException(
3913 "The calling package is not allowed to select ISD-R.");
3914 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003915 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003916
Malcolm Chend965c8b2018-02-28 15:00:40 -08003917 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003918 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3919 null /* workSource */);
3920 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003921
Malcolm Chend965c8b2018-02-28 15:00:40 -08003922 // Append the returned status code to the end of the response payload.
3923 String s = Integer.toHexString(
3924 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3925 if (response.payload != null) {
3926 s = IccUtils.bytesToHexString(response.payload) + s;
3927 }
3928 return s;
3929 } finally {
3930 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003931 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003932 }
3933
3934 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003935 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003936 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3938 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003939
Malcolm Chend965c8b2018-02-28 15:00:40 -08003940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 if (DBG) {
3943 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3944 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3945 }
3946
3947 IccIoResult response =
3948 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3949 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3950 subId);
3951
3952 if (DBG) {
3953 log("Exchange SIM_IO [R]" + response);
3954 }
3955
3956 byte[] result = null;
3957 int length = 2;
3958 if (response.payload != null) {
3959 length = 2 + response.payload.length;
3960 result = new byte[length];
3961 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3962 } else {
3963 result = new byte[length];
3964 }
3965
3966 result[length - 1] = (byte) response.sw2;
3967 result[length - 2] = (byte) response.sw1;
3968 return result;
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003971 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003972 }
3973
Nathan Haroldb3014052017-01-25 15:57:32 -08003974 /**
3975 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3976 * on a particular subscription
3977 */
sqianb6e41952018-03-12 14:54:01 -07003978 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3980 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3981 return null;
3982 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003983
3984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 if (appType != TelephonyManager.APPTYPE_USIM
3987 && appType != TelephonyManager.APPTYPE_SIM) {
3988 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3989 return null;
3990 }
3991 Object response = sendRequest(
3992 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3993 if (response instanceof String[]) {
3994 return (String[]) response;
3995 }
3996 // Response is an Exception of some kind,
3997 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003998 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003999 } finally {
4000 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004001 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004002 }
4003
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004004 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004005 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4007 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004008
Malcolm Chend965c8b2018-02-28 15:00:40 -08004009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4012 if (response.payload == null) {
4013 return "";
4014 }
Evan Charltonc66da362014-05-16 14:06:40 -07004015
Malcolm Chend965c8b2018-02-28 15:00:40 -08004016 // Append the returned status code to the end of the response payload.
4017 String s = Integer.toHexString(
4018 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4019 s = IccUtils.bytesToHexString(response.payload) + s;
4020 return s;
4021 } finally {
4022 Binder.restoreCallingIdentity(identity);
4023 }
Evan Charltonc66da362014-05-16 14:06:40 -07004024 }
4025
Jake Hambye994d462014-02-03 13:10:13 -08004026 /**
4027 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4028 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4029 *
4030 * @param itemID the ID of the item to read
4031 * @return the NV item as a String, or null on error.
4032 */
4033 @Override
4034 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004035 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4037 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004038
4039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004042 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004043 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4044 return value;
4045 } finally {
4046 Binder.restoreCallingIdentity(identity);
4047 }
Jake Hambye994d462014-02-03 13:10:13 -08004048 }
4049
4050 /**
4051 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4052 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4053 *
4054 * @param itemID the ID of the item to read
4055 * @param itemValue the value to write, as a String
4056 * @return true on success; false on any failure
4057 */
4058 @Override
4059 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4062 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004063
4064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4067 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004068 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004069 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4070 return success;
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
Jake Hambye994d462014-02-03 13:10:13 -08004074 }
4075
4076 /**
4077 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4078 * Used for device configuration by some CDMA operators.
4079 *
4080 * @param preferredRoamingList byte array containing the new PRL
4081 * @return true on success; false on any failure
4082 */
4083 @Override
4084 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4086 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004087
4088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4091 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4092 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4093 return success;
4094 } finally {
4095 Binder.restoreCallingIdentity(identity);
4096 }
Jake Hambye994d462014-02-03 13:10:13 -08004097 }
4098
4099 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004100 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004101 * Used for device configuration by some CDMA operators.
4102 *
chen xu1cc0abe2018-10-26 17:39:23 -07004103 * @param slotIndex - device slot.
4104 *
Jake Hambye994d462014-02-03 13:10:13 -08004105 * @return true on success; false on any failure
4106 */
4107 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004108 public boolean resetModemConfig(int slotIndex) {
4109 Phone phone = PhoneFactory.getPhone(slotIndex);
4110 if (phone != null) {
4111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4112 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004113
chen xu1cc0abe2018-10-26 17:39:23 -07004114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4117 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4118 return success;
4119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004122 }
chen xu1cc0abe2018-10-26 17:39:23 -07004123 return false;
4124 }
4125
4126 /**
4127 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4128 *
4129 * @param slotIndex - device slot.
4130 *
4131 * @return true on success; false on any failure
4132 */
4133 @Override
4134 public boolean rebootModem(int slotIndex) {
4135 Phone phone = PhoneFactory.getPhone(slotIndex);
4136 if (phone != null) {
4137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4138 mApp, phone.getSubId(), "rebootModem");
4139
4140 final long identity = Binder.clearCallingIdentity();
4141 try {
4142 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4143 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4144 return success;
4145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
4148 }
4149 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004150 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004151
Svet Ganovb320e182015-04-16 12:30:10 -07004152 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004153 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004154 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004155 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004156 return new String[0];
4157 }
4158
Malcolm Chend965c8b2018-02-28 15:00:40 -08004159 final long identity = Binder.clearCallingIdentity();
4160 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004161 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
Wink Saville36469e72014-06-11 15:17:00 -07004165 }
4166
Brad Ebinger51f743a2017-01-23 13:50:20 -08004167 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004168 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4169 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004170 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004171 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004172 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004173
4174 final long identity = Binder.clearCallingIdentity();
4175 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004176 ImsResolver resolver = PhoneFactory.getImsResolver();
4177 if (resolver == null) {
4178 // may happen if the device does not support IMS.
4179 return;
4180 }
4181 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004182 } finally {
4183 Binder.restoreCallingIdentity(identity);
4184 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004185 }
4186
4187 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004188 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4189 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004190 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004191 public void disableIms(int slotId) {
4192 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004193
4194 final long identity = Binder.clearCallingIdentity();
4195 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004196 ImsResolver resolver = PhoneFactory.getImsResolver();
4197 if (resolver == null) {
4198 // may happen if the device does not support IMS.
4199 return;
4200 }
4201 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004202 } finally {
4203 Binder.restoreCallingIdentity(identity);
4204 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004205 }
4206
4207 /**
4208 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4209 * feature or {@link null} if the service is not available. If the feature is available, the
4210 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4211 */
4212 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004213 IImsServiceFeatureCallback callback) {
4214 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004215
4216 final long identity = Binder.clearCallingIdentity();
4217 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004218 ImsResolver resolver = PhoneFactory.getImsResolver();
4219 if (resolver == null) {
4220 // may happen if the device does not support IMS.
4221 return null;
4222 }
4223 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004224 } finally {
4225 Binder.restoreCallingIdentity(identity);
4226 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004227 }
4228
4229 /**
4230 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4231 * feature during emergency calling or {@link null} if the service is not available. If the
4232 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4233 * listener for feature updates.
4234 */
4235 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4236 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004237
4238 final long identity = Binder.clearCallingIdentity();
4239 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004240 ImsResolver resolver = PhoneFactory.getImsResolver();
4241 if (resolver == null) {
4242 // may happen if the device does not support IMS.
4243 return null;
4244 }
4245 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004249 }
4250
Brad Ebinger5f64b052017-12-14 14:26:15 -08004251 /**
4252 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004253 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004254 */
4255 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4256 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004257
4258 final long identity = Binder.clearCallingIdentity();
4259 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004260 ImsResolver resolver = PhoneFactory.getImsResolver();
4261 if (resolver == null) {
4262 // may happen if the device does not support IMS.
4263 return null;
4264 }
4265 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004266 } finally {
4267 Binder.restoreCallingIdentity(identity);
4268 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004269 }
4270
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004271 /**
4272 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004273 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004274 */
4275 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4276 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004277
4278 final long identity = Binder.clearCallingIdentity();
4279 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004280 ImsResolver resolver = PhoneFactory.getImsResolver();
4281 if (resolver == null) {
4282 // may happen if the device does not support IMS.
4283 return null;
4284 }
4285 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004289 }
4290
Brad Ebinger884c07b2018-02-15 16:17:40 -08004291 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004292 * Sets the ImsService Package Name that Telephony will bind to.
4293 *
4294 * @param slotId the slot ID that the ImsService should bind for.
4295 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4296 * ImsService is the device default ImsService.
4297 * @param packageName The package name of the application that contains the ImsService to bind
4298 * to.
4299 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4300 * @hide
4301 */
4302 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004303 int[] subIds = SubscriptionManager.getSubId(slotId);
4304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4305 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4306 "setImsService");
4307
Malcolm Chend965c8b2018-02-28 15:00:40 -08004308 final long identity = Binder.clearCallingIdentity();
4309 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004310 ImsResolver resolver = PhoneFactory.getImsResolver();
4311 if (resolver == null) {
4312 // may happen if the device does not support IMS.
4313 return false;
4314 }
4315 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4316 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004320 }
4321
4322 /**
4323 * Return the ImsService configuration.
4324 *
4325 * @param slotId The slot that the ImsService is associated with.
4326 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4327 * the device default.
4328 * @return the package name of the ImsService configuration.
4329 */
4330 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004331 int[] subIds = SubscriptionManager.getSubId(slotId);
4332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4333 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4334 "getImsService");
4335
Malcolm Chend965c8b2018-02-28 15:00:40 -08004336 final long identity = Binder.clearCallingIdentity();
4337 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004338 ImsResolver resolver = PhoneFactory.getImsResolver();
4339 if (resolver == null) {
4340 // may happen if the device does not support IMS.
4341 return "";
4342 }
4343 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004344 } finally {
4345 Binder.restoreCallingIdentity(identity);
4346 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004347 }
4348
Wink Saville36469e72014-06-11 15:17:00 -07004349 public void setImsRegistrationState(boolean registered) {
4350 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004351
4352 final long identity = Binder.clearCallingIdentity();
4353 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004354 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
Wink Saville36469e72014-06-11 15:17:00 -07004358 }
4359
4360 /**
Stuart Scott54788802015-03-30 13:18:01 -07004361 * Set the network selection mode to automatic.
4362 *
4363 */
4364 @Override
4365 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4367 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004368
Pengquan Meng466e2482018-09-21 15:54:48 -07004369 if (!isActiveSubscription(subId)) {
4370 return;
4371 }
4372
Malcolm Chend965c8b2018-02-28 15:00:40 -08004373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4376 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
Stuart Scott54788802015-03-30 13:18:01 -07004380 }
4381
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004382 /**
4383 * Ask the radio to connect to the input network and change selection mode to manual.
4384 *
4385 * @param subId the id of the subscription.
4386 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4387 * the operator to attach to.
4388 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4389 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4390 * normal network selection next time.
4391 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004392 */
4393 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004394 public boolean setNetworkSelectionModeManual(
4395 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4397 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004398
4399 if (!isActiveSubscription(subId)) {
4400 return false;
4401 }
4402
Malcolm Chend965c8b2018-02-28 15:00:40 -08004403 final long identity = Binder.clearCallingIdentity();
4404 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004405 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004406 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004407 if (DBG) {
4408 log("setNetworkSelectionModeManual: subId: " + subId
4409 + " operator: " + operatorInfo);
4410 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004411 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004415 }
4416
4417 /**
4418 * Scans for available networks.
4419 */
4420 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004421 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4423 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004424 LocationAccessPolicy.LocationPermissionResult locationResult =
4425 LocationAccessPolicy.checkLocationPermission(mApp,
4426 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4427 .setCallingPackage(callingPackage)
4428 .setCallingPid(Binder.getCallingPid())
4429 .setCallingUid(Binder.getCallingUid())
4430 .setMethod("getCellNetworkScanResults")
4431 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4432 .build());
4433 switch (locationResult) {
4434 case DENIED_HARD:
4435 throw new SecurityException("Not allowed to access scan results -- location");
4436 case DENIED_SOFT:
4437 return null;
4438 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004439
Pengquan Meng0c05b502018-09-06 09:59:22 -07004440 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004441 try {
4442 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004443 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004444 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004445 } finally {
4446 Binder.restoreCallingIdentity(identity);
4447 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004448 }
4449
4450 /**
yinxub1bed742017-04-17 11:45:04 -07004451 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004452 *
yinxub1bed742017-04-17 11:45:04 -07004453 * @param subId id of the subscription
4454 * @param request contains the radio access networks with bands/channels to scan
4455 * @param messenger callback messenger for scan results or errors
4456 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004457 * @return the id of the requested scan which can be used to stop the scan.
4458 */
4459 @Override
4460 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004461 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4463 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004464 LocationAccessPolicy.LocationPermissionResult locationResult =
4465 LocationAccessPolicy.checkLocationPermission(mApp,
4466 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4467 .setCallingPackage(callingPackage)
4468 .setCallingPid(Binder.getCallingPid())
4469 .setCallingUid(Binder.getCallingUid())
4470 .setMethod("requestNetworkScan")
4471 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4472 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004473 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4474 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4475 if (e != null) {
4476 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4477 throw e;
4478 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004479 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004480 return TelephonyScanManager.INVALID_SCAN_ID;
4481 }
4482 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004483 }
Hall Liubac7d482019-04-25 14:02:26 -07004484 int callingUid = Binder.getCallingUid();
4485 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004486 final long identity = Binder.clearCallingIdentity();
4487 try {
4488 return mNetworkScanRequestTracker.startNetworkScan(
4489 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004490 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
yinxu504e1392017-04-12 16:03:22 -07004494 }
4495
Hall Liub2ac8ef2019-02-28 15:56:23 -08004496 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4497 NetworkScanRequest request) {
4498 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4499 != PERMISSION_GRANTED) {
4500 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4501 + " without location access.");
4502 }
4503
4504 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4505 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004506 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4507 return new SecurityException("Specific channels must not be"
4508 + " scanned without location access.");
4509 }
4510 }
4511 }
4512
Hall Liub2ac8ef2019-02-28 15:56:23 -08004513 return null;
4514 }
4515
yinxu504e1392017-04-12 16:03:22 -07004516 /**
4517 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004518 *
4519 * @param subId id of the subscription
4520 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004521 */
4522 @Override
4523 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4525 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004526
Hall Liubac7d482019-04-25 14:02:26 -07004527 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004528 final long identity = Binder.clearCallingIdentity();
4529 try {
Hall Liubac7d482019-04-25 14:02:26 -07004530 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
yinxu504e1392017-04-12 16:03:22 -07004534 }
4535
4536 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004537 * Get the calculated preferred network type.
4538 * Used for debugging incorrect network type.
4539 *
4540 * @return the preferred network type, defined in RILConstants.java.
4541 */
4542 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004543 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004544 final Phone defaultPhone = getDefaultPhone();
4545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4546 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004547 return RILConstants.PREFERRED_NETWORK_MODE;
4548 }
4549
Malcolm Chend965c8b2018-02-28 15:00:40 -08004550 final long identity = Binder.clearCallingIdentity();
4551 try {
4552 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004553 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004554 } finally {
4555 Binder.restoreCallingIdentity(identity);
4556 }
Junda Liu84d15a22014-07-02 11:21:04 -07004557 }
4558
4559 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004560 * Get the preferred network type.
4561 * Used for device configuration by some CDMA operators.
4562 *
4563 * @return the preferred network type, defined in RILConstants.java.
4564 */
4565 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004566 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004567 TelephonyPermissions
4568 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4569 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004570
4571 final long identity = Binder.clearCallingIdentity();
4572 try {
4573 if (DBG) log("getPreferredNetworkType");
4574 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4575 int networkType = (result != null ? result[0] : -1);
4576 if (DBG) log("getPreferredNetworkType: " + networkType);
4577 return networkType;
4578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004581 }
4582
4583 /**
4584 * Set the preferred network type.
4585 * Used for device configuration by some CDMA operators.
4586 *
4587 * @param networkType the preferred network type, defined in RILConstants.java.
4588 * @return true on success; false on any failure.
4589 */
4590 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004591 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4593 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004594
4595 final long identity = Binder.clearCallingIdentity();
4596 try {
4597 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4598 Boolean success = (Boolean) sendRequest(
4599 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4600 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4601 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004602 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004603 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4604 }
4605 return success;
4606 } finally {
4607 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004608 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004609 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004610
4611 /**
Miaoa84611c2019-03-15 09:21:10 +08004612 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004613 *
Miaoa84611c2019-03-15 09:21:10 +08004614 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004615 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004616 * @hide
4617 */
4618 @Override
Miaoa84611c2019-03-15 09:21:10 +08004619 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004620 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004621 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004622 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004623 try {
Miaoa84611c2019-03-15 09:21:10 +08004624 if (phone != null) {
4625 return phone.hasMatchedTetherApnSetting();
4626 } else {
4627 return false;
4628 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004629 } finally {
4630 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004631 }
Junda Liu475951f2014-11-07 16:45:03 -08004632 }
4633
4634 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004635 * Set mobile data enabled
4636 * Used by the user through settings etc to turn on/off mobile data
4637 *
4638 * @param enable {@code true} turn turn data on, else {@code false}
4639 */
4640 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004641 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4643 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004644
4645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 int phoneId = mSubscriptionController.getPhoneId(subId);
4648 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4649 Phone phone = PhoneFactory.getPhone(phoneId);
4650 if (phone != null) {
4651 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004652 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004653 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004654 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004655 }
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004658 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004659 }
4660
4661 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004662 * Get the user enabled state of Mobile Data.
4663 *
4664 * TODO: remove and use isUserDataEnabled.
4665 * This can't be removed now because some vendor codes
4666 * calls through ITelephony directly while they should
4667 * use TelephonyManager.
4668 *
4669 * @return true on enabled
4670 */
4671 @Override
4672 public boolean getDataEnabled(int subId) {
4673 return isUserDataEnabled(subId);
4674 }
4675
4676 /**
4677 * Get whether mobile data is enabled per user setting.
4678 *
4679 * There are other factors deciding whether mobile data is actually enabled, but they are
4680 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004681 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004682 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004683 *
4684 * @return {@code true} if data is enabled else {@code false}
4685 */
4686 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004687 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004688 try {
4689 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4690 null);
4691 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4693 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004694 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004695
4696 final long identity = Binder.clearCallingIdentity();
4697 try {
4698 int phoneId = mSubscriptionController.getPhoneId(subId);
4699 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4700 Phone phone = PhoneFactory.getPhone(phoneId);
4701 if (phone != null) {
4702 boolean retVal = phone.isUserDataEnabled();
4703 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4704 return retVal;
4705 } else {
4706 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4707 return false;
4708 }
4709 } finally {
4710 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004711 }
4712 }
4713
4714 /**
4715 * Get whether mobile data is enabled.
4716 *
4717 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4718 * whether mobile data is actually enabled.
4719 *
4720 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4721 *
4722 * @return {@code true} if data is enabled else {@code false}
4723 */
4724 @Override
4725 public boolean isDataEnabled(int subId) {
4726 try {
4727 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4728 null);
4729 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4731 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004732 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004733
4734 final long identity = Binder.clearCallingIdentity();
4735 try {
4736 int phoneId = mSubscriptionController.getPhoneId(subId);
4737 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4738 Phone phone = PhoneFactory.getPhone(phoneId);
4739 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004740 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004741 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4742 return retVal;
4743 } else {
4744 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4745 return false;
4746 }
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004749 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004750 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004751
4752 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004753 public int getCarrierPrivilegeStatus(int subId) {
4754 final Phone phone = getPhone(subId);
4755 if (phone == null) {
4756 loge("getCarrierPrivilegeStatus: Invalid subId");
4757 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4758 }
4759 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004760 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004761 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004762 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4763 }
4764 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004765 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004766 }
Junda Liu29340342014-07-10 15:23:27 -07004767
4768 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004769 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4770 final Phone phone = getPhone(subId);
4771 if (phone == null) {
4772 loge("getCarrierPrivilegeStatus: Invalid subId");
4773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4774 }
4775 UiccProfile profile =
4776 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4777 if (profile == null) {
4778 loge("getCarrierPrivilegeStatus: No UICC");
4779 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4780 }
4781 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4782 }
4783
4784 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004785 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004786 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004787 if (TextUtils.isEmpty(pkgName))
4788 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004789 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004790 if (card == null) {
4791 loge("checkCarrierPrivilegesForPackage: No UICC");
4792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4793 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004794 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4795 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004796 }
4797
4798 @Override
4799 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004800 if (TextUtils.isEmpty(pkgName))
4801 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004802 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4803 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4804 UiccCard card = UiccController.getInstance().getUiccCard(i);
4805 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004806 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004807 continue;
4808 }
4809
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004810 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004811 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4812 break;
4813 }
4814 }
4815
4816 return result;
Junda Liu29340342014-07-10 15:23:27 -07004817 }
Derek Tan89e89d42014-07-08 17:00:10 -07004818
4819 @Override
Junda Liue64de782015-04-16 17:19:16 -07004820 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4821 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4822 loge("phoneId " + phoneId + " is not valid.");
4823 return null;
4824 }
4825 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004826 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004827 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004828 return null ;
4829 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004830 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004831 }
4832
Amith Yamasani6e118872016-02-19 12:53:51 -08004833 @Override
4834 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004835 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004836 List<String> privilegedPackages = new ArrayList<>();
4837 List<PackageInfo> packages = null;
4838 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4839 UiccCard card = UiccController.getInstance().getUiccCard(i);
4840 if (card == null) {
4841 // No UICC in that slot.
4842 continue;
4843 }
4844 if (card.hasCarrierPrivilegeRules()) {
4845 if (packages == null) {
4846 // Only check packages in user 0 for now
4847 packages = pm.getInstalledPackagesAsUser(
4848 PackageManager.MATCH_DISABLED_COMPONENTS
4849 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4850 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4851 }
4852 for (int p = packages.size() - 1; p >= 0; p--) {
4853 PackageInfo pkgInfo = packages.get(p);
4854 if (pkgInfo != null && pkgInfo.packageName != null
4855 && card.getCarrierPrivilegeStatus(pkgInfo)
4856 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4857 privilegedPackages.add(pkgInfo.packageName);
4858 }
4859 }
4860 }
4861 }
4862 return privilegedPackages;
4863 }
4864
Wink Savilleb564aae2014-10-23 10:18:09 -07004865 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004866 final Phone phone = getPhone(subId);
4867 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004868 if (card == null) {
4869 loge("getIccId: No UICC");
4870 return null;
4871 }
4872 String iccId = card.getIccId();
4873 if (TextUtils.isEmpty(iccId)) {
4874 loge("getIccId: ICC ID is null or empty.");
4875 return null;
4876 }
4877 return iccId;
4878 }
4879
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004880 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004881 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4882 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004883 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4884 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004885
Malcolm Chend965c8b2018-02-28 15:00:40 -08004886 final long identity = Binder.clearCallingIdentity();
4887 try {
4888 final String iccId = getIccId(subId);
4889 final Phone phone = getPhone(subId);
4890 if (phone == null) {
4891 return false;
4892 }
4893 final String subscriberId = phone.getSubscriberId();
4894
4895 if (DBG_MERGE) {
4896 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4897 + subscriberId + " to " + number);
4898 }
4899
4900 if (TextUtils.isEmpty(iccId)) {
4901 return false;
4902 }
4903
4904 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4905
4906 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4907 if (alphaTag == null) {
4908 editor.remove(alphaTagPrefKey);
4909 } else {
4910 editor.putString(alphaTagPrefKey, alphaTag);
4911 }
4912
4913 // Record both the line number and IMSI for this ICCID, since we need to
4914 // track all merged IMSIs based on line number
4915 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4916 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4917 if (number == null) {
4918 editor.remove(numberPrefKey);
4919 editor.remove(subscriberPrefKey);
4920 } else {
4921 editor.putString(numberPrefKey, number);
4922 editor.putString(subscriberPrefKey, subscriberId);
4923 }
4924
4925 editor.commit();
4926 return true;
4927 } finally {
4928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004929 }
Derek Tan7226c842014-07-02 17:42:23 -07004930 }
4931
4932 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004933 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004934 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004936 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004937 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004938 return null;
4939 }
Derek Tan97ebb422014-09-05 16:55:38 -07004940
Malcolm Chend965c8b2018-02-28 15:00:40 -08004941 final long identity = Binder.clearCallingIdentity();
4942 try {
4943 String iccId = getIccId(subId);
4944 if (iccId != null) {
4945 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4946 if (DBG_MERGE) {
4947 log("getLine1NumberForDisplay returning "
4948 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4949 }
4950 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004951 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004952 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4953 return null;
4954 } finally {
4955 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004956 }
Derek Tan7226c842014-07-02 17:42:23 -07004957 }
4958
4959 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004960 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004962 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004963 return null;
4964 }
Derek Tan97ebb422014-09-05 16:55:38 -07004965
Malcolm Chend965c8b2018-02-28 15:00:40 -08004966 final long identity = Binder.clearCallingIdentity();
4967 try {
4968 String iccId = getIccId(subId);
4969 if (iccId != null) {
4970 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4971 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4972 }
4973 return null;
4974 } finally {
4975 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004976 }
Derek Tan7226c842014-07-02 17:42:23 -07004977 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004978
4979 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004980 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004981 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4982 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004984 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4985 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004986 return null;
4987 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004988
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004989 final long identity = Binder.clearCallingIdentity();
4990 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004991 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004992 final TelephonyManager tele = TelephonyManager.from(context);
4993 final SubscriptionManager sub = SubscriptionManager.from(context);
4994
4995 // Figure out what subscribers are currently active
4996 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4997 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4998 // the process, where TelephonyManager was instantiated.
4999 // Otherwise AppOps check will fail.
5000
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005001 final int[] subIds = sub.getActiveSubscriptionIdList();
5002 for (int subId : subIds) {
5003 activeSubscriberIds.add(tele.getSubscriberId(subId));
5004 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005005
5006 // First pass, find a number override for an active subscriber
5007 String mergeNumber = null;
5008 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5009 for (String key : prefs.keySet()) {
5010 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5011 final String subscriberId = (String) prefs.get(key);
5012 if (activeSubscriberIds.contains(subscriberId)) {
5013 final String iccId = key.substring(
5014 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5015 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5016 mergeNumber = (String) prefs.get(numberKey);
5017 if (DBG_MERGE) {
5018 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5019 + " for active subscriber " + subscriberId);
5020 }
5021 if (!TextUtils.isEmpty(mergeNumber)) {
5022 break;
5023 }
5024 }
5025 }
5026 }
5027
5028 // Shortcut when no active merged subscribers
5029 if (TextUtils.isEmpty(mergeNumber)) {
5030 return null;
5031 }
5032
5033 // Second pass, find all subscribers under that line override
5034 final ArraySet<String> result = new ArraySet<>();
5035 for (String key : prefs.keySet()) {
5036 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5037 final String number = (String) prefs.get(key);
5038 if (mergeNumber.equals(number)) {
5039 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5040 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5041 final String subscriberId = (String) prefs.get(subscriberKey);
5042 if (!TextUtils.isEmpty(subscriberId)) {
5043 result.add(subscriberId);
5044 }
5045 }
5046 }
5047 }
5048
5049 final String[] resultArray = result.toArray(new String[result.size()]);
5050 Arrays.sort(resultArray);
5051 if (DBG_MERGE) {
5052 Slog.d(LOG_TAG,
5053 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5054 }
5055 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005056 } finally {
5057 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005058 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005059 }
5060
5061 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005062 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005063 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5064 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005065
5066 final long identity = Binder.clearCallingIdentity();
5067 try {
5068 final Phone phone = getPhone(subId);
5069 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005073 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005074
5075 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005076 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005077 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5078 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005079 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005080
5081 final long identity = Binder.clearCallingIdentity();
5082 try {
5083 final Phone phone = getPhone(subId);
5084 if (phone == null) {
5085 return false;
5086 }
5087 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5088 cdmaNonRoamingList);
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005091 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005092 }
5093
5094 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005095 @Deprecated
5096 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5097 enforceModifyPermission();
5098
5099 int returnValue = 0;
5100 try {
vagdevie435a3e2018-08-15 16:01:53 -07005101 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005102 if(result.exception == null) {
5103 if (result.result != null) {
5104 byte[] responseData = (byte[])(result.result);
5105 if(responseData.length > oemResp.length) {
5106 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5107 responseData.length + "bytes. Buffer Size is " +
5108 oemResp.length + "bytes.");
5109 }
5110 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5111 returnValue = responseData.length;
5112 }
5113 } else {
5114 CommandException ex = (CommandException) result.exception;
5115 returnValue = ex.getCommandError().ordinal();
5116 if(returnValue > 0) returnValue *= -1;
5117 }
5118 } catch (RuntimeException e) {
5119 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5120 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5121 if(returnValue > 0) returnValue *= -1;
5122 }
5123
5124 return returnValue;
5125 }
5126
5127 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005128 public void setRadioCapability(RadioAccessFamily[] rafs) {
5129 try {
5130 ProxyController.getInstance().setRadioCapability(rafs);
5131 } catch (RuntimeException e) {
5132 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5133 }
5134 }
5135
5136 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005137 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005138 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005139 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005140 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005141 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005142 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
chen xufeeed752018-10-26 14:17:57 -07005145 TelephonyPermissions
5146 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5147 mApp, phone.getSubId(), "getRadioAccessFamily");
5148 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005149 } finally {
5150 Binder.restoreCallingIdentity(identity);
5151 }
chen xufeeed752018-10-26 14:17:57 -07005152 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005153 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005154
5155 @Override
5156 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005157 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005158 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005159
5160 final long identity = Binder.clearCallingIdentity();
5161 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005162 ImsManager.getInstance(defaultPhone.getContext(),
5163 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005164 } finally {
5165 Binder.restoreCallingIdentity(identity);
5166 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005167 }
5168
5169 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005170 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005171 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005173 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005174 return false;
5175 }
Svet Ganovb320e182015-04-16 12:30:10 -07005176
Malcolm Chend965c8b2018-02-28 15:00:40 -08005177 final long identity = Binder.clearCallingIdentity();
5178 try {
5179 // Check the user preference and the system-level IMS setting. Even if the user has
5180 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5181 // In the long run, we may instead need to check if there exists a connection service
5182 // which can support video calling.
5183 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005184 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005185 return imsManager.isVtEnabledByPlatform()
5186 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5187 && imsManager.isVtEnabledByUser();
5188 } finally {
5189 Binder.restoreCallingIdentity(identity);
5190 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005191 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005192
Andrew Leea1239f22015-03-02 17:44:07 -08005193 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005194 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5196 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5197 return false;
5198 }
5199
5200 final long identity = Binder.clearCallingIdentity();
5201 try {
5202 CarrierConfigManager configManager =
5203 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005204 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005205 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
5208 }
Andrew Leea1239f22015-03-02 17:44:07 -08005209 }
5210
5211 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005212 public boolean isWorldPhone(int subId, String callingPackage) {
5213 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5214 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5215 return false;
5216 }
5217
5218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 CarrierConfigManager configManager =
5221 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005222 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005223 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5224 } finally {
5225 Binder.restoreCallingIdentity(identity);
5226 }
Andrew Leea1239f22015-03-02 17:44:07 -08005227 }
5228
Andrew Lee9431b832015-03-09 18:46:45 -07005229 @Override
5230 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005231 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005232 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005233 }
5234
5235 @Override
5236 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005237 final long identity = Binder.clearCallingIdentity();
5238 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005239 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
Andrew Lee9431b832015-03-09 18:46:45 -07005243 }
5244
Hall Liuf6668912018-10-31 17:05:23 -07005245 /**
5246 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5247 * support for the feature and device firmware support.
5248 *
5249 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5250 */
5251 @Override
5252 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005253 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005254 final Phone phone = getPhone(subscriptionId);
5255 if (phone == null) {
5256 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5257 return false;
5258 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005259 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005260 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005261 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5262 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005263 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005264 return isCarrierSupported && isDeviceSupported;
5265 } finally {
5266 Binder.restoreCallingIdentity(identity);
5267 }
Hall Liu98187582018-01-22 19:15:32 -08005268 }
5269
Hall Liuf6668912018-10-31 17:05:23 -07005270 /**
5271 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5272 * both also support RTT.
5273 */
5274 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005275 final long identity = Binder.clearCallingIdentity();
5276 try {
Hall Liuf6668912018-10-31 17:05:23 -07005277 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005278 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005279 } finally {
5280 Binder.restoreCallingIdentity(identity);
5281 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005282 }
5283
Sanket Padawe7310cc72015-01-14 09:53:20 -08005284 /**
5285 * Returns the unique device ID of phone, for example, the IMEI for
5286 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5287 *
5288 * <p>Requires Permission:
5289 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5290 */
5291 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005292 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005293 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005294 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005295 return null;
5296 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005297 int subId = phone.getSubId();
5298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5299 mApp, subId, callingPackage, "getDeviceId")) {
5300 return null;
5301 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005302
5303 final long identity = Binder.clearCallingIdentity();
5304 try {
5305 return phone.getDeviceId();
5306 } finally {
5307 Binder.restoreCallingIdentity(identity);
5308 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005309 }
5310
Ping Sunc67b7c22016-03-02 19:16:45 +08005311 /**
5312 * {@hide}
5313 * Returns the IMS Registration Status on a particular subid
5314 *
5315 * @param subId
5316 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005317 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005318 Phone phone = getPhone(subId);
5319 if (phone != null) {
5320 return phone.isImsRegistered();
5321 } else {
5322 return false;
5323 }
5324 }
5325
Santos Cordon7a1885b2015-02-03 11:15:19 -08005326 @Override
5327 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005328 final long identity = Binder.clearCallingIdentity();
5329 try {
5330 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005334 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005335
Tyler Gunn327a9722019-04-03 15:28:53 -07005336 @Override
5337 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 Phone phone = getPhone(subscriptionId);
5341 if (phone == null) {
5342 return null;
5343 }
5344 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
5348 }
5349
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005350 /**
5351 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005352 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005353 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005354 final long identity = Binder.clearCallingIdentity();
5355 try {
5356 Phone phone = getPhone(subId);
5357 if (phone != null) {
5358 return phone.isWifiCallingEnabled();
5359 } else {
5360 return false;
5361 }
5362 } finally {
5363 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005364 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005365 }
5366
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005367 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005368 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005369 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005370 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005371 final long identity = Binder.clearCallingIdentity();
5372 try {
5373 Phone phone = getPhone(subId);
5374 if (phone != null) {
5375 return phone.isVideoEnabled();
5376 } else {
5377 return false;
5378 }
5379 } finally {
5380 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005381 }
5382 }
5383
5384 /**
5385 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5386 * defined in {@link ImsRegistrationImplBase}.
5387 */
5388 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005389 final long identity = Binder.clearCallingIdentity();
5390 try {
5391 Phone phone = getPhone(subId);
5392 if (phone != null) {
5393 return phone.getImsRegistrationTech();
5394 } else {
5395 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5396 }
5397 } finally {
5398 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005399 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005400 }
5401
Stuart Scott8eef64f2015-04-08 15:13:54 -07005402 @Override
5403 public void factoryReset(int subId) {
5404 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005405 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5406 return;
5407 }
5408
Svet Ganovcc087f82015-05-12 20:35:54 -07005409 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005410
Svet Ganovcc087f82015-05-12 20:35:54 -07005411 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005412 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5413 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005414 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005415 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005416 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005417 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5418 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005419 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005420 // There has been issues when Sms raw table somehow stores orphan
5421 // fragments. They lead to garbled message when new fragments come
5422 // in and combined with those stale ones. In case this happens again,
5423 // user can reset all network settings which will clean up this table.
5424 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005425 } finally {
5426 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005427 }
5428 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005429
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005430 private void cleanUpSmsRawTable(Context context) {
5431 ContentResolver resolver = context.getContentResolver();
5432 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5433 resolver.delete(uri, null, null);
5434 }
5435
Narayan Kamath1c496c22015-04-16 14:40:19 +01005436 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005437 public String getSimLocaleForSubscriber(int subId) {
5438 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5439 final Phone phone = getPhone(subId);
5440 if (phone == null) {
5441 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005442 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005443 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005444 final long identity = Binder.clearCallingIdentity();
5445 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005446 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5447 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005448 // Try and fetch the locale from the carrier properties or from the SIM language
5449 // preferences (EF-PL and EF-LI)...
5450 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005451 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005452 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5453 if (localeFromDefaultSim != null) {
5454 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5455 if (DBG) log("Using locale from subId: " + subId + " locale: "
5456 + localeFromDefaultSim);
5457 return localeFromDefaultSim.toLanguageTag();
5458 } else {
5459 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005460 }
5461 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005462
Malcolm Chend965c8b2018-02-28 15:00:40 -08005463 // The SIM language preferences only store a language (e.g. fr = French), not an
5464 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5465 // the SIM and carrier preferences does not include a country we add the country
5466 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005467 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005468 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005469 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005470 return mccLocale.toLanguageTag();
5471 }
5472
5473 if (DBG) log("No locale found - returning null");
5474 return null;
5475 } finally {
5476 Binder.restoreCallingIdentity(identity);
5477 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005478 }
5479
5480 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005481 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005482 }
5483
Malcolm Chend965c8b2018-02-28 15:00:40 -08005484 /**
5485 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5486 */
5487 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005488 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005489 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005490
Chenjie Yu1ba97252018-01-11 18:16:20 -08005491 private final ModemActivityInfo mLastModemActivityInfo =
5492 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5493
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005494 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005495 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5496 * representing the state of the modem.
5497 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005498 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5499 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005500 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005501 */
5502 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005503 public void requestModemActivityInfo(ResultReceiver result) {
5504 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005505 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 ModemActivityInfo ret = null;
5510 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005511 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5512 CMD_GET_MODEM_ACTIVITY_INFO,
5513 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005514 if (isModemActivityInfoValid(info)) {
5515 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5516 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5517 mergedTxTimeMs[i] =
5518 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5519 }
5520 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5521 mLastModemActivityInfo.setSleepTimeMillis(
5522 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5523 mLastModemActivityInfo.setIdleTimeMillis(
5524 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5525 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5526 mLastModemActivityInfo.setRxTimeMillis(
5527 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5528 mLastModemActivityInfo.setEnergyUsed(
5529 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005530 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005531 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5532 mLastModemActivityInfo.getSleepTimeMillis(),
5533 mLastModemActivityInfo.getIdleTimeMillis(),
5534 mLastModemActivityInfo.getTxTimeMillis(),
5535 mLastModemActivityInfo.getRxTimeMillis(),
5536 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005537 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005538 Bundle bundle = new Bundle();
5539 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5540 result.send(0, bundle);
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005543 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005544 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005545
Siddharth Rayf5d29552018-06-17 15:02:38 -07005546 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5547 // less than total activity duration.
5548 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5549 if (info == null) {
5550 return false;
5551 }
5552 int activityDurationMs =
5553 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5554 int totalTxTimeMs = 0;
5555 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5556 totalTxTimeMs += info.getTxTimeMillis()[i];
5557 }
5558 return (info.isValid()
5559 && (info.getSleepTimeMillis() <= activityDurationMs)
5560 && (info.getIdleTimeMillis() <= activityDurationMs)
5561 && (info.getRxTimeMillis() <= activityDurationMs)
5562 && (totalTxTimeMs <= activityDurationMs));
5563 }
5564
Jack Yu85bd38a2015-11-09 11:34:32 -08005565 /**
5566 * {@hide}
5567 * Returns the service state information on specified subscription.
5568 */
5569 @Override
5570 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005572 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005573 return null;
5574 }
5575
Hall Liuf19c44f2018-11-27 14:38:17 -08005576 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5577 LocationAccessPolicy.checkLocationPermission(mApp,
5578 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5579 .setCallingPackage(callingPackage)
5580 .setCallingPid(Binder.getCallingPid())
5581 .setCallingUid(Binder.getCallingUid())
5582 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005583 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005584 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5585 .build());
5586
5587 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5588 LocationAccessPolicy.checkLocationPermission(mApp,
5589 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5590 .setCallingPackage(callingPackage)
5591 .setCallingPid(Binder.getCallingPid())
5592 .setCallingUid(Binder.getCallingUid())
5593 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005594 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005595 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5596 .build());
5597 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5598 boolean hasFinePermission =
5599 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5600 boolean hasCoarsePermission =
5601 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5602
Malcolm Chend965c8b2018-02-28 15:00:40 -08005603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 final Phone phone = getPhone(subId);
5606 if (phone == null) {
5607 return null;
5608 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005609
Hall Liuf19c44f2018-11-27 14:38:17 -08005610 ServiceState ss = phone.getServiceState();
5611
5612 // Scrub out the location info in ServiceState depending on what level of access
5613 // the caller has.
5614 if (hasFinePermission) return ss;
5615 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5616 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005620 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005621
5622 /**
5623 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5624 *
5625 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5626 * voicemail ringtone.
5627 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5628 * PhoneAccount.
5629 */
5630 @Override
5631 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005632 final long identity = Binder.clearCallingIdentity();
5633 try {
5634 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5635 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005636 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005637 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005638
Malcolm Chend965c8b2018-02-28 15:00:40 -08005639 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005643 }
5644
5645 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005646 * Sets the per-account voicemail ringtone.
5647 *
5648 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5649 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5650 *
5651 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5652 * voicemail ringtone.
5653 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5654 * PhoneAccount.
5655 */
5656 @Override
5657 public void setVoicemailRingtoneUri(String callingPackage,
5658 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005659 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005660 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5661 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005662 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5664 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5665 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005666 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005667
5668 final long identity = Binder.clearCallingIdentity();
5669 try {
5670 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5671 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005672 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005673 }
5674 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005677 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005678 }
5679
5680 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005681 * Returns whether vibration is set for voicemail notification in Phone settings.
5682 *
5683 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5684 * voicemail vibration setting.
5685 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5686 */
5687 @Override
5688 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5692 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005693 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005694 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005695
Malcolm Chend965c8b2018-02-28 15:00:40 -08005696 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005700 }
5701
Youhan Wange64578a2016-05-02 15:32:42 -07005702 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005703 * Sets the per-account voicemail vibration.
5704 *
5705 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5706 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5707 *
5708 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5709 * voicemail vibration setting.
5710 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5711 * specific PhoneAccount.
5712 */
5713 @Override
5714 public void setVoicemailVibrationEnabled(String callingPackage,
5715 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005716 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005717 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5718 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005719 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5721 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5722 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005723 }
5724
Malcolm Chend965c8b2018-02-28 15:00:40 -08005725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5728 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005729 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005730 }
5731 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005734 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005735 }
5736
5737 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005738 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5739 *
5740 * @throws SecurityException if the caller does not have the required permission
5741 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005742 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005743 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005744 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005745 }
5746
5747 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005748 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5749 * permission.
5750 *
5751 * @throws SecurityException if the caller does not have the required permission
5752 */
5753 private void enforceSendSmsPermission() {
5754 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5755 }
5756
5757 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005758 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005759 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005760 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005761 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005762 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005763 final long identity = Binder.clearCallingIdentity();
5764 try {
5765 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005766 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005767 if (componentName == null) {
5768 throw new SecurityException(
5769 "Caller not current active visual voicemail package[null]");
5770 }
5771 String vvmPackage = componentName.getPackageName();
5772 if (!callingPackage.equals(vvmPackage)) {
5773 throw new SecurityException("Caller not current active visual voicemail package["
5774 + vvmPackage + "]");
5775 }
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005778 }
5779 }
5780
5781 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005782 * Return the application ID for the app type.
5783 *
5784 * @param subId the subscription ID that this request applies to.
5785 * @param appType the uicc app type.
5786 * @return Application ID for specificied app type, or null if no uicc.
5787 */
5788 @Override
5789 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005790 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005791 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005792
5793 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005794 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005795 if (phone == null) {
5796 return null;
5797 }
5798 String aid = null;
5799 try {
5800 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5801 .getApplicationByType(appType).getAid();
5802 } catch (Exception e) {
5803 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5804 }
5805 return aid;
5806 } finally {
5807 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005808 }
Youhan Wange64578a2016-05-02 15:32:42 -07005809 }
5810
Youhan Wang4001d252016-05-11 10:29:41 -07005811 /**
5812 * Return the Electronic Serial Number.
5813 *
5814 * @param subId the subscription ID that this request applies to.
5815 * @return ESN or null if error.
5816 */
5817 @Override
5818 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005819 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005820 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005821
5822 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005823 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005824 if (phone == null) {
5825 return null;
5826 }
5827 String esn = null;
5828 try {
5829 esn = phone.getEsn();
5830 } catch (Exception e) {
5831 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5832 }
5833 return esn;
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005836 }
Youhan Wang4001d252016-05-11 10:29:41 -07005837 }
5838
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005839 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005840 * Return the Preferred Roaming List Version.
5841 *
5842 * @param subId the subscription ID that this request applies to.
5843 * @return PRLVersion or null if error.
5844 */
5845 @Override
5846 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005847 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005848 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005849
5850 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005851 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005852 if (phone == null) {
5853 return null;
5854 }
5855 String cdmaPrlVersion = null;
5856 try {
5857 cdmaPrlVersion = phone.getCdmaPrlVersion();
5858 } catch (Exception e) {
5859 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5860 }
5861 return cdmaPrlVersion;
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005864 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005865 }
5866
5867 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005868 * Get snapshot of Telephony histograms
5869 * @return List of Telephony histograms
5870 * @hide
5871 */
5872 @Override
5873 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5875 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005876
5877 final long identity = Binder.clearCallingIdentity();
5878 try {
5879 return RIL.getTelephonyRILTimingHistograms();
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005883 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005884
5885 /**
5886 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005887 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5888 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005889 * Require system privileges. In the future we may add this to carrier APIs.
5890 *
Michele Berionne0963c862018-11-27 18:57:59 -08005891 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005892 */
5893 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005894 @TelephonyManager.SetCarrierRestrictionResult
5895 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005896 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005897 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005898
Michele Berionne0963c862018-11-27 18:57:59 -08005899 if (carrierRestrictionRules == null) {
5900 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005901 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005902
Malcolm Chend965c8b2018-02-28 15:00:40 -08005903 final long identity = Binder.clearCallingIdentity();
5904 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005905 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005906 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005910 }
5911
5912 /**
5913 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005914 * Get the allowed carrier list and the excluded carrier list, including the priority between
5915 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005916 * Require system privileges. In the future we may add this to carrier APIs.
5917 *
Michele Berionne0963c862018-11-27 18:57:59 -08005918 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005919 */
5920 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005921 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005922 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005924
5925 final long identity = Binder.clearCallingIdentity();
5926 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005927 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5928 if (response instanceof CarrierRestrictionRules) {
5929 return (CarrierRestrictionRules) response;
5930 }
5931 // Response is an Exception of some kind,
5932 // which is signalled to the user as a NULL retval
5933 return null;
5934 } catch (Exception e) {
5935 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5936 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005940 }
5941
fionaxu59545b42016-05-25 15:53:37 -07005942 /**
5943 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5944 * @param subId the subscription ID that this action applies to.
5945 * @param enabled control enable or disable metered apns.
5946 * {@hide}
5947 */
5948 @Override
5949 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5950 enforceModifyPermission();
5951 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005952
5953 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005954 if (phone == null) {
5955 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5956 return;
5957 }
5958 try {
5959 phone.carrierActionSetMeteredApnsEnabled(enabled);
5960 } catch (Exception e) {
5961 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005962 } finally {
5963 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005964 }
5965 }
5966
5967 /**
5968 * Action set from carrier signalling broadcast receivers to enable/disable radio
5969 * @param subId the subscription ID that this action applies to.
5970 * @param enabled control enable or disable radio.
5971 * {@hide}
5972 */
5973 @Override
5974 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5975 enforceModifyPermission();
5976 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005977
5978 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005979 if (phone == null) {
5980 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5981 return;
5982 }
5983 try {
5984 phone.carrierActionSetRadioEnabled(enabled);
5985 } catch (Exception e) {
5986 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005987 } finally {
5988 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005989 }
5990 }
5991
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005992 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005993 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5994 * network status based on which carrier apps could apply actions accordingly,
5995 * enable/disable default url handler for example.
5996 *
5997 * @param subId the subscription ID that this action applies to.
5998 * @param report control start/stop reporting the default network status.
5999 * {@hide}
6000 */
6001 @Override
6002 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6003 enforceModifyPermission();
6004 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006005
6006 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006007 if (phone == null) {
6008 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6009 return;
6010 }
6011 try {
6012 phone.carrierActionReportDefaultNetworkStatus(report);
6013 } catch (Exception e) {
6014 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006015 } finally {
6016 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006017 }
6018 }
6019
6020 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006021 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6022 * bug report is being generated.
6023 */
6024 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006025 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006026 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6027 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006028 writer.println("Permission Denial: can't dump Phone from pid="
6029 + Binder.getCallingPid()
6030 + ", uid=" + Binder.getCallingUid()
6031 + "without permission "
6032 + android.Manifest.permission.DUMP);
6033 return;
6034 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006035 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006036 }
Jack Yueb89b242016-06-22 13:27:47 -07006037
Brad Ebingerdac2f002018-04-03 15:17:52 -07006038 @Override
6039 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6040 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6041 throws RemoteException {
6042 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6043 }
6044
Jack Yueb89b242016-06-22 13:27:47 -07006045 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006046 * Get aggregated video call data usage since boot.
6047 *
6048 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6049 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006050 * {@hide}
6051 */
6052 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006053 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006054 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6055 null);
6056
Malcolm Chend965c8b2018-02-28 15:00:40 -08006057 final long identity = Binder.clearCallingIdentity();
6058 try {
6059 // NetworkStatsService keeps tracking the active network interface and identity. It
6060 // records the delta with the corresponding network identity.
6061 // We just return the total video call data usage snapshot since boot.
6062 Phone phone = getPhone(subId);
6063 if (phone != null) {
6064 return phone.getVtDataUsage(perUidStats);
6065 }
6066 return null;
6067 } finally {
6068 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006069 }
Jack Yueb89b242016-06-22 13:27:47 -07006070 }
Jack Yu75ab2952016-07-08 14:29:33 -07006071
6072 /**
6073 * Policy control of data connection. Usually used when data limit is passed.
6074 * @param enabled True if enabling the data, otherwise disabling.
6075 * @param subId Subscription index
6076 * {@hide}
6077 */
6078 @Override
6079 public void setPolicyDataEnabled(boolean enabled, int subId) {
6080 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006081
6082 final long identity = Binder.clearCallingIdentity();
6083 try {
6084 Phone phone = getPhone(subId);
6085 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006086 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006087 }
6088 } finally {
6089 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006090 }
6091 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006092
6093 /**
6094 * Get Client request stats
6095 * @return List of Client Request Stats
6096 * @hide
6097 */
6098 @Override
6099 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006101 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006102 return null;
6103 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006104 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006105
Malcolm Chend965c8b2018-02-28 15:00:40 -08006106 final long identity = Binder.clearCallingIdentity();
6107 try {
6108 if (phone != null) {
6109 return phone.getClientRequestStats();
6110 }
6111
6112 return null;
6113 } finally {
6114 Binder.restoreCallingIdentity(identity);
6115 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006116 }
6117
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006118 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006119 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006120 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006121 }
Jack Yueb4124c2017-02-16 15:32:43 -08006122
6123 /**
Grace Chen70990072017-03-24 17:21:30 -07006124 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006125 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006126 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006127 * @param state State of SIM (power down, power up, pass through)
6128 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6129 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6130 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006131 *
6132 **/
6133 @Override
Grace Chen70990072017-03-24 17:21:30 -07006134 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006135 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006136 Phone phone = PhoneFactory.getPhone(slotIndex);
6137
vagdevie435a3e2018-08-15 16:01:53 -07006138 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6139
Malcolm Chend965c8b2018-02-28 15:00:40 -08006140 final long identity = Binder.clearCallingIdentity();
6141 try {
6142 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006143 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006144 }
6145 } finally {
6146 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006147 }
6148 }
Shuo Qiandd210312017-04-12 22:11:33 +00006149
Tyler Gunn65d45c22017-06-05 11:22:26 -07006150 private boolean isUssdApiAllowed(int subId) {
6151 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006152 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006153 if (configManager == null) {
6154 return false;
6155 }
6156 PersistableBundle pb = configManager.getConfigForSubId(subId);
6157 if (pb == null) {
6158 return false;
6159 }
6160 return pb.getBoolean(
6161 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6162 }
6163
Shuo Qiandd210312017-04-12 22:11:33 +00006164 /**
6165 * Check if phone is in emergency callback mode
6166 * @return true if phone is in emergency callback mode
6167 * @param subId sub id
6168 */
goneil9c5f4872017-12-05 14:07:56 -08006169 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006170 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006171 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006172 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006173
6174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 if (phone != null) {
6177 return phone.isInEcm();
6178 } else {
6179 return false;
6180 }
6181 } finally {
6182 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006183 }
6184 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006185
6186 /**
6187 * Get the current signal strength information for the given subscription.
6188 * Because this information is not updated when the device is in a low power state
6189 * it should not be relied-upon to be current.
6190 * @param subId Subscription index
6191 * @return the most recent cached signal strength info from the modem
6192 */
6193 @Override
6194 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006195 final long identity = Binder.clearCallingIdentity();
6196 try {
6197 Phone p = getPhone(subId);
6198 if (p == null) {
6199 return null;
6200 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006201
Malcolm Chend965c8b2018-02-28 15:00:40 -08006202 return p.getSignalStrength();
6203 } finally {
6204 Binder.restoreCallingIdentity(identity);
6205 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006206 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006207
Pengquan Meng9140aec2018-08-22 14:49:57 -07006208 /**
chen xu907e5a22018-10-11 13:21:04 -07006209 * Get the current modem radio state for the given slot.
6210 * @param slotIndex slot index.
6211 * @param callingPackage the name of the package making the call.
6212 * @return the current radio power state from the modem
6213 */
6214 @Override
6215 public int getRadioPowerState(int slotIndex, String callingPackage) {
6216 Phone phone = PhoneFactory.getPhone(slotIndex);
6217 if (phone != null) {
6218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6219 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6220 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6221 }
6222
6223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 return phone.getRadioPowerState();
6226 } finally {
6227 Binder.restoreCallingIdentity(identity);
6228 }
6229 }
6230 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6231 }
6232
6233 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006234 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6235 *
6236 * <p>Requires one of the following permissions:
6237 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6238 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6239 * privileges.
6240 *
6241 * @param subId subscription id
6242 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6243 * {@code false}.
6244 */
6245 @Override
6246 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006247 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6248 null /* message */);
6249
Pengquan Meng0c05b502018-09-06 09:59:22 -07006250 boolean isEnabled = false;
6251 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006252 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006253 Phone phone = getPhone(subId);
6254 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006255 } catch (Exception e) {
6256 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6257 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006258 } finally {
6259 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006260 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006261 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006262 }
6263
6264
6265 /**
6266 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6267 *
6268 * <p> Requires permission:
6269 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6270 * privileges.
6271 *
6272 * @param subId subscription id
6273 * @param isEnabled {@code true} means enable, {@code false} means disable.
6274 */
6275 @Override
6276 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6278 mApp, subId, "setDataRoamingEnabled");
6279
Pengquan Meng0c05b502018-09-06 09:59:22 -07006280 final long identity = Binder.clearCallingIdentity();
6281 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006282 Phone phone = getPhone(subId);
6283 if (phone != null) {
6284 phone.setDataRoamingEnabled(isEnabled);
6285 }
6286 } finally {
6287 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006288 }
6289 }
6290
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006291 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006292 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006293 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6294 mApp, subId, "isManualNetworkSelectionAllowed");
6295
Pengquan Meng312de0c2018-10-03 12:19:13 -07006296 boolean isAllowed = true;
6297 final long identity = Binder.clearCallingIdentity();
6298 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006299 Phone phone = getPhone(subId);
6300 if (phone != null) {
6301 isAllowed = phone.isCspPlmnEnabled();
6302 }
6303 } finally {
6304 Binder.restoreCallingIdentity(identity);
6305 }
6306 return isAllowed;
6307 }
6308
6309 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006310 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006311 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006312 try {
6313 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006314 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006315 } catch (SecurityException e) {
6316 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6317 // has carrier privileges on an active UICC
6318 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6319 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006320 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006321 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006322 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006323
6324 final long identity = Binder.clearCallingIdentity();
6325 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006326 UiccController uiccController = UiccController.getInstance();
6327 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006328 if (hasReadPermission) {
6329 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006330 }
Jordan Liu67997952019-04-22 15:10:43 -07006331
6332 // Remove private info if the caller doesn't have access
6333 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6334 for (UiccCardInfo cardInfo : cardInfos) {
6335 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6336 // is available
6337 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6338 if (card == null || card.getUiccProfile() == null) {
6339 // assume no access if the card or profile is unavailable
6340 filteredInfos.add(cardInfo.getUnprivileged());
6341 continue;
6342 }
6343 UiccProfile profile = card.getUiccProfile();
6344 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6345 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6346 filteredInfos.add(cardInfo);
6347 } else {
6348 filteredInfos.add(cardInfo.getUnprivileged());
6349 }
6350 }
6351 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006352 } finally {
6353 Binder.restoreCallingIdentity(identity);
6354 }
6355 }
6356
6357 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006358 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006359 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006360
Malcolm Chend965c8b2018-02-28 15:00:40 -08006361 final long identity = Binder.clearCallingIdentity();
6362 try {
6363 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6364 if (slots == null) {
6365 Rlog.i(LOG_TAG, "slots is null.");
6366 return null;
6367 }
6368
6369 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6370 for (int i = 0; i < slots.length; i++) {
6371 UiccSlot slot = slots[i];
6372 if (slot == null) {
6373 continue;
6374 }
6375
6376 String cardId;
6377 UiccCard card = slot.getUiccCard();
6378 if (card != null) {
6379 cardId = card.getCardId();
6380 } else {
6381 cardId = slot.getIccId();
6382 }
6383
6384 int cardState = 0;
6385 switch (slot.getCardState()) {
6386 case CARDSTATE_ABSENT:
6387 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6388 break;
6389 case CARDSTATE_PRESENT:
6390 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6391 break;
6392 case CARDSTATE_ERROR:
6393 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6394 break;
6395 case CARDSTATE_RESTRICTED:
6396 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6397 break;
6398 default:
6399 break;
6400
6401 }
6402
6403 infos[i] = new UiccSlotInfo(
6404 slot.isActive(),
6405 slot.isEuicc(),
6406 cardId,
6407 cardState,
6408 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006409 slot.isExtendedApduSupported(),
6410 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006411 }
6412 return infos;
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006415 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006416 }
6417
6418 @Override
6419 public boolean switchSlots(int[] physicalSlots) {
6420 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006421
6422 final long identity = Binder.clearCallingIdentity();
6423 try {
6424 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006428 }
Jack Yu4c988042018-02-27 15:30:01 -08006429
6430 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006431 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 return UiccController.getInstance().getCardIdForDefaultEuicc();
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
6438 }
6439
6440 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006441 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6442 enforceModifyPermission();
6443 final Phone phone = getPhone(subId);
6444 if (phone == null) {
6445 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6446 return;
6447 }
6448
Malcolm Chend965c8b2018-02-28 15:00:40 -08006449 final long identity = Binder.clearCallingIdentity();
6450 try {
6451 phone.setRadioIndicationUpdateMode(filters, mode);
6452 } finally {
6453 Binder.restoreCallingIdentity(identity);
6454 }
Jack Yu4c988042018-02-27 15:30:01 -08006455 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006456
6457 /**
goneil47ffb6e2018-04-06 15:40:58 -07006458 * A test API to reload the UICC profile.
6459 *
6460 * <p>Requires that the calling app has permission
6461 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6462 * @hide
6463 */
6464 @Override
6465 public void refreshUiccProfile(int subId) {
6466 enforceModifyPermission();
6467
6468 final long identity = Binder.clearCallingIdentity();
6469 try {
6470 Phone phone = getPhone(subId);
6471 if (phone == null) {
6472 return;
6473 }
6474 UiccCard uiccCard = phone.getUiccCard();
6475 if (uiccCard == null) {
6476 return;
6477 }
6478 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6479 if (uiccProfile == null) {
6480 return;
6481 }
6482 uiccProfile.refresh();
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
6486 }
6487
6488 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006489 * Returns false if the mobile data is disabled by default, otherwise return true.
6490 */
6491 private boolean getDefaultDataEnabled() {
6492 return "true".equalsIgnoreCase(
6493 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6494 }
6495
6496 /**
6497 * Returns true if the data roaming is enabled by default, i.e the system property
6498 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6499 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6500 */
6501 private boolean getDefaultDataRoamingEnabled(int subId) {
6502 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006503 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006504 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6505 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6506 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6507 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6508 return isDataRoamingEnabled;
6509 }
6510
6511 /**
6512 * Returns the default network type for the given {@code subId}, if the default network type is
6513 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6514 */
6515 private int getDefaultNetworkType(int subId) {
6516 return Integer.parseInt(
6517 TelephonyManager.getTelephonyProperty(
6518 mSubscriptionController.getPhoneId(subId),
6519 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6520 String.valueOf(Phone.PREFERRED_NT_MODE)));
6521 }
fionaxua13278b2018-03-21 00:08:13 -07006522
6523 @Override
6524 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6525 gid1, String gid2, String plmn, String spn) {
6526 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006527
6528 final long identity = Binder.clearCallingIdentity();
6529 try {
6530 final Phone phone = getPhone(subId);
6531 if (phone == null) {
6532 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6533 return;
6534 }
6535 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6536 } finally {
6537 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006538 }
fionaxua13278b2018-03-21 00:08:13 -07006539 }
6540
6541 @Override
6542 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006543 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006544
6545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 final Phone phone = getPhone(subId);
6548 if (phone == null) {
6549 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6550 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6551 }
6552 return phone.getCarrierIdListVersion();
6553 } finally {
6554 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006555 }
fionaxua13278b2018-03-21 00:08:13 -07006556 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006557
6558 @Override
6559 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6561 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6562 return -1;
6563 }
6564
6565 final long identity = Binder.clearCallingIdentity();
6566 try {
6567 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
6571 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006572
6573 @Override
6574 public int getCdmaRoamingMode(int subId) {
6575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6576 mApp, subId, "getCdmaRoamingMode");
6577
6578 final long identity = Binder.clearCallingIdentity();
6579 try {
6580 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6581 } finally {
6582 Binder.restoreCallingIdentity(identity);
6583 }
6584 }
6585
6586 @Override
6587 public boolean setCdmaRoamingMode(int subId, int mode) {
6588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6589 mApp, subId, "setCdmaRoamingMode");
6590
6591 final long identity = Binder.clearCallingIdentity();
6592 try {
6593 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6594 } finally {
6595 Binder.restoreCallingIdentity(identity);
6596 }
6597 }
6598
6599 @Override
6600 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6602 mApp, subId, "setCdmaSubscriptionMode");
6603
6604 final long identity = Binder.clearCallingIdentity();
6605 try {
6606 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6607 } finally {
6608 Binder.restoreCallingIdentity(identity);
6609 }
6610 }
chen xu7ee67862018-10-30 22:27:10 -07006611
sqian2fff4a32018-11-05 14:18:37 -08006612 private void ensureUserRunning(int userId) {
6613 if (!mUserManager.isUserRunning(userId)) {
6614 throw new IllegalStateException("User " + userId + " does not exist or not running");
6615 }
6616 }
6617
6618 /**
6619 * Returns a list of SMS apps on a given user.
6620 *
6621 * Only the shell user (UID 2000 or 0) can call it.
6622 * Target user must be running.
6623 */
6624 @Override
6625 public String[] getSmsApps(int userId) {
6626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6627 ensureUserRunning(userId);
6628
6629 final Collection<SmsApplicationData> apps =
6630 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6631
6632 String[] ret = new String[apps.size()];
6633 int i = 0;
6634 for (SmsApplicationData app : apps) {
6635 ret[i++] = app.mPackageName;
6636 }
6637 return ret;
6638 }
6639
6640 /**
6641 * Returns the default SMS app package name on a given user.
6642 *
6643 * Only the shell user (UID 2000 or 0) can call it.
6644 * Target user must be running.
6645 */
6646 @Override
6647 public String getDefaultSmsApp(int userId) {
6648 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6649 ensureUserRunning(userId);
6650
6651 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6652 /* updateIfNeeded= */ true, userId);
6653 return cn == null ? null : cn.getPackageName();
6654 }
6655
6656 /**
6657 * Set a package as the default SMS app on a given user.
6658 *
6659 * Only the shell user (UID 2000 or 0) can call it.
6660 * Target user must be running.
6661 */
6662 @Override
6663 public void setDefaultSmsApp(int userId, String packageName) {
6664 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6665 ensureUserRunning(userId);
6666
6667 boolean found = false;
6668 for (String pkg : getSmsApps(userId)) {
6669 if (TextUtils.equals(packageName, pkg)) {
6670 found = true;
6671 break;
6672 }
6673 }
6674 if (!found) {
6675 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6676 }
6677
6678 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6679 }
6680
chen xu7ee67862018-10-30 22:27:10 -07006681 @Override
sqian65eefe12019-02-22 15:55:18 -08006682 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006683 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006685 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006686 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6687 }
6688 final long identity = Binder.clearCallingIdentity();
6689 try {
sqian991b35e2018-12-12 16:48:18 -08006690 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6691 for (Phone phone: PhoneFactory.getPhones()) {
6692 if (phone.getEmergencyNumberTracker() != null
6693 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6694 emergencyNumberListInternal.put(
6695 phone.getSubId(),
6696 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6697 }
sqian03bca152018-12-05 18:48:28 -08006698 }
sqian991b35e2018-12-12 16:48:18 -08006699 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006700 } finally {
6701 Binder.restoreCallingIdentity(identity);
6702 }
sqian04b86072018-11-07 14:02:21 -08006703 }
6704
6705 @Override
sqian65eefe12019-02-22 15:55:18 -08006706 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006707 final Phone defaultPhone = getDefaultPhone();
6708 if (!exactMatch) {
6709 TelephonyPermissions
6710 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006711 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006712 }
6713 final long identity = Binder.clearCallingIdentity();
6714 try {
sqian991b35e2018-12-12 16:48:18 -08006715 for (Phone phone: PhoneFactory.getPhones()) {
6716 if (phone.getEmergencyNumberTracker() != null
6717 && phone.getEmergencyNumberTracker() != null) {
6718 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6719 number, exactMatch)) {
6720 return true;
sqian03bca152018-12-05 18:48:28 -08006721 }
6722 }
sqian03bca152018-12-05 18:48:28 -08006723 }
6724 return false;
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
6728 }
6729
sqian9d4df8b2019-01-15 18:32:07 -08006730 /**
6731 * Update emergency number list for test mode.
6732 */
6733 @Override
6734 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6735 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6736 "updateEmergencyNumberListTestMode");
6737
6738 final long identity = Binder.clearCallingIdentity();
6739 try {
6740 for (Phone phone: PhoneFactory.getPhones()) {
6741 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6742 if (tracker != null) {
6743 tracker.executeEmergencyNumberTestModeCommand(action, num);
6744 }
6745 }
6746 } finally {
6747 Binder.restoreCallingIdentity(identity);
6748 }
6749 }
6750
6751 /**
6752 * Get the full emergency number list for test mode.
6753 */
6754 @Override
6755 public List<String> getEmergencyNumberListTestMode() {
6756 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6757 "getEmergencyNumberListTestMode");
6758
6759 final long identity = Binder.clearCallingIdentity();
6760 try {
6761 Set<String> emergencyNumbers = new HashSet<>();
6762 for (Phone phone: PhoneFactory.getPhones()) {
6763 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6764 if (tracker != null) {
6765 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6766 emergencyNumbers.add(num.getNumber());
6767 }
6768 }
6769 }
6770 return new ArrayList<>(emergencyNumbers);
6771 } finally {
6772 Binder.restoreCallingIdentity(identity);
6773 }
6774 }
6775
sqian04b86072018-11-07 14:02:21 -08006776 @Override
chen xu7ee67862018-10-30 22:27:10 -07006777 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6778 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6779 Phone phone = getPhone(subId);
6780 if (phone == null) {
6781 return null;
6782 }
6783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 UiccProfile profile = UiccController.getInstance()
6786 .getUiccProfileForPhone(phone.getPhoneId());
6787 if (profile != null) {
6788 return profile.getCertsFromCarrierPrivilegeAccessRules();
6789 }
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
6793 return null;
6794 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006795
6796 /**
6797 * Enable or disable a modem stack.
6798 */
6799 @Override
6800 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6801 enforceModifyPermission();
6802
6803 final long identity = Binder.clearCallingIdentity();
6804 try {
6805 Phone phone = PhoneFactory.getPhone(slotIndex);
6806 if (phone == null) {
6807 return false;
6808 } else {
6809 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6810 }
6811 } finally {
6812 Binder.restoreCallingIdentity(identity);
6813 }
6814 }
Micheled3107c52018-12-21 15:00:11 -08006815
Malcolm Chen33f55e12019-03-27 18:34:05 -07006816 /**
6817 * Whether a modem stack is enabled or not.
6818 */
6819 @Override
6820 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6821 Phone phone = PhoneFactory.getPhone(slotIndex);
6822 if (phone == null) return false;
6823
6824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6825 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6826 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6827 }
6828
6829 final long identity = Binder.clearCallingIdentity();
6830 try {
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07006831 try {
6832 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6833 } catch (NoSuchElementException ex) {
6834 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6835 }
Malcolm Chen33f55e12019-03-27 18:34:05 -07006836 } finally {
6837 Binder.restoreCallingIdentity(identity);
6838 }
6839 }
6840
Micheled3107c52018-12-21 15:00:11 -08006841 @Override
Michele2fb0f222019-03-19 14:58:42 -07006842 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006843 enforceModifyPermission();
6844
6845 final long identity = Binder.clearCallingIdentity();
6846 try {
6847 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006848 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006849 .commit();
6850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
6853 }
6854
6855 @Override
Michele2fb0f222019-03-19 14:58:42 -07006856 @TelephonyManager.IsMultiSimSupportedResult
6857 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006859 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6860 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006861 }
Micheled3107c52018-12-21 15:00:11 -08006862
6863 final long identity = Binder.clearCallingIdentity();
6864 try {
Michele2fb0f222019-03-19 14:58:42 -07006865 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
6869 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006870
Michele2fb0f222019-03-19 14:58:42 -07006871 @TelephonyManager.IsMultiSimSupportedResult
6872 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006873 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6874 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6875 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006876 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6877 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006878 }
6879 // Check if the hardware supports multisim functionality. If usage of multisim is not
6880 // supported by the modem, indicate that it is restricted.
6881 PhoneCapability staticCapability =
6882 mPhoneConfigurationManager.getStaticPhoneCapability();
6883 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006884 loge("isMultiSimSupportedInternal: no static configuration available");
6885 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006886 }
6887 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006888 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6889 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006890 }
6891 // Check if support of multiple SIMs is restricted by carrier
6892 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006893 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006894 }
6895
Michele2fb0f222019-03-19 14:58:42 -07006896 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006897 }
6898
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006899 /**
6900 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006901 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6902 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6903 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006904 * @param numOfSims number of active sims we want to switch to
6905 */
6906 @Override
6907 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006908 if (numOfSims == 1) {
6909 enforceModifyPermission();
6910 } else {
6911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6912 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6913 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006914 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006915
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006916 try {
Michele30b57b22019-03-01 12:01:14 -08006917 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006918 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006919 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6920 return;
6921 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006922 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6923 } finally {
6924 Binder.restoreCallingIdentity(identity);
6925 }
6926 }
6927
6928 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006929 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006930 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006931 */
6932 @Override
6933 public boolean isRebootRequiredForModemConfigChange() {
6934 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6935 final long identity = Binder.clearCallingIdentity();
6936 try {
6937 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6938 } finally {
6939 Binder.restoreCallingIdentity(identity);
6940 }
6941 }
6942
Pengquan Meng92d253b2019-02-06 11:12:53 -08006943 private void updateModemStateMetrics() {
6944 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6945 // TODO: check the state for each modem if the api is ready.
6946 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6947 }
6948
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006949 @Override
6950 public int[] getSlotsMapping() {
6951 enforceReadPrivilegedPermission("getSlotsMapping");
6952
6953 final long identity = Binder.clearCallingIdentity();
6954 try {
6955 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6956 // All logical slots should have a mapping to a physical slot.
6957 int[] logicalSlotsMapping = new int[phoneCount];
6958 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6959 for (int i = 0; i < slotInfos.length; i++) {
6960 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6961 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6962 }
6963 }
6964 return logicalSlotsMapping;
6965 } finally {
6966 Binder.restoreCallingIdentity(identity);
6967 }
6968 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006969
6970 /**
6971 * Get the IRadio HAL Version
6972 */
6973 @Override
6974 public int getRadioHalVersion() {
6975 Phone phone = getDefaultPhone();
6976 if (phone == null) return -1;
6977 HalVersion hv = phone.getHalVersion();
6978 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6979 return hv.major * 100 + hv.minor;
6980 }
Malcolm Chen460810d2019-04-10 18:25:07 -07006981
6982 /**
Malcolm Chen29739692019-04-18 13:51:02 -07006983 * Return whether data is enabled for certain APN type. This will tell if framework will accept
6984 * corresponding network requests on a subId.
6985 *
6986 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07006987 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07006988 * 2) APN is un-metered for this subscription, or
6989 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
6990 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
6991 *
6992 * @return whether data is allowed for a apn type.
6993 *
6994 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07006995 */
6996 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07006997 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07006998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07006999 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7000 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07007001 }
7002
7003 // Now that all security checks passes, perform the operation as ourselves.
7004 final long identity = Binder.clearCallingIdentity();
7005 try {
7006 Phone phone = getPhone(subId);
7007 if (phone == null) return false;
7008
7009 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chen29739692019-04-18 13:51:02 -07007010 apnType), phone);
7011 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
7014 }
7015 }
7016
7017 @Override
7018 public boolean isApnMetered(int apnType, int subId) {
7019 enforceReadPrivilegedPermission("isApnMetered");
7020
7021 // Now that all security checks passes, perform the operation as ourselves.
7022 final long identity = Binder.clearCallingIdentity();
7023 try {
7024 Phone phone = getPhone(subId);
7025 if (phone == null) return true; // By default return true.
7026
7027 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
7028 apnType), phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07007029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
7032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007033}